pytorch - CUDA 错误 59:触发了设备端断言
问题描述
我使用 Pytorch 收到上述错误,并带有以下断言:
/opt/conda/conda-bld/pytorch_1565272269120/work/aten/src/ATen/native/cuda/IndexKernel.cu:60: lambda [](int)->auto::operator()(int)->auto: block: [1,0,0], thread: [127,0,0]
assertion `index >= -size[i] && index < size at] && "index out of bounds"` failed
我已经看到了这个问题的其他解决方案,这些解决方案描述了由于标签不是来自 (0, num_classes-1) 等原因。但是,我已经确保在我的情况下,并且在计算铰链损失时出现错误,如下所示:
diff_hinge_loss+= F.hinge_embedding_loss( neg_dist - pos_dist, torch.tensor(-1).to(cuda), args.diff_margin, reduction='sum').to(cuda)
最初训练时一切正常,但是在训练某些时期后,计算铰链损失时出现 CUDA 运行时错误。
完整的错误跟踪:
/opt/conda/conda-bld/pytorch_1565272269120/work/aten/src/ATen/native/cuda/IndexKernel.cu:60: lambda [](int)->auto::operator()(int)->auto: block: [1,0,0], thread: [127,0,0]
Assertion `index >= -sizes[i] && index < sizes[i] && "index out of bounds"` failed.
Traceback (most recent call last):
File "ours-vision.py", line 1106, in <module>
penalty_erm, penalty_irm, penalty_ws, penalty_same_ctr, penalty_diff_ctr = train( train_dataset, data_match_tensor, label_match_tensor, phi, opt, opt_ws, scheduler, epoch, base_domain_idx, bool_erm, bool_ws, bool_ctr )
File "ours-vision.py", line 688, in train
diff_hinge_loss+= F.hinge_embedding_loss( neg_dist - pos_dist, torch.tensor(-1).to(cuda), args.diff_margin, reduction='sum').to(cuda)
RuntimeError: CUDA error: device-side assert triggered
解决方案
推荐阅读
- android-studio - Android Studio - 表格行
- android - google playstore 和 Aptoide App store 是如何直接在手机上安装应用而不是只下载 APK 文件的?
- azure - 是否有要运行的查询,以便我可以获取过去 30 天内未登录的用户列表?
- android - 什么是移动设备应用 URI 方案要求/标准?
- html - 是否可以使“a”元素占据包含元素的全部高度和宽度
- reactjs - 如何在单独的文件中从子组件(菜单项)调用父组件方法(关闭菜单)?
- codeigniter - Codeigniter Route 无法在实时服务器上运行,但可以在 localhost 上运行
- android - 无法解析配置 ':shared_preferences:lintClassPath' 的所有文件
- python - Tensorflow 1 到 Tensorflow 2 的转换代码 - detection_graph.as_default() 属性错误
- c# - 从 dsharp c# 中的文本通道获取所有用户