-
Notifications
You must be signed in to change notification settings - Fork 1
Add auto logging of trainer metadata and optimizer state saving to help with resumation of training #39
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
Merged
Merged
Add auto logging of trainer metadata and optimizer state saving to help with resumation of training #39
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b8000e8
Add optimizer state saving functionality as new trainer contract, upd…
wli51 3c19922
Implement AutoTrainerLogger for adding auto logging of certain useful…
wli51 bd3036b
Add unit tests for model and optimizer state saving functionality
wli51 7689071
Fix MlflowLogger to use _log_trainer_artifact for model weight loggin…
wli51 3b0d53b
Rename _log_trainer_artifact function name with _save_and_log_trainer…
wli51 f6248b9
Update DatasetManifest serialization to stop using depracated functio…
wli51 ac2c0b8
Refactor protocol and abstract class definition to make the `file_nam…
wli51 cc3ab85
Remove unused _epochs attribute from TrainerProtocol class
wli51 309927a
Refactor AbstractTrainer to enforce integer type for epoch parameter …
wli51 6b13039
Update CHANGELOG.md for version 0.4.9: Add initial training resume su…
wli51 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/virtual_stain_flow/trainers/trainer_utils/save_optimizer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| from pathlib import Path | ||
| from typing import Optional, List | ||
|
|
||
| import torch | ||
|
|
||
| from ..trainer_protocol import TrainerProtocol | ||
|
|
||
|
|
||
| def save_optimizer_state( | ||
| trainer: 'TrainerProtocol', | ||
| save_path: Path, | ||
| file_name_prefix: str = 'optimizer', | ||
| file_name_suffix: Optional[str] = None, | ||
| file_ext: str = '.pth', | ||
| ) -> List[Path]: | ||
|
|
||
| if file_name_suffix is None: | ||
| file_name_suffix = f"{trainer.epoch}" | ||
|
|
||
| optimizer = trainer.optimizer | ||
|
|
||
| if optimizer is None: | ||
| return [] | ||
|
|
||
| save_file = save_path / f"{file_name_prefix}_{file_name_suffix}{file_ext}" | ||
|
|
||
| torch.save( | ||
| optimizer.state_dict(), | ||
| save_file | ||
| ) | ||
|
|
||
| if save_file.exists(): | ||
| return [save_file] | ||
|
|
||
| return [] | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.