【解决方案】CUDA kernel errors might be asynchronously reported at some other API call

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

目录

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

背景

详细报错

原因分析

解决步骤

总结


背景

在训练 mmseg 工程时遇到报错 “CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.”,该报错信息模糊,难以直接定位问题。

详细报错

报错提示 CUDA 内核错误可能在其他 API 调用中异步报告,导致堆栈跟踪可能不准确。

原因分析

报错涉及 CUDA 内核错误,但由于异步报告机制,难以直接确定具体错误原因和代码位置。

解决步骤

定位报错详细信息:在代码起始位置添加import osos.environ['CUDA_LAUNCH_BLOCKING'] = '1'两行代码,使报错定位到实际位置,便于针对性解决问题。

检查 num_class 设置:查看数据集中 label 对应的值是否超出 num_class 的设定范围。例如,若 num_class 设为 3,label 值应在 [0, 1, 2] 内,不能有其他值。(因为工程里的label默认是从0开始计算的)

检查模型输出尺寸:模型输入尺寸的通道数一般为 3,而输出尺寸的通道数应与 num_class 大小一致,需确保模型的 out_channel 已正确设置为 num_class。

总结

Python 代码报错通常较易理解,但遇到模糊报错时,可通过设置os.environ['CUDA_LAUNCH_BLOCKING'] = '1'打印详细报错信息来定位和修改代码。此次经验表明,CUDA kernel errors 报错很可能是 out_channel 和 num_class 不对应导致的。

【常见模块错误】

如果出现模块错误

进入控制台输入:建议使用国内镜像源

pip install 模块名称 -i https://mirrors.aliyun.com/pypi/simple

我大致罗列了以下几种国内镜像源:

清华大学
https://pypi.tuna.tsinghua.edu.cn/simple
     
阿里云
https://mirrors.aliyun.com/pypi/simple/
     
豆瓣
https://pypi.douban.com/simple/
     
百度云
https://mirror.baidu.com/pypi/simple/
     
中科大
https://pypi.mirrors.ustc.edu.cn/simple/
     
华为云
https://mirrors.huaweicloud.com/repository/pypi/simple/
     
腾讯云
https://mirrors.cloud.tencent.com/pypi/simple/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yan-英杰

感谢大佬打赏,我会更加努力创作

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值