sonnet icon indicating copy to clipboard operation
sonnet copied to clipboard

how to remove model from gpu memory?

Open xfchen0912 opened this issue 2 years ago • 1 comments

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

xfchen0912 avatar Mar 19 '22 08:03 xfchen0912

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.

tomhennigan avatar Mar 24 '22 14:03 tomhennigan