1、前提
我之前一直用的cuda11.8。今天在github上,gitclone了一个代码需要Tested with ROS Noetic on Ubuntu 20.04 with python 3.8.10 and pytorch 1.10。然后我按照要求下载了pytorch。但是最后发现cuda不能使用。
print(torch.version)
2.3.0+cu118
我们可以看到我们是有cuda和pytorch的
print(torch.cuda.is_available())
/home/zhang/APPS/Anaconda/envs/pathplan/lib/python3.9/site-packages/torch/cuda/init.py:118: UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at ../c10/cuda/CUDAFunctions.cpp:108.)
return torch.C.cuda_getDeviceCount() > 0
False
但是输入torch.cuda.is_available()。报错且是false
2、解决
- 步骤一:cuda、pytorch版本对应问题。
- 首先我发现cuda11.8是与pytorch1.1是不兼容的。现在面临的选择是降cuda版本或者提升pytorch版本。
- 我选择的是提升pytorch版本。
- 具体对应规则可以参考
Previous PyTorch Versions | PyTorch
我进行安装后版本也对应上了。但是还是报错。
步骤二:安装
sudo apt install nvidia-modprobe
然后重启电脑就解决了