谷歌colab上的pytorch几何“检测到PyTorch和torch_sparse是用不同的CUDA版本编译的”

eny*_*alo 4 torch pytorch google-colaboratory

我是 pytorch geometry 的新手,尝试将其安装到我的计算机上但失败了,所以我尝试在 Google Colab 上运行代码。根据上一个问题(这对我没有帮助,我不确定是不是同样的问题):

Google Colab 上的 PyTorch Geometric CUDA 安装问题

我做了:

!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
Run Code Online (Sandbox Code Playgroud)

他们打印:

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
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行时

import torch_geometric.datasets as datasets
Run Code Online (Sandbox Code Playgroud)

我得到:

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.
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

小智 6

我想出了以下应该在 Colab 上安装 PyTorch Geometric 及其依赖项的代码片段: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
Run Code Online (Sandbox Code Playgroud)


Kor*_*ich 1

我已经更新了上一个问题的答案。希望现在有效。也不要忘记选择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
Run Code Online (Sandbox Code Playgroud)