Skip to content

Fix AdaptiveMuon step for param groups added after init - #313

Merged
skyw merged 1 commit into
NVIDIA-NeMo:mainfrom
v0ropaev:fix/adaptive-muon-add-param-group
Oct 20, 2026
Merged

skyw merged 1 commit into
NVIDIA-NeMo:mainfrom
v0ropaev:fix/adaptive-muon-add-param-group

Conversation

@v0ropaev

Copy link
Copy Markdown
Contributor

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 calling opt.add_param_group({"params": [w2]}) and opt.step() with gradients on both parameters raises KeyError: 'beta2' from the group["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 from self.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_init to tests/test_adaptive_muon.py, parameterized over adamuon, normuon and namo. On main it fails for all three with KeyError: '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=42 and 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.

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>
@copy-pr-bot

copy-pr-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Fixes AdaptiveMuon for parameter groups added after construction.

  • AdaptiveMuon gives added parameter groups the right moment settings.

Reviews (1) · Last reviewed commit: "Fix AdaptiveMuon step for param groups a..." · Reviewed by Greptile

@skyw skyw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Note that add_param_group is not something regularly tested across the repo, there may be other holes.

@skyw

skyw commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

/ok to test bc4b7ed

@skyw
skyw merged commit a966f00 into NVIDIA-NeMo:main Oct 20, 2026
31 checks passed

This branch was successfully deployed

2 active deployments
public — bc4b7ede Deployed Oct 20, 2026 by copy-pr-bot[bot] via release / finalize / notify #284
test — bc4b7ede Deployed Oct 20, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #1095
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants