🎃 Valiukas

jump to main content

pytorch: garbage collection freeing up memory

Sep 27, 2022

This function will free up your memory if you're having some problems:

import gc

def garbage_collect(model):
    del model
    gc.collect()
    torch.cuda.empty_cache()