Building Pytorch on an Old Laptop

Journey of building Pytorch 2.2.0 on 10+ old amd64 laptop.

– Created: February 13, 2024 UTC

– Edited: January 24, 2025 UTC

– Tags: Compilation, Bash


This started when I was following my first tutorial on Pytorch to generate toponyms (will probably write about it too later). Just as I got enough courage to run it for first time I was faced with heartbreaking words, - Illegal instruction. Here’s the following story:

First I downloaded Pytorch release:

git clone --depth 1 https://github.com/pytorch/pytorch --single-branch --branch v2.2.0 pytorch

Then struggled for a bit with initialization of submodules, it looks like there are broken links or something??? Anyway, the command is:

git submodule update --init --recursive

But I had to rm -fr ./third_party/<> && git rm -fr --cached ./third_party/<> and then git submodule add ... replace a few libs.

Later by trial and error I came up with this script which excludes every part that demands AVX as well as anything not necessary, as compilation time of it all is ridiculous:

#!/bin/sh

set +e

# Could comment or override it if you have different compiler you want to use.
export CMAKE_C_COMPILER=clang
export CMAKE_CXX_COMPILER=clang++
export USE_CCACHE=ON

export USE_CUDA=0
export USE_DISTRIBUTED=0
export USE_GLOO=0
export BUILD_TEST=0
export BUILD_CAFFE2=0
export USE_CUDNN=0
export USE_ASAN=0
export USE_MKLDNN=0
export USE_KINETO=0
export DEBUG=0
export USE_XNNPACK=0
export USE_FBGEMM=0
export USE_NNPACK=0
export USE_QNNPACK=0

# You can comment this, but for me throttling was making it slower than just using a single core.
export MAX_JOBS=1

export USE_AVX=OFF
export USE_NNPACK=OFF
export USE_MKLDNN=OFF
export USE_FBGEMM=OFF
export C_HAS_AVX_2=OFF
export C_HAS_AVX2_2=OFF
export CXX_HAS_AVX_2=OFF
export CXX_HAS_AVX2_2=OFF
export CAFFE2_COMPILER_SUPPORTS_AVX512_EXTENSIONS=OFF
export USE_NATIVE_ARCH=ON
export USE_VULKAN=OFF

export USE_SYSTEM_ZSTD=ON

# You can install those from your package manager, but only if you're on up-to-date repos. (so, not stable Debian)
# export USE_SYSTEM_PYBIND11=ON
# export USE_SYSTEM_CPUINFO=ON
# export USE_SYSTEM_SLEEF=ON

python3 setup.py develop

It installs itself with dependencies on this very git folder, so you better place it somewhere permanent (I ended up mv and ln it, just to not forget and delete it from ~/tmp/)

Not sure how to clean the temporary stuff properly after installation, it wastes quite a bit of space (1.7 GiB for me).

In the end I just used this, which shredded about 400 MiBs of space:

rm -fr ./third_party
cd ./build && find . -name \*.o -type f -delete

That’s about it. It’s slow but you can play with it for small tasks.