Repository navigation
refactor(ema)!: track a module's trainable parameters by reference - #1
Merged
Merged
Conversation
EMA now takes the module and keeps references to its trainable parameters, so update and swap no longer take a tensor mapping.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Make
EMAtrack a module's trainable parameters directly, so callers no longer pass tensors on every call.Motivation
{n: p for n, p in model.named_parameters() if p.requires_grad})updateandswaptookmodel.state_dict()on each call, which rebuilds the whole state dict every step only to look tensors up by nameChanges
EMA(module, decay)keeps references to the module'srequires_gradparameters and raises if there are noneupdate(decay=None)andswap()take no tensors;swapstill exchanges in place and swaps back on exitstate_dict,load_state_dict, andtoare unchanged, and keys stay the parameter names, so saved EMA states still loadMigration
Pass the unwrapped module (not a DDP or
torch.compilewrapper) so that names match the module'sstate_dict.