PyTorch Geometric CUDA installation issues on Google Colab
Asked Answered
S

6

10

I was working on a PyTorch Geometric project using Google Colab for CUDA support. Since it's library isn't present by default, I run:

!pip install --upgrade torch-scatter
!pip install --upgrade torch-sparse
!pip install --upgrade torch-cluster
!pip install --upgrade torch-spline-conv 
!pip install torch-geometric

Recently, while importing torch_geometric, owing to version upgrades, there's a CUDA version mismatch saying:

RuntimeError: Detected that PyTorch and torch_sparse were compiled with different CUDA versions. PyTorch has CUDA version 10.1 and torch_sparse has CUDA version 10.0. Please reinstall the torch_sparse that matches your PyTorch install.

To solve this, I tried using conda for specific CUDA version as:

!conda install pytorch==1.4.0 cudatoolkit=10.0 -c pytorch

Yet, on running print(torch.version.cuda), I get 10.1 as the output and not 10.0 as I wanted.

This is a recent error since it wasn't throwing up this issue in past week. Any best practice to solve this issue?

Sanguineous answered 15/2, 2020 at 5:32 Comment(0)
W
12

From their website

Try this

!pip install torch-geometric \
  torch-sparse==latest+cu101 \
  torch-scatter==latest+cu101 \
  torch-cluster==latest+cu101 \
  -f https://pytorch-geometric.com/whl/torch-1.4.0.html
Wax answered 15/2, 2020 at 6:56 Comment(2)
UPDATE: We must even include torch-spline-conv in the above command to be compatible with the latest version.Sanguineous
@MdWahiduzzamanKhan, apparently, even torch-cluster has been updated. Use: !pip install torch-cluster==latest+cu101 -f pytorch-geometric.com/whl/torch-1.4.0.html This line will even make torch-cluster compatibleSanguineous
H
2

You can find example colab notebooks on the pytorch geometric official website https://pytorch-geometric.readthedocs.io/en/latest/notes/colabs.html

Here is what I used from the same website. It is working on the date of posting.

!pip install -q torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu113.html
!pip install -q torch-sparse -f https://data.pyg.org/whl/torch-1.10.0+cu113.html
!pip install -q git+https://github.com/pyg-team/pytorch_geometric.git
Horan answered 17/1, 2022 at 13:48 Comment(2)
This seems to duplicate existing answers by and large, can you explain what's different and significant?Diez
None of the solutions given here are working right now. The one given on Pytorch Geometric official website is what worked for me.Horan
I
1

The issues can be solve with comment:

!pip install torch-scatter==latest+cu101 torch-sparse==latest+cu101 -f https://s3.eu-central-1.amazonaws.com/pytorch-geometric.com/whl/torch-1.4.0.html

Do we have another solution ?

Intoxicated answered 7/3, 2020 at 7:45 Comment(1)
Could you please comment how did you solve the issue with this line? Should it be added after !pip install torch-geometric \ torch-sparse==latest+cu101 \ torch-scatter==latest+cu101 \ torch-cluster==latest+cu101 \ -f pytorch-geometric.com/whl/torch-1.4.0.html or used instead ?Trefoil
B
0

you might want to try the following to see if this solves your problem with the CUDA versioning error in "pytorch-geometric" :

  1. apt-get --purge remove "cublas" "cuda*"
  2. reboot
  3. sudo curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.0.130-1_amd64.deb
  4. sudo dpkg -i cuda-repo-ubuntu1804_10.0.130-1_amd64.deb sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
  5. sudo apt-get install cuda-10-1
  6. python -c "import torch; print(torch.version.cuda)"

    10.1

  7. nvcc --version

    Cuda compilation tools, release 10.1, V10.1.243

Bestiary answered 1/4, 2020 at 5:45 Comment(0)
T
0

As per my analysis torch geometric is giving error for cuda 11 and pytorch 1.7.0

Please install pytorch 1.6 and amd cuda 10.2 and execute below

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.6.0+cu102.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.6.0+cu102.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.6.0+cu102.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.6.0+cu102.html
pip install torch-geometric
Testa answered 29/12, 2020 at 14:24 Comment(0)
D
0

This is the latest code-command,that I've used on co-lab for installing PyTorch geometry related dependency.

import torch

def format_pytorch_version(version):
  return version.split('+')[0]

TORCH_version = torch.__version__
TORCH = format_pytorch_version(TORCH_version)

def format_cuda_version(version):
  return 'cu' + version.replace('.', '')

CUDA_version = torch.version.cuda
CUDA = format_cuda_version(CUDA_version)

!pip install torch-scatter     -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-sparse      -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-cluster     -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-geometric 
Directory answered 22/8, 2021 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.