I keep getting this error while building PyTorch

Hello

I am planning to contribute to PyTorch project.

I followed the installation process on the GitHub README.

git submodule sync
git submodule update --init --recursive

python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
pip install --group dev

export USE_CUDA=0
export USE_ROCM=0
export USE_XPU=0
export CMAKE_PREFIX_PATH="${VIRTUAL_ENV}:${CMAKE_PREFIX_PATH}"
python -m pip install --no-build-isolation -v -e .

However, I am getting the following error.

  [2629/5804] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/native/cpu/SortingKernel.cpp.SVE256.cpp.o
  ninja: build stopped: subcommand failed.
  error: subprocess-exited-with-error
  
  Ă— Building editable for torch (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> No available output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /home/yeonguchoebusiness/pytorch/.venv/bin/python /home/yeonguchoebusiness/pytorch/.venv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_editable /tmp/tmp4okde_bo
  cwd: /home/yeonguchoebusiness/pytorch
  Building editable for torch (pyproject.toml) ... error
  ERROR: Failed building editable for torch
Failed to build torch
error: failed-wheel-build-for-install

Ă— Failed to build installable wheels for some pyproject.toml based projects
╰─> torch

I am using Linux on CPU-only environment.

Has anyone encountered this error before? How did you solve it?

Thanks.

And what does your gcc -v (or cc -v) says?

1 Like

Thank you for the reply. Nikita.

My gcc version is gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1).

ychoe@laptop:~/Desktop/pytorch$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04.1' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-13-EldibY/gcc-13-13.3.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1) 

After reading your comment, I thought it has something to do with python, so I built cpython manually and tried again. However, it is still crashing when building pytorch.

Do you mind asking which option do you use when building pytorch?
(e.g,
export USE_CUDA=0
USE_ROCM=0
USE_XPU=0
CMAKE_PREFIX_PATH=“${VIRTUAL_ENV}:${CMAKE_PREFIX_PATH}” &&
python -m pip install --no-build-isolation -v -e .)

BTW, I don’t have GPU and only use CPU.

Sincerely,
Yeongu

Hi Yeongu,

The error you’re seeing from the build wrapper just reports the compiler exited nonzero. The real error is in the lines above it.

Could you re-run and share the first error: line before the SortingKernel failure?

pip install -e . -v --no-build-isolation 2>&1 | tee build.log

the compiler running out of memory and getting killed. dmesg | tail after the crash will show it. If that’s it, MAX_JOBS=2 usually does.

For CPU-only I use:

USE_CUDA=0 USE_ROCM=0 USE_XPU=0 USE_DISTRIBUTED=0 BUILD_TEST=0 \
pip install -e . -v --no-build-isolation

GCC 13.3.0 on 24.04 should be fine.