5

I'm new to pytorch geometric, tried to install it to my computer but failed, so I'm trying to run the code on Google Colab instead. According to this previous question (which didn't help me and I'mnot sure its the same issue):

PyTorch Geometric CUDA installation issues on Google Colab

I did:

!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

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

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

they print:

Successfully installed torch-cluster-1.5.4

Successfully installed torch-scatter-2.0.4 torch-sparse-0.6.1 torch-spline-conv-1.2.0

However, when I try to run

import torch_geometric.datasets as datasets

I get:

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 0.0. Please reinstall the torch_sparse that matches your PyTorch install.

Any help would be greatly appretiated.

talonmies
  • 70,661
  • 34
  • 192
  • 269
enyhertbalo
  • 73
  • 1
  • 5
  • Looking at https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html it says "Check if PyTorch is installed with CUDA support: `python -c "import torch; print(torch.cuda.is_available())"`". If I type `!python -c "import torch; print(torch.cuda.is_available())"` in my colab session, I get `False`, which is a bad sign, the site suggests I should get a `True`. – zabop Apr 18 '20 at 23:26
  • However, following this: https://stackoverflow.com/a/60338745/8565438, if I click `Menu > Runtime > Change runtime ` then change Hardware accelerator to GPU, click `Save `, run the same code as before ( `!python -c "import torch; print(torch.cuda.is_available())"`), I get a `True` output. Do you get the error you got previously if you change your Hardware accelerator to GPU? – zabop Apr 18 '20 at 23:31
  • Tried it myself, I think it works if you enable GPU hardware accelerator (I enabled before installing all of the things you installed, idk what happens if you enable it after). `import torch_geometric.datasets as datasets` runs in this case without error message. – zabop Apr 19 '20 at 00:05

2 Answers2

9

I came up with the following snippet that should work on Colab to install PyTorch Geometric and its dependencies: https://gist.github.com/ameya98/b193856171d11d37ada46458f60e73e7

# Add this in a Google Colab cell to install the correct version of Pytorch Geometric.
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
Nikita
  • 3
  • 2
  • 4
Ameya
  • 326
  • 3
  • 9
1

I have updated the answer from that previous question. Hope this works now. Also don't forget to select GPU Runtime.

!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
korakot
  • 37,818
  • 16
  • 123
  • 144