-
Notifications
You must be signed in to change notification settings - Fork 55
Sophiex/dev/monitor collapse #1814
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
Open
sophie-xhonneux
wants to merge
10
commits into
develop
Choose a base branch
from
sophiex/dev/monitor-collapse
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.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
71d2cce
Add collapse monitoring
1d29611
Fix bug
bc92ae7
Fix SVD computation failing
7693c19
Reduce variables logged
7f8de00
Fix EMA beta value computation
c3eb019
Refactor get_current_beta to ema.py
59a0a89
Sensible default for ema in jepa
sophie-xhonneux ebbbf33
Allow collapse monitoring for forecasting
97f9734
Fix no collapse monitoring for forecasting
0111e75
Try to fix forecasting
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ def __init__( | |
| self.rampup_ratio = rampup_ratio | ||
| self.ema_model = empty_model | ||
| self.is_model_sharded = is_model_sharded | ||
| self.batch_size = 1 | ||
| # Build a name → param map once | ||
| self.src_params = dict(self.original_model.named_parameters()) | ||
|
|
||
|
|
@@ -55,16 +56,33 @@ def requires_grad_(self, flag: bool): | |
| for p in self.ema_model.parameters(): | ||
| p.requires_grad = flag | ||
|
|
||
| def get_current_beta(self, cur_step: int) -> float: | ||
| """ | ||
| Get current EMA beta value for monitoring. | ||
|
|
||
| The beta value determines how much the teacher model is updated towards | ||
| the student model at each step. Higher beta means slower teacher updates. | ||
|
|
||
| Args: | ||
| cur_step: Current training step (typically istep * batch_size). | ||
|
|
||
| Returns: | ||
| Current EMA beta value. | ||
| """ | ||
| halflife_steps = self.halflife_steps | ||
| if self.rampup_ratio is not None: | ||
| halflife_steps = min(halflife_steps, cur_step / self.rampup_ratio) | ||
| beta = 0.5 ** (self.batch_size / max(halflife_steps, 1e-6)) | ||
| return beta | ||
|
Collaborator
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. Shouldn't we continuously update beta and store it as a class member variable, and just return it in the function.
Contributor
Author
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. this is what is happening |
||
|
|
||
| @torch.no_grad() | ||
| def update(self, cur_step, batch_size): | ||
| # ensure model remains sharded | ||
| if self.is_model_sharded: | ||
| self.ema_model.reshard() | ||
| # determine correct interpolation params | ||
| halflife_steps = self.halflife_steps | ||
| if self.rampup_ratio is not None: | ||
| halflife_steps = min(halflife_steps, cur_step / 1e3 * self.rampup_ratio) | ||
| beta = 0.5 ** (batch_size / max(halflife_steps * 1e3, 1e-6)) | ||
| self.batch_size = batch_size | ||
| beta = self.get_current_beta(cur_step) | ||
|
|
||
| for name, p_ema in self.ema_model.named_parameters(): | ||
| p_src = self.src_params.get(name, None) | ||
|
|
||
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.
The default config is on forecasting so we shouldn't need this in there.
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 think it would be interesting to measure anyway, but if you feel strongly. I can remove it