How to delete a Tensor in GPU to free up memory

Thank you very much!
There is no change in gpu memory after excuting torch.cuda.empty_cache().
I just want to manually delete some unused variables such as grads or other intermediate variables to free up gpu memory. So I tested it by loading the pre-trained weights to gpu, then try to delete it. I’ve tried del, torch.cuda.empty_cache(), but nothing was happening.

1 Like