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相匹配便解决了。

相关推荐
冬奇Lab4 分钟前
Agent 系列(一):Agent 是什么——不只是「会调工具的 LLM」
人工智能·llm·agent
冬奇Lab12 分钟前
RAG 系列(二十四):代码 RAG——让 AI 理解你的代码库
人工智能·llm
南屹川20 分钟前
【算法】动态规划实战:从入门到精通
人工智能
人工智能培训24 分钟前
大模型与传统小模型、传统NLP模型的核心差异解析
人工智能·深度学习·神经网络·机器学习·生成对抗网络
沪漂阿龙28 分钟前
面试题详解:智能客服 Agent 系统全栈拆解——Rasa Pro、对话管理、意图识别、GraphRAG、Qwen 与 RAG 优化实战
人工智能·架构
薛定猫AI1 小时前
【深度解析】Gemini Omni 多模态生成与 Agent 化创作工作流:从视频编辑到 UI 生成的技术演进
人工智能·ui·音视频
羊羊小栈1 小时前
AI赋能电力巡检:智能故障预警系统
人工智能·yolo·目标检测·毕业设计·大作业
Python私教1 小时前
视觉 Agent 爬取 vs Playwright 脚本:Browser Use 2026 选型表
人工智能
Python私教1 小时前
Crawlee StagehandCrawler:自然语言点 Load More 的工程化爬虫
人工智能
南屹川1 小时前
【容器化】Docker实战:从入门到生产环境部署
人工智能