Repository navigation
Add Muon optimizer - #607
Conversation
Signed-off-by: Eldar Kurtic <[email protected]>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds Muon as a second optimizer choice alongside AdamW. A new ChangesMuon Optimizer Integration
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@scripts/train.py`:
- Around line 782-815: The numeric hyperparameter arguments (--weight-decay,
--muon-lr, --muon-momentum, --muon-weight-decay, --muon-ns-steps) lack bounds
validation, allowing invalid values like negative learning rates, non-positive
muon-ns-steps, or out-of-range momentum. Add validation constraints to each
parser.add_argument call by using custom type functions or validation logic that
enforces: non-negative values for weight-decay and muon-weight-decay, positive
values for muon-lr and muon-ns-steps, and valid range (typically 0 to 1) for
muon-momentum. Apply these constraints directly in the argument parser
configuration to catch invalid inputs early before training begins.
In `@src/speculators/train/optimizers.py`:
- Around line 63-70: In the AdamW optimizer initialization within the
config.optimizer == "adamw" block, replace `model.named_parameters()` with
`model.parameters()`. The torch.optim.AdamW optimizer expects an iterable of
parameter tensors, but named_parameters() yields (name, param) tuples which will
cause a runtime error during optimization.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9c2175cb-a757-4c08-adb8-9a69ebb7cec4
📒 Files selected for processing (5)
scripts/train.pysrc/speculators/train/checkpointer.pysrc/speculators/train/optimizers.pysrc/speculators/train/trainer.pytests/unit/train/test_checkpoint.py
… multi-optimizer LR logging - Use strict=True in zip when loading optimizer/scheduler state dicts to fail loudly on count mismatch instead of silently dropping state - Return named parameter tuples from split_named_params_for_muon for consistency with the adamw path - Log per-optimizer LRs as a dict when multiple optimizers are active Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Fynn Schmitt-Ulms <[email protected]>
Signed-off-by: Fynn Schmitt-Ulms <[email protected]>
fynnsu
left a comment
There was a problem hiding this comment.
Blocking till e2e is done:
https://github.com/neuralmagic/llm-compressor-testing/actions/runs/27772187815
Just want to make sure the switch to multi-optimizers doesn't break anything.
We recently found and validated that Muon optimizer performs much better than Adam in training of speculator models.
Validated on two models: decoder-only (Qwen3-8B) and an MoE (Laguna-XS.2).
Training setup is the standard Magpie dataset, 50k samples for 1 epoch.
Validation setup: an extensive LR sweep for both Adam and Muon.
Test example 1:

a) Qwen3-8B, DFlash, LR sweep, metric=accuracy
b) Qwen3-8B, DFlash, LR sweep, metric=loss

Test example 2:

a) Laguna-XS.2, DFlash, LR sweep, metric=accuracy
b) Laguna-XS.2, DFlash, LR sweep, metric=loss

A few notes regarding the implementation: