【报错解决】RuntimeError: CUDA error: out of memory(已解决)
【先赞后看养成习惯】求关注+点赞+收藏
问题描述:在运行python代码中,遇到如下报错
return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
RuntimeError: CUDA error: out of memory
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.

原因分析:这个错误通常表示你的程序在运行时超出了GPU的内存限制,原先我调用的是第一块显卡
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"
解决方法:查看闲置显卡
nvidia-smi

将其改成其他闲置的显卡,改成第五块,代码顺利运行
import os
os.environ["CUDA_VISIBLE_DEVICES"]="4"
文章讲述了在Python代码中遇到CUDAoutofmemory错误的解决方案,原因是程序超出了GPU内存限制。通过检查并修改CUDA_VISIBLE_DEVICES环境变量,将计算设备切换到闲置显卡以解决问题。
1555

被折叠的 条评论
为什么被折叠?



