with torch.no_grad(): pass Reference:模型训练或测试时候显存爆掉(RuntimeError:CUDA out of memory)的几种可能及解决方案_洗千帆,还少年的博客-CSDN博客_模型爆显存https://blog.csdn.net/qq_45040216/article/details/126603593