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

Memory leaked when the model and trainer were reinitialized #3136

Open
earthlovebpt opened this issue Dec 14, 2024 · 3 comments · May be fixed by #3144
Open

Memory leaked when the model and trainer were reinitialized #3136

earthlovebpt opened this issue Dec 14, 2024 · 3 comments · May be fixed by #3144

Comments

@earthlovebpt
Copy link

earthlovebpt commented Dec 14, 2024

examples/training/data_augmentation/train_sts_seed_optimization.py

  • I ran this code in Colab, and the memory usage kept increasing whenever I ran the next trainer.
Screenshot 2567-12-14 at 23 43 31
  • After I removed trainer and model at the end of each training, the memory usage was still high.
Screenshot 2567-12-14 at 23 56 18
@tomaarsen
Copy link
Collaborator

Hello!

I'm able to reproduce this. I'll try and see which object is not being cleaned up as it should be.

  • Tom Aarsen

@earthlovebpt
Copy link
Author

Thank you!!!
Are there any alternatives to avoid reinitializing the model and trainer?

@tomaarsen
Copy link
Collaborator

tomaarsen commented Dec 23, 2024

When doing seed optimization? Not really - this is the safest option. During "normal" training, you usually only have to initialize a model and trainer once.

I've discovered the issue, and will be creating a patch soon. In the meantime, you can add this line right at the end of the for-loop code block instead of the del trainer, model.

model.model_card_data.trainer = None

It should help a lot with the memory usage.

  • Tom Aarsen

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