pytorch程序异常后删除占用的显存

1-删除模型变量

del model_define

2-清空CUDA cache

torch.cuda.empty_cache()

3-步骤2(异步)需要一定时间,设置时延

time.sleep(5)

完整代码如下:

del styler  
torch.cuda.empty_cache() 
time.sleep(5)

猜你喜欢

转载自blog.csdn.net/dlhlSC/article/details/86687789