还是想写代码的啊 2019-04-27 23:25 采纳率: 100%
浏览 11570
已采纳

求助: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

求助啊!!!

  • 写回答

6条回答

  • Beccapan 2019-07-19 18:30
    关注

    https://github.com/pytorch/pytorch/issues/20990
    链接答案来源
    import torch
    torch.cuda.current_device()
    torch.cuda._initialized = True
    就加上上面两行就行了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办