BUG
之前都能正常用pytoch.cuda,两个星期没用,忽然就报错了。
报错如下:
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 /opt/conda/conda-bld/pytorch_1614378083779/work/c10/cuda/CUDAFunctions.cpp:109.)
return torch._C._cuda_getDeviceCount() > 0
并且
print(torch.cuda.is_available())
#输出
False
但是我一切都是正常的。
这里的一切指:
- nivida470和cuda11.4版本一致
- cuda11.4和pytorch11.3版本一致【pytorch没有11.4,11.3可以适配】
- 环境变量设置正确
print(torch.__version__)显示 “XX+cu11.3”.
尝试:
- 卸载&重新安装cuda版本的pytorch
- 在环境变量中增加
export CUDA_VISIBLE_DEVICES=0
#也尝试了
export CUDA_VISIBLE_DEVICES=0,1,2,
- 更新nvidia-modprobe
apt-get install nvidia-modprobe
但都不能解决问题。
最终解决方案:
直到!!!我重启,重启大法好!
给print(torch.cuda.is_available()) False
的兄弟们提供一个可能的解决方案