How to remove the model of transformers in GPU memory
from transformers import CTRLTokenizer, TFCTRLLMHeadModel
tokenizer_ctrl = CTRLTokenizer.from_pretrained('ctrl', cache_dir='./cache', local_files_only=True)
model_ctrl = TFCTRLLMHeadModel.from_pretrained('ctrl', cache_dir='./cache', local_files_only=True)
print(tokenizer_ctrl)
gen_nlp  = pipeline(&quot;text-generation&quot;, model=model_ctrl, tokenizer=tokenizer_ctrl, device=1, return_full_text=False)

Hello, my codes can load the transformer model, for example, CTRL here, into the gpu memory.
How to remove it from GPU after usage, to free more gpu memory?
show I use torch.cuda.empty_cache() ?
Thanks.

You can simply del tokenizer_ctrl and then use torch.cuda.empty_cache().
See this thread from pytorch forum discussing it.
