当前位置:   article > 正文

PyTorch 错误 RuntimeError: CUDA error: device-side assert triggered

runtimeerror: cuda error: device-side assert triggered

PyTorch 错误 RuntimeError: CUDA error: device-side assert triggered

flyfish
具体提示如下

/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [2,0,0] Assertion `t >= 0 && t < n_classes` failed.
/pytorch/aten/src/THCUNN/ClassNLLCriterion.cu:108: cunn_ClassNLLCriterion_updateOutput_kernel: block: [0,0,0], thread: [20,0,0] Assertion `t >= 0 && t < n_classes` failed.
Traceback (most recent call last):
  File "train_feature.py", line 65, in run
    loss.backward()
  File "/media/ubuntu/data/pytorch1.7/lib/python3.6/site-packages/torch/tensor.py", line 221, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/media/ubuntu/data/pytorch1.7/lib/python3.6/site-packages/torch/autograd/__init__.py", line 126, in backward
    grad_tensors_ = _make_grads(tensors, grad_tensors_)
  File "/media/ubuntu/data/pytorch1.7/lib/python3.6/site-packages/torch/autograd/__init__.py", line 51, in _make_grads
    new_grads.append(torch.ones_like(out, memory_format=torch.preserve_format))
RuntimeError: CUDA error: device-side assert triggered
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

重点提示在这Assertion t >= 0 && t < n_classes failed.
此错误的原因是模型输出的类别与标签的类别个数不一致
例如模型输出3类,但标签里有4类
可以该model的输出或者去除标签的一类,总之类别数目一致即可解决

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/89212
推荐阅读
相关标签
  

闽ICP备14008679号