CUDA kernel errors might be asynchronously reported at some other API call 错误解决

Posted 厚积薄发FY

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CUDA kernel errors might be asynchronously reported at some other API call 错误解决相关的知识,希望对你有一定的参考价值。

Pytorch项目报错:

CUDA kernel errors might be asynchronously reported at some other API call

在运行基于pytorch的深度学习项目时,有时候会遇到上述错误,并且在报错时没有定位到正确的位置。


原因分析:

这里查阅了很多网上的相关资料,说是分类数目和模型里的实际分类数目不匹配,大家可以仔细查看一下这个。也有说是在计算logits之前先进性softmax归一化,大家也可以试试这个方法。

我仔细检查自己的项目分类数目,发现并不是上述原因,因此需要先定位到实际导致错误的代码位置。


解决方案:

我们的目的是定位到实际导致报错的代码位置,只需要在最开头添加:

import os
os.environ['CUDA_LAUNCH_BLOCKING'] = '1'

这时候报错会定位到实际位置,大家对症下药解决即可。

以上是关于CUDA kernel errors might be asynchronously reported at some other API call 错误解决的主要内容,如果未能解决你的问题,请参考以下文章

RuntimeError:CUDA error:no kernel image is available for execution on the device报错解决(亲测)

Error resolving template [xxx], template might not exist or might not be exist

报错Error resolving template template might not exist or might not be accessible解决方案

解决Error resolving template template might not exist or might not be accessible问题

异常:Error resolving template "xxx", template might not exist or might not be accessible...解

Error resolving template: template might not exist or might not be accessible是一句缩水报错?