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

Add option to save optimizer and scheduler state during training, and to resume training from these states #3640

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

alanakbik
Copy link
Collaborator

@alanakbik alanakbik commented Mar 14, 2025

This PR adds functionality to save and load optimizer and scheduler states. You can enable this by setting save_optimizer_state=True in any of the train methods of ModelTrainer (train(), fine_tune(), or train_custom()). When enabled, both the optimizer state and the scheduler state are saved in the model file.

If you load a model that contains these states and pass it to the ModelTrainer, it will automatically load them if you continue training the model.

Changes:

  • Modified ModelTrainer._save_model to save scheduler states from active plugins
  • Added scheduler_state_dict handling in Model._get_state_dict and load methods
  • Updated scheduler plugins (LinearScheduler and AnnealOnPlateau) to load their states when resuming training

Closes #3444

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…True
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

Successfully merging this pull request may close these issues.

[Bug]: optimizer state not saved
1 participant