Installing PyTorch on Debian bullseye (Debian 11)• deep-learning • Permalink
I 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.
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.
python3-dev(currently version 3.9.2-2)
- Essential packages (according to the PyTorch installation page) are:
The PyTorch website also says that
mklshould be included, which is probably provided by the
libmkl-devpackage. But that provides alternatives to the
libblaslibrary packages, so it fine to install one of the open source
libblas-devpackages instead (
Though the PyTorch page says that
dataclassesis 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).
libcudnn8-dev(version 22.214.171.124-1+cuda11.2; this package was downloaded directly from the NVIDIA website)
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
$ 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).
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
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):
There is also an extra dependency on
python3-scipy in the
extras_require option; I am unclear whether this is needed.
torchaudio does not have any dependencies beyond PyTorch itself.
Downloading and building
pip3) to install rather than directly using
setup.py, as otherwise the package gets installed in
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
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.