Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to remove model from gpu memory? #237

Open
xfchen0912 opened this issue Mar 19, 2022 · 1 comment
Open

how to remove model from gpu memory? #237

xfchen0912 opened this issue Mar 19, 2022 · 1 comment

Comments

@xfchen0912
Copy link

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

@tomhennigan
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants