Installing PyTorch on Debian bullseye (Debian 11)
• deep-learning • PermalinkI have just rebuilt PyTorch for my Debian bullseye machine (Debian 11 as it will become) from source. This blog post documents how I did this.
System setup
I have the following key packages/libraries installed. There will certainly be others that I have overlooked, of course; please feel free to let me know of anything I’ve overlooked.
- Python:
python3-dev
(currently version 3.9.2-2) - Essential packages (according to the PyTorch installation page) are:
ninja-build
cmake
libmagma-dev
python3-numpy
python3-yaml
python3-setuptools
python3-cffi
python3-typing-extensions
python3-future
python3-six
python3-requests
-
The PyTorch website also says that
mkl
should be included, which is probably provided by thelibmkl-dev
package. But that provides alternatives to thelibblas
library packages, so it fine to install one of the open sourcelibblas-dev
packages instead (libblas-dev
,libblas64-dev
,libopenblas-dev
orlibopenblas64-dev
). -
Though the PyTorch page says that
dataclasses
is required, this is only for Python versions less than 3.7, so there is no need to install this. -
CUDA: The Debian non-free archive includes the package
nvidia-cuda-toolkit
, which does everything required (unlike the case with TensorFlow). - cuDNN:
libcudnn8-dev
(version 8.1.0.77-1+cuda11.2; this package was downloaded directly from the NVIDIA website)
Building PyTorch
I started by following the guidance on the PyTorch installing from source webpage.
Downloading the PyTorch source code
I followed the instructions as given; I also checked out the latest
release branch, which at the time of writing is r1.8.1
.
$ git clone --recursive https://github.com/pytorch/pytorch
$ cd pytorch
$ git checkout -t origin/release/1.8
$ git submodule sync
$ git submodule update --init --recursive
(where the last two commands are needed if updating an existing checkout, though they do not do any harm if not).
Pre-build
The version number in the PyTorch sources does not match the official version number for some reason. So I “corrected” it:
$ echo 1.8.1 > version.txt
Building the package
It’s a one-line command:
$ python3 setup.py install --user
This compilation step is pretty long, but that is all that is needed.
To clean the build directory after it had finished, I ran:
$ python3 setup.py clean
Building torchvision and torchaudio
Installing dependencies
torchvision
looks for certain graphics libraries during the build.
I’m not sure which are strictly required, but here are the packages to
install to ensure that everything is present (in addition to having
PyTorch itself already installed as above):
libpng-dev
libpng-tools
libjpeg-dev
ffmpeg
libavcodec-dev
libavformat-dev
libavutil-dev
libswresample-dev
libswscale-dev
There is also an extra dependency on python3-scipy
in the setup.py
extras_require
option; I am unclear whether this is needed.
torchaudio
does not have any dependencies beyond PyTorch itself.
Downloading and building
I used pip
(or pip3
) to install rather than directly using
setup.py
, as otherwise the package gets installed in egg
format.
I installed torchvision
as follows:
$ git clone https://github.com/pytorch/vision.git
$ cd vision
$ git checkout -t origin/release/0.9
$ echo 0.9.1 > version.txt
$ pip install --user .
Cleaning, if needed, apparently still needs to be done via setup.py
:
python3 setup.py clean
torchaudio
was only a tiny bit trickier:
$ git clone --recursive https://github.com/pytorch/audio.git
$ cd audio
$ git checkout -t origin/release/0.8
$ git submodule sync
$ git submodule update --init --recursive
(As with PyTorch, the last two commands are needed if updating an existing checkout, though they do not do any harm if not).
Then I edited setup.py
, modifying lines 14-16 to read:
# Creating the version file
version = '0.8.1'
sha = 'e4e171a51714b2b2bd79e1aea199c3f658eddf9a'
Then a one-line build command:
$ pip install --user .
and I was done.