在win10上用pytorch和cuda出错,在排除版本出错的情况下,跑如下代码:
import torch print("torch.cuda.is_available() =", torch.cuda.is_available()) print("torch.cuda.device_count() =", torch.cuda.device_count()) print("torch.cuda.current_device() =", torch.cuda.current_device())出错:
torch.cuda.is_available() = True torch.cuda.device_count() = 1 Traceback (most recent call last): File "D:\code\python\nn\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-93-786a6e4d1700>", line 5, in <module> print("torch.cuda.current_device() =", torch.cuda.current_device()) File "D:\code\python\nn\venv\lib\site-packages\torch\cuda\__init__.py", line 351, in current_device _lazy_init() File "D:\code\python\nn\venv\lib\site-packages\torch\cuda\__init__.py", line 163, in _lazy_init torch._C._cuda_init() RuntimeError: CUDA error: unknown error各种百度谷歌,参考如下解决:https://github.com/pytorch/pytorch/issues/17108
果然,我用的是pycharm下面的交互式python console,然后出错: 换回直接在代码里写,就没关系:
神奇,感觉像个bug,等待高人解惑
