问题解决 | RuntimeError: CUDA error: invalid device ordinalCUDA kernel errors
·
错误:
RuntimeError: CUDA error: invalid device ordinal
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
RuntimeError(运行时错误): CUDA 错误:设备序号无效
CUDA 内核错误可能会在其他 API 调用中异步报告,因此下面的堆栈跟踪可能不正确。
为便于调试,可考虑通过 CUDA_LAUNCH_BLOCKING=1。
使用 `TORCH_USE_CUDA_DSA` 进行编译,以启用设备端断言。
错误分析
在进行测试时,运行gradio的api文件,服务器有5张卡,开了jupyter lab,只指定了一张卡,然后出现以上问题
尝试
一般来说,因为是一张卡,所以默认指定cuda:0,尝试了3种方法
# 方法1
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
# 方法2
CUDA_VISIBLE_DEVICES=0 python gradio_api.py
-> 运行后出现同样错误
# 方法3
CUDA_VISIBLE_DEVICES=1 python gradio_api.py
-> RuntimeError: No CUDA GPUs are available
最终解决:
gradio_api.py中含有 cuda,device的指定代码
快速搜索键:Ctrl+F , 搜索cuda/device,查看是否指定号码
我的错误是因为cuda处指定cuda:0,而device=1,所以出现错误。
更多推荐
已为社区贡献13条内容
所有评论(0)