I’ve been fiddling with PyTorch Geometric installation lately, and I believe we all know that although being an awesome library, sometimes it can be notoriously hard to get it to work in the first place. Especially if your CUDA version is way too low. That can be very, very problematic. So, let’s assume we have an unlisted CUDA version (11.1 in my case,) and let’s try to make it work!
So the very first thing is to install PyTorch. And to install PyTorch (the GPU-enabled version, obviously,) you can follow this helpful link on the official website. If, however, our CUDA version is too low and becomes unlisted (again,) we can follow this link and just search for our version. In our case (CUDA 11.1,) we see that the latest supported version is
So we copy & paste that into our command line and BAM! PyTorch done.
After that, try to
import torch and verify that we can indeed create variables using
import torch torch.randn(1, 1, device='cuda')
Wow! It is on device! Let’s go!
For unsupported OSes, sometimes there is no precompiled PyTorch wheels, and that calls for a complete compilation from source. If such cases arise, it is very important for us to choose one compiler throughout the entire compilation (i.e. the compiler needs to be the same for both PyTorch and PyTorch Geometric.) If you are using an archaic version of, say, Ubuntu, which leads to an ancient GCC and G++, I highly recommend you to install Clang instead. For Ubuntu users, you can install Clang using
llvm.sh, with a comprehensive guide available here. The Clang version can’t be too new or too old, otherwise we can’t compile PyTorch Geometric. My recommended version is clang-6.0, which works for me.
We can tell
pip to use our new compiler once we have finished the installation:
export CC=clang-6.0 export CXX=clang++-6.0 # And now install PyTorch pip install torch==...
PyTorch Geometric (PyG for short) is more like a toolkit with four major dependencies:
If you have relatively new PyTorch and CUDA installed, you can just follow the guide from its official website. Otherwise, we will have to take the matter into our own hands. Note that on its official website, there is a find link for specific PyTorch and CUDA versions:
By copy-pasting it and replacing the torch version and CUDA version with our version (PyTorch 1.10.1 + CUDA 11.1), we get https://data.pyg.org/whl/torch-1.10.1+cu111.html. And after accessing it we are presented with a list of supported versions of PyG dependencies:
After a quick look we can see that supported versions of PyG dependencies given our CUDA and PyTorch versions are:
Now we simply need to pick their newest versions (or not as new, it’s really up to you) and
pip install them.
pip install torch_scatter==2.0.9 torch_sparse==0.6.13 torch_cluster==1.6.0 torch_spline_conv==1.2.1 -f https://data.pyg.org/whl/torch-1.10.1+cu111.html pip install torch_geometric
WARNING! It’s very important that you specify the version here, otherwise pip will completely disregard the find link and just download the newest version of the four dependencies. You might have noticed that
pyg_lib is absent from the above list. I have noticed that as well, but since my task then was to simply install PyG, I disregarded the discrepency and no errors comes off it. I guess my PyTorch Geometric version is too old for the
If you want some new thrilling adventure (or if your OS is too old, as stated above,) you can also compile PyG from source. The procedure is basically the same as above. We have to guarantee the compiler remains the same.
However, if you are using Clang as advised, you will encounter two errors.
CFLAGS="-fopenmp=libiomp5" pip install torch_cluster --no-cache
After a long wait, you should be able to build all four (five?) dependencies from source. After that, just install PyG (or build it as well.)
That’s it! A grand adventure of version wrangling, all due to the outdated CUDA version on the server side. But I guess that’s why it’s fun, right? To verify that PyG has been definitively successfully installed, I try to import all four dependencies independently, and try to print out its CUDA version:
import torch_scatter print(torch_scatter.torch.version.cuda) # ... and so on.
And that’s about it. Have fun using PyG!