You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Singularity构建因pip内存占用过高报错设备空间不足,求解决方案

Singularity构建镜像时pip安装报[Errno 28] No space left on device的解决思路

问题背景

  • 使用Singularity 4.1.3在Fedora 39(8GB内存)上构建基于Ubuntu 20.04的.sif镜像
  • .def文件内容:
Bootstrap: library
From: ubuntu:20.04

%post
  export DEBIAN_FRONTEND=noninteractive
  apt-get -qq -y update

  apt-get -qq -y install apt-utils > /dev/null

  apt-get -qq -y install --no-install-recommends \
      python3 \
      python3-tk \
      python3-pip \
      python3-distutils \
      python3-setuptools \

  pip3 install -q langchain faiss-cpu torch sentence_transformers
  • 错误现象:pip安装阶段内存占用飙升至5.9GB/6.7GB后,抛出ERROR: Could not install packages due to an EnvironmentError: [Errno 28] No space left on device
  • 已尝试:扩大本地/tmp空间、指定镜像内TMPDIR、使用pip --no-cache-dir,均无效

解决思路

1. 强制Singularity使用磁盘临时目录而非内存tmpfs

Singularity默认会将临时目录挂载到内存tmpfs,当构建过程需要大量临时空间时会耗尽内存。通过设置SINGULARITY_TMPDIR指定宿主磁盘上的大空间目录:

sudo SINGULARITY_TMPDIR=/path/to/large/disk/dir singularity build faiss_env.sif faiss_index_env.def

确保指定目录有足够剩余空间,且权限允许Singularity读写。

2. 在镜像内指定pip的磁盘临时目录

修改.def文件的%post阶段,显式让pip使用镜像内的磁盘路径作为临时目录,避免占用内存:

%post
  export DEBIAN_FRONTEND=noninteractive
  apt-get -qq -y update

  apt-get -qq -y install apt-utils > /dev/null

  apt-get -qq -y install --no-install-recommends \
      python3 \
      python3-tk \
      python3-pip \
      python3-distutils \
      python3-setuptools \

  # 创建镜像内磁盘临时目录
  mkdir -p /tmp/pip_build_temp
  export TMPDIR=/tmp/pip_build_temp
  export PIP_BUILD_DIR=/tmp/pip_build_temp
  # 无缓存安装并指定临时目录
  pip3 install --no-cache-dir -q langchain faiss-cpu torch sentence_transformers
  # 清理临时文件
  rm -rf /tmp/pip_build_temp

3. 切换构建引擎或调整Singularity版本

Singularity 4.x在Fedora上可能存在tmpfs配置兼容性问题,尝试:

  • 使用OCI引擎构建:
sudo singularity build --engine oci faiss_env.sif faiss_index_env.def
  • 降级到Singularity 3.x版本,该版本在内存临时存储处理上更稳定。

4. 拆分pip安装命令,降低内存峰值

torch、faiss-cpu等包体积大,同时安装会导致临时文件堆积。拆分安装步骤,逐个处理:

pip3 install --no-cache-dir -q torch
pip3 install --no-cache-dir -q faiss-cpu
pip3 install --no-cache-dir -q sentence_transformers
pip3 install --no-cache-dir -q langchain

单个包安装完成后,pip会自动清理部分临时文件,减少内存占用峰值。

5. 检查宿主系统的磁盘inode使用

部分情况下,inode耗尽会伪装成“空间不足”错误,执行以下命令检查:

df -h  # 检查磁盘空间
df -i  # 检查inode使用情况

如果inode不足,清理宿主系统的冗余文件或扩容对应分区。

内容的提问来源于stack exchange,提问作者Pietro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 07:43:25