Setting up PyTorch Geometric (GPU) on Gradient, help needed

I am trying to set up a Notebook with Pytorch Geometric on Gradient. At present, I am using a Free tier. However, I am running into an OS Error. I have a notebook with 3 cells only. First, I import PyTorch:

import torch
print(torch.__version__) #1.5.1
print(torch.version.cuda) #10.2

Next, I install the relevant packages I want to use through PIP.

!pip install --upgrade pip
! pip install ogb
!pip install torch-scatter==latest+cu102 -f https://pytorch-geometric.com/whl/torch-1.5.0.html
!pip install torch-sparse==latest+cu102 -f https://pytorch-geometric.com/whl/torch-1.5.0.html
!pip install torch-cluster==latest+cu102 -f https://pytorch-geometric.com/whl/torch-1.5.0.html
!pip install torch-spline-conv==latest+cu102 -f https://pytorch-geometric.com/whl/torch-1.5.0.html
!pip install torch-geometric

And in cell 3, I try to import PyG

import torch_geometric

Here, I get the error:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
 in 
----> 1 import torch_geometric

/usr/local/lib/python3.6/dist-packages/torch_geometric/__init__.py in 
      1 from .debug import is_debug_enabled, debug, set_debug
----> 2 import torch_geometric.nn
      3 import torch_geometric.data
      4 import torch_geometric.datasets
      5 import torch_geometric.transforms

/usr/local/lib/python3.6/dist-packages/torch_geometric/nn/__init__.py in 
      1 from .meta import MetaLayer
----> 2 from .data_parallel import DataParallel
      3 from .reshape import Reshape
      4 from .conv import *  # noqa
      5 from .norm import *  # noqa

/usr/local/lib/python3.6/dist-packages/torch_geometric/nn/data_parallel.py in 
      3 
      4 import torch
----> 5 from torch_geometric.data import Batch
      6 
      7 

/usr/local/lib/python3.6/dist-packages/torch_geometric/data/__init__.py in 
----> 1 from .data import Data
      2 from .batch import Batch
      3 from .dataset import Dataset
      4 from .in_memory_dataset import InMemoryDataset
      5 from .dataloader import DataLoader, DataListLoader, DenseDataLoader

/usr/local/lib/python3.6/dist-packages/torch_geometric/data/data.py in 
      5 import torch
      6 import torch_geometric
----> 7 from torch_sparse import coalesce, SparseTensor
      8 from torch_geometric.utils import (contains_isolated_nodes,
      9                                    contains_self_loops, is_undirected)

/usr/local/lib/python3.6/dist-packages/torch_sparse/__init__.py in 
     11 ]:
     12     torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
---> 13         library, [osp.dirname(__file__)]).origin)
     14 
     15 if torch.version.cuda is not None:  # pragma: no cover

/usr/local/lib/python3.6/dist-packages/torch/_ops.py in load_library(self, path)
    103             # static (global) initialization code in order to register custom
    104             # operators with the JIT.
--> 105             ctypes.CDLL(path)
    106         self.loaded_libraries.add(path)
    107 

/usr/lib/python3.6/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    346 
    347         if handle is None:
--> 348             self._handle = _dlopen(self._name, mode)
    349         else:
    350             self._handle = handle

OSError: libcusparse.so.10: cannot open shared object file: No such file or directory

Now, the same code runs well in Kaggle Kernels where I simply simply use cu101 instead of cu102. I think it is something related with the CUDA version available.

Hi,

now there is a base container (https://docs.paperspace.com/gradient/notebooks/notebook-containers) with Torch, which I am using with Pytorch geometric. This container brings PyTorch 1.2, so we need to upgrade it at least to 1.4 to be compatible with Pytorch geometric.

Please create a Notebook and check the results of

import torch
print(torch.__version__)
print(torch.version.cuda)
!nvcc --version

You should get that it is using CUDA 10.0 (the container tag is paperspace/dl-containers:pytorch-py36-cu100-jupyter) and PyTorch 1.2. Now to update to PyTorch 1.4:

!pip install torch==1.4.0 torchvision==0.5.0 -f https://download.pytorch.org/whl/cu100/torch_stable.html

And then, it is time to install PyTorch Geometric for PyTorch 1.4 and CUDA 10.0:

!pip install torch-scatter==latest+cu100 -f https://pytorch-geometric.com/whl/torch-1.4.0.html
!pip install torch-sparse==latest+cu100 -f https://pytorch-geometric.com/whl/torch-1.4.0.html
!pip install torch-cluster==latest+cu100 -f https://pytorch-geometric.com/whl/torch-1.4.0.html
!pip install torch-spline-conv==latest+cu100 -f https://pytorch-geometric.com/whl/torch-1.4.0.html
!pip install torch-geometric

After this, check again with:

import torch
print(torch.__version__)

It should print a 1.4 version. If it doesn’t, stop and start the notebook from the Web Interface and check again.

At this point you should be able to import PyTorch Geometric and execute any example. Hope it helps!

Regards,
Joaquín.