求助:CUDA的RuntimeError:cuda runtime error (30)
from torchvision import models
use_gpu = torch.cuda.is_available()
model_ft = models.resnet18(pretrained = True)
if use_gpu:
model_ft = model_ft.cuda()
运行后报错:
RuntimeError Traceback (most recent call last)
<ipython-input-6-87942ec8aa13> in <module>()
11 model_ft.fc = nn.Linear(num_ftrs , 5)#############################2
12 if use_gpu:
---> 13 model_ft = model_ft.cuda()
14 #criterion = nn.MultiMarginLoss()
15 criterion = nn.CrossEntropyLoss()
~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in cuda(self, device)
258 Module: self
259 """
--> 260 return self._apply(lambda t: t.cuda(device))
261
262 def cpu(self):
~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _apply(self, fn)
185 def _apply(self, fn):
186 for module in self.children():
--> 187 module._apply(fn)
188
189 for param in self._parameters.values():
~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _apply(self, fn)
191 # Tensors stored in modules are graph leaves, and we don't
192 # want to create copy nodes, so we have to unpack the data.
--> 193 param.data = fn(param.data)
194 if param._grad is not None:
195 param._grad.data = fn(param._grad.data)
~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in <lambda>(t)
258 Module: self
259 """
--> 260 return self._apply(lambda t: t.cuda(device))
261
262 def cpu(self):
~\Anaconda3\lib\site-packages\torch\cuda\__init__.py in _lazy_init()
160 "Cannot re-initialize CUDA in forked subprocess. " + msg)
161 _check_driver()
--> 162 torch._C._cuda_init()
163 _cudart = _load_cudart()
164 _cudart.cudaGetErrorName.restype = ctypes.c_char_p
RuntimeError: cuda runtime error (30) : unknown error at ..\aten\src\THC\THCGeneral.cpp:87
Win10+Anaconda5.0.1+python3.6.3
Cuda driver version 10.1
Cuda Toolkit 10.1
pytorch 1.0.1
显卡GeForce GTX 1050 Ti
nvidia驱动版本430.39
求助啊!!!
https://github.com/pytorch/pytorch/issues/20990
链接答案来源
import torch
torch.cuda.current_device()
torch.cuda._initialized = True
就加上上面两行就行了。
估计是你的显示卡已经被别的程序占用了,重新启动,关闭不必要的程序,包括网页、防病毒软件
再不行,考虑是你的pyTorch或者cuDNN没有安装对,重新安装匹配兼容的版本
我在官网上没有看到关于支持cuda10.1的说明,可能是cuda版本过高导致不兼容匹配。可以装cuda10.0或者9.x试试
我也有一样的问题,找了一天发现vscode,jupyter,pycharm这类交互式的都不行,但是直接运行文件可以。
这点不知道是不是和你一样,我重装了ipython,再重启就好了,再也没有出现过这个问题。
pip uninstall ipython
pip install ipython
我的程序昨天还可以用,今天突然就报了这个错,研究无果后,发现我的英伟达显卡没有驱动了,重新装上显卡驱动就好了,不知道是不是因为我昨天晚上更新了系统,但是也觉得更新系统把显卡驱动整没了很神奇。从这里看出,先判断是否有显卡,再使用是一个比较好的习惯
我遇到这个问题,首先查看了一下显卡驱动 nvidia-smi 发现显卡驱动没问题.同时发现显存有被占用, 通过这个命令 fuser -v /dev/nvidia*