we need gpu gc when complete use model
Closed this issue · 2 comments
kylelee commented
I have wrote a new function gpu.gc
kylelee commented
import gc
import torch
def gpu_gc():
gc.collect()
if torch.cuda.is_available():
# with torch.cuda.device(DEVICE):
torch.cuda.empty_cache()
torch.cuda.ipc_collect()
elif torch.backends.mps.is_available():
try:
from torch.mps import empty_cache
empty_cache()
except Exception as e:
print(e)
print("if you are on macOS, suggest upgrade pytorch >= 2.0.0")
huajianmao commented
Thanks for your suggestion.
We have gc for cuda in lifespan
with the code after the yield
.
And I have added gc for the mps device according to your suggestion in the commit 81d6cc9.
For the torch version problem, we have declared that the torch version should be >= 2.0
in the requirements.txt
Thanks.