炼丹之初不知为何突然报个错,说是pytorch和cuda版本不兼容,搜索了一下,好像原因是cuda版本太高了,没有相应的pytorch支持(我原本安装的cuda版本是12.4),好在cuda可以向下兼容。
!!默认你已经安装过pytorch和cuda了!!
!!本人的python为conda环境,在你对应的python环境进行应该也行,没试过,可以试试,如果可以,请在评论区分享一下哦
一、报错
AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'
AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'
二:解决办法
思路:按照pytorch版本去降低cuda的版本
1、检查cuda版本
参照这个博主的博客:查看NVIDIA CUDA版本号的四种方法_51CTO博客_怎么查看cuda的版本
2、检查脚本(开一个python文件哦)
import torch
print("Torch version:", torch.__version__)
print("CUDA version:", torch.version.cuda)
print("CUDA available:", torch.cuda.is_available())
if torch.cuda.is_available():
print("CUDA device:", torch.cuda.get_device_name(torch.cuda.current_device()))
该检查脚本可以检查到pytorch版本,如果只出现3个输出证明版本不兼容,如果出现4个输出则证明兼容了。第一次运行一般只有3个输出。
3、查找pytorch对应的cuda版本
①本人的pytorch版本为2.2.0
②访问Previous PyTorch Versions | PyTorch,找到对应版本的位置:
③复制一条你喜欢的或者适合你的去install就好了
④报错情况:最后说没有连接上,则可能是网络问题了,可以开 梯 子 或者关掉试试。
4、再次运行检查脚本
如果出现4个输出就完成了。