sonnet
sonnet copied to clipboard
how to remove model from gpu memory?
I have model_a and model_b, is there any elegant way to remove model_a from gpu memory after i copy weights from model_a to model_b. Except for save and reload from disk
HI @xfchen0912 , in TensorFlow 2 memory is freed eagerly when there are no more references to the model in Python. So you can do something like:
model_a = ...
model_b = ...
copy_weights(model_a, model_b)
del model_a # If there are no other references to model_a GPU memory associated with it will be released.