Repository navigation
Fix AdaptiveMuon step for param groups added after init - #313
Merged
skyw merged 1 commit intoOct 20, 2026
Merged
Conversation
AdaptiveMuon set beta2 and eps with setdefault on the param groups that existed when the constructor ran, but did not put them in the optimizer defaults. torch.optim.Optimizer.add_param_group fills missing hyperparameters from self.defaults only, so a group added later had no beta2 or eps and step() failed with KeyError: 'beta2'. Pass beta2 and eps to the base class as keyword arguments so they land in the defaults like lr and momentum, and drop the setdefault loop. Groups that set their own beta2 or eps keep them. Signed-off-by: Dmitry Voropaev <dy.voropaev@gmail.com>
Contributor
[Medium impact] The PR appears safe to merge. SummaryFixes
Reviews (1) · Last reviewed commit: "Fix AdaptiveMuon step for param groups a..." · Reviewed by Greptile |
skyw
approved these changes
Oct 20, 2026
skyw
left a comment
Contributor
There was a problem hiding this comment.
LGTM.
Note that add_param_group is not something regularly tested across the repo, there may be other holes.
Contributor
|
/ok to test bc4b7ed |
This branch was successfully deployed
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.
AdaptiveMuon fails on the first step after a param group is added with add_param_group. For example, building
AdaptiveMuon([w1], lr=0.01, momentum=0.9, weight_decay=0.0), then callingopt.add_param_group({"params": [w2]})andopt.step()with gradients on both parameters raisesKeyError: 'beta2'from thegroup["beta2"]lookup in step(). Any training loop that adds layers to the optimizer partway through, such as progressive unfreezing, runs into this.The cause is that beta2 and eps were set with setdefault on the groups that existed at construction time, but they never went into
self.defaults. torch's add_param_group fills missing hyperparameters only fromself.defaults, so a later group ended up with lr, momentum and weight_decay and nothing else.The fix passes beta2 and eps to OrthogonalizedOptimizer through its existing
**kwargs, which already go into the defaults dict, and removes the setdefault loop. Per-group values still win, so{"params": [w], "beta2": 0.5}keeps 0.5.I added
test_step_with_param_group_added_after_initto tests/test_adaptive_muon.py, parameterized over adamuon, normuon and namo. On main it fails for all three withKeyError: 'beta2', and with the change it passes. I ran test_adaptive_muon.py, test_orthogonalized_optimizer.py, test_registry.py, test_weight_update_hooks.py and test_weight_decay_mixin.py with--device=cpu, once with no seed, once with--seed=42and once with--seed=3735928559, all passing on torch 2.8.0 CPU on macOS. I did not run the CUDA suite. ruff 0.9.9 check and format, the end-of-file and trailing-whitespace hooks, and mypy 1.19.1 on adaptive_muon.py are clean.