-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(training,rollout)!: Rollout Schedulers #46
Draft
HCookie
wants to merge
14
commits into
develop
Choose a base branch
from
14-training-rollout-scheduling
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
973349f
Rollout Schedulers
HCookie fcf1f1f
Incrementer
HCookie a712c48
Improve incrementor
HCookie 72e0bf9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c199c0e
Precommit fixes
HCookie 69a5d9a
Add changelog entry
HCookie d5a0ff9
Seed random every time and remove -1 for inf
HCookie a0759ce
Merge commit 'd5a0ff9c20b0560da9bb540a1e63a4e9015dcc79' into 145-roll…
HCookie 249144e
MIGRATION COMMIT
HCookie 71f99f3
Merge commit '249144e5c4ea3222e2d5eddec80025ce3acd5a5d' into 145-roll…
HCookie 7659721
Merge branch 'develop' into 145-rollout-scheduling
HCookie 433362a
Update warnings
HCookie 3ac7dcd
Add tests
HCookie 71a9e08
pre-commit
HCookie 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 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 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 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 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 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 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
70 changes: 70 additions & 0 deletions
70
training/src/anemoi/training/diagnostics/callbacks/rollout.py
This file contains 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,70 @@ | ||
# (C) Copyright 2024 Anemoi contributors. | ||
# | ||
# This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# In applying this licence, ECMWF does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an intergovernmental organisation | ||
# nor does it submit to any jurisdiction. | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
import pytorch_lightning as pl | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class UpdateRollout(pl.callbacks.Callback): | ||
"""Update Rollout values in datamodule.""" | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
def _update_rollout( | ||
self, | ||
trainer: pl.Trainer, | ||
pl_module: pl.LightningModule, | ||
epoch: int | None = None, | ||
step: int | None = None, | ||
) -> None: | ||
rollsched = pl_module.rollout | ||
with rollsched.at(epoch=epoch, step=step): | ||
rollout = rollsched.current_maximum | ||
|
||
LOGGER.debug("Propagating rollout value %s to datamodule", rollout) | ||
trainer.datamodule.update_rollout(rollout=rollout) | ||
|
||
def on_load_checkpoint(self, trainer: pl.Trainer, pl_module: pl.LightningModule, checkpoint: dict) -> None: | ||
""" | ||
Update the rollout values in the datamodule when loading a checkpoint. | ||
|
||
Parameters | ||
---------- | ||
trainer : pl.Trainer | ||
Pytorch Lightning trainer | ||
pl_module : pl.LightningModule | ||
Model | ||
checkpoint : dict | ||
Checkpoint dictionary | ||
""" | ||
self._update_rollout(trainer, pl_module, epoch=checkpoint["epoch"], step=checkpoint["global_step"]) | ||
|
||
def on_validation_epoch_end(self, trainer: pl.Trainer, pl_module: pl.LightningModule, *_) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone sets the limit_batches for validation to 0, to skip validation this hook wouldn't be triggered? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I'll need to take a look. |
||
""" | ||
Update the rollout values in the datamodule every validation epoch. | ||
|
||
Parameters | ||
---------- | ||
trainer : pl.Trainer | ||
Pytorch Lightning trainer | ||
pl_module : pl.LightningModule | ||
Model | ||
""" | ||
if trainer.sanity_checking: | ||
return | ||
|
||
# Offset of 1 needed as the epoch counter does not increment | ||
# until after the epoch ends. | ||
self._update_rollout(trainer, pl_module, epoch=trainer.current_epoch + 1) |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am probably just being slow but how does this interact with the
limit batches
? What would be the difference between doing the above, and the 'old configuration' with a limit batches of 200000?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
limit_batches
ends the training, this will continue on, and then begin updating the rollout.