假设我创建了一个张量并将其放在 GPU 上,以后不需要它并想释放分配给它的 GPU 内存;我该怎么做?
import torch
a=torch.randn(3,4).cuda() # nvidia-smi shows that some mem has been allocated.
# do something
# a does not exist and nvidia-smi shows that mem has been freed.
我努力了:
del a
del a; torch.cuda.empty_cache()
但它们都不起作用。
MYYA
相关分类