A guide to recovering from CUDA Out of Memory and other exceptions

use torch.cuda.empty_cache()
it will save some memory for you.