diff --git a/articles/build-pytorch-on-old-amd64/page.mmd b/articles/build-pytorch-on-old-amd64/page.mmd new file mode 100644 index 0000000..afe2865 --- /dev/null +++ b/articles/build-pytorch-on-old-amd64/page.mmd @@ -0,0 +1,89 @@ +Title: Building Pytorch on an Old Laptop +Brief: Journey of building Pytorch 2.2.0 on 10+ old amd64 laptop. +Date: 1707822832 +Tags: Compilation, Bash +CSS: /style.css + +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: + +```bash +#!/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.