Pytorch报错RuntimeError: CUDA error: device-side assert triggered

参考:

  • https://blog.csdn.net/BetrayFree/article/details/134267306

完整报错如下:

shell 复制代码
Traceback (most recent call last):
  File "/home/yingmuzhi/SpecML2/test.py", line 150, in <module>
    trainer.fit(model, data)
  File "/home/yingmuzhi/SpecML2/core.py", line 486, in fit
    self.fit_epoch()
  File "/home/yingmuzhi/SpecML2/core.py", line 496, in fit_epoch
    loss = self.model.training_step(self.prepare_batch(batch))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yingmuzhi/SpecML2/core.py", line 394, in training_step
    self.plot('loss', l, train=True)
  File "/home/yingmuzhi/SpecML2/core.py", line 384, in plot
    self.board.draw(x, value.to(cpu()).detach().numpy(),
                       ^^^^^^^^^^^^^^^
RuntimeError: CUDA error: device-side assert triggered
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.

有很多愿意会导致这个CUDA triggered的Error,我的问题是在于网络前半部分都是卷积层,在最后一层使用了全连接层,而在最后一层我的输出并没有和类别相匹配。例如,原先多分类我用的是十个类别,更改成二十二种类别后忘记改输出的类别了,将类别和输出channel相匹配便解决了。

相关推荐
甲维斯1 天前
坦克大战测试全翻车了!豆包,DeepSeek,Qwen,GPT,Claude
前端·人工智能·游戏开发
若丶相见1 天前
AI 大模型零基础知识扫盲
人工智能
曲幽1 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
猿人谷1 天前
不只是 CPU 阈值:STAR 如何用 GAT + Transformer 做容器级自动扩缩容?
人工智能·算法
说了很好1 天前
PyTorch从零搭建DDPM:时间嵌入+UNet网络+扩散调度完整复现
人工智能
Bigfish_coding1 天前
前端转agent-【python】-06 长期记忆(向量数据库 + 嵌入)
人工智能
小林ixn1 天前
别再手写Prompt了!用AI Loop实现自动化自我迭代,效率提升10倍
人工智能·自动化运维
说了很好1 天前
逐行注释DDPM源码:正向加噪、逆向去噪、MSE损失全流程复现
人工智能
用户556918817531 天前
#从脚本到独立程序:Python + Playwright 批量抓取的完整踩坑记录
python·自动化运维
Dilee1 天前
Spring AI 1.1.7 接入 MCP:Filesystem Server 最小 Demo
人工智能·后端