python系列&deep_study系列:【已解决】RuntimeError: PyTorch has CUDA version 12.1 and torch_sparse has CUDA ver




【已解决】RuntimeError: PyTorch has CUDA version 12.1 and torch_sparse has CUDA version 11.8

问题描述

今天遇到这么一个问题:RuntimeError: Detected that PyTorch and torch_sparse were compiled with different CUDA versions. PyTorch has CUDA version 12.1 and torch_sparse has CUDA version 11.8. Please reinstall the torch_sparse that matches your PyTorch install.

详细内容如下:

/home/visionx/anaconda3/envs/gdem/lib/python3.8/site-packages/torch_geometric/typing.py:101: UserWarning: An issue occurred while importing 'torch-sparse'. Disabling its usage. Stacktrace: Detected that PyTorch and torch_sparse were compiled with different CUDA versions. PyTorch has CUDA version 12.1 and torch_sparse has CUDA version 11.8. Please reinstall the torch_sparse that matches your PyTorch install.
  warnings.warn(f"An issue occurred while importing 'torch-sparse'. "
Traceback (most recent call last):
  File "preprocess.py", line 7, in <module>
    from dataset import get_dataset, get_largest_cc, get_eigh, Transd2Ind, DataGraphSAINT
  File "/media/visionx/monica/project24/GDEM/dataset.py", line 23, in <module>
    from utils import normalize_adj
  File "/media/visionx/monica/project24/GDEM/utils.py", line 14, in <module>
    from torch_sparse import SparseTensor
  File "/home/visionx/anaconda3/envs/gdem/lib/python3.8/site-packages/torch_sparse/__init__.py", line 32, in <module>
    raise RuntimeError(
RuntimeError: Detected that PyTorch and torch_sparse were compiled with different CUDA versions. PyTorch has CUDA version 12.1 and torch_sparse has CUDA version 11.8. Please reinstall the torch_sparse that matches your PyTorch install.

原因分析与解决

一开始看到这个的时候我是懵逼的,为什么呢?我明明按照requirements.txt安装了

pip install -r requirements.txt

requirements.txt内容如下:

deeprobust==0.2.9
gdown==4.7.3
networkx==3.2.1
numpy==1.26.3
ogb==1.3.6
pandas==2.1.4
scikit-learn==1.3.2
scipy==1.11.4
torch==2.1.2
torch_geometric==2.4.0
torch-sparse==0.6.18

但首先是报错如下图(解决办法可以看我的另一篇博客:点击这里​​​​​​​):

在这里插入图片描述

解决完上面这个问题之后呢,又会出现新的问题:RuntimeError: PyTorch has CUDA version 12.1 and torch_sparse has CUDA version 11.8,显然就是版本version不对,但是为什么会这样呢?我们从pytorch故那王找到了答案:
在这里插入图片描述

我们会发现同样是torch2.1.2,但是却对应了不同的cuda版本,也就是我们在pip install -r requirements.txt的时候torch里的2.1.2并不是cuda11.8的而是cuda12.1的,这个大家也熟,pip install一般就是说安装最新版本的,所以出了问题。那,怎么解决呢?

很多人的想法就是直接:

pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu118

但别忘了,pip install是安装最新的,这个版本比我们现在已有的旧,所以安装不上!!!

所以需要先卸载:

pip uninstall torch

然后再安装:

pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu118

这样就ok了!

相关链接

在这里插入图片描述

完结撒花

就让一切随风~







鳗小鱼

【已解决】RuntimeError: PyTorch has CUDA version 12.1 and torch_sparse has CUDA version 11.8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坦笑&&life

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值