Skip to content

Add --muon-coefficient-type argument for Muon optimizer - #3927

Merged
mchrzanowski merged 25 commits into
NVIDIA:mainfrom
mchrzanowski:add-muon-coefficient-type
Mar 26, 2026
Merged

Add --muon-coefficient-type argument for Muon optimizer#3927
mchrzanowski merged 25 commits into
NVIDIA:mainfrom
mchrzanowski:add-muon-coefficient-type

Conversation

@mchrzanowski

Copy link
Copy Markdown
Contributor

Allow users to select the Newton-Schulz polynomial coefficient set (e.g. simple, quintic, polar_express, aol) via the new --muon-coefficient-type CLI flag. Supported types are discovered dynamically from the installed emerging_optimizers package so that upstream additions are picked up automatically without code changes.

Allow users to select the Newton-Schulz polynomial coefficient set
(e.g. simple, quintic, polar_express, aol) via the new
--muon-coefficient-type CLI flag. Supported types are discovered
dynamically from the installed emerging_optimizers package so that
upstream additions are picked up automatically without code changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mchrzanowski
mchrzanowski requested review from a team as code owners March 18, 2026 16:26
@copy-pr-bot

copy-pr-bot Bot commented Mar 18, 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.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft March 18, 2026 16:27
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

root and others added 4 commits March 18, 2026 09:34
Derive supported coefficient types from the public NSCoeffT Literal
type via typing.get_args() rather than reading keys from the private
_COEFFICIENT_SETS dict. Tests likewise avoid importing _COEFFICIENT_SETS.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
emerging_optimizers must be installed to use Muon, so there is no
need for a hardcoded fallback list. get_supported_coefficient_types()
now asserts the package is present and reads NSCoeffT directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace hardcoded _NS_STEPS_FOR_COEFF_TYPE mapping with dynamic discovery
via get_supported_coefficient_types() (backed by NSCoeffT). Since
get_coefficient_iterator cycles/repeats coefficients, a single default
step count works for all types. Remove redundant duplicate test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mchrzanowski
mchrzanowski marked this pull request as ready for review March 18, 2026 23:02
Comment thread megatron/core/optimizer/optimizer_config.py
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Mar 19, 2026
@@ -288,6 +311,7 @@ def lion_init_state_fn(opt, config=None):
"use_nesterov": config.muon_use_nesterov,

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.

BTW, should we check for certain versions of emerging_optimizers? I believe this got re-named to nesterov in the latest release.

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.

I feel it is better to keep the code only support one version. And I think having that version be the tagged in pyproject is reasonable. Optionally we can add a global check.
We will bump main to support v0.2.0 soon(after dev refactor+bump and main2dev sync, both are finalizing).

Comment thread megatron/core/optimizer/muon.py
Comment thread megatron/core/optimizer/muon.py Outdated
root and others added 2 commits March 19, 2026 15:29
The Lion class moved in emerging_optimizers 0.2. Gate the import
behind an explicit version check so users get a clear error instead
of a silent ImportError on older versions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Mar 25, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added this to the Core 0.16 milestone Mar 25, 2026
root and others added 2 commits March 25, 2026 10:43
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
root and others added 2 commits March 25, 2026 13:03
Tests were failing with AssertionError because they unconditionally
called get_supported_coefficient_types() which requires emerging_optimizers >= 0.2.
Added pytestmark skip conditions and guarded module-level collection code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@skyw
skyw requested review from skyw and removed request for skyw March 25, 2026 20:47
mchrzanowski and others added 4 commits March 25, 2026 17:19
validate_coefficient_type was unconditionally calling
get_supported_coefficient_types() which asserts HAVE_EO_V02. This
caused dist_checkpointing tests to fail when emerging_optimizers < 0.2
was installed, since TensorParallelMuon.__init__ always calls
validate_coefficient_type. Skip validation when HAVE_EO_V02 is False,
as the coefficient_type kwarg is not passed to newton_schulz_tp in
that case anyway.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…>= 0.2

"quintic" is the default coefficient type supported before
emerging_optimizers 0.2, so validate against it rather than
skipping validation entirely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ient_types

Now that validate_coefficient_type falls back to ("quintic",) without
emerging_optimizers >= 0.2, most tests only need HAVE_EMERGING_OPTIMIZERS.
Only the three tests that directly call get_supported_coefficient_types()
still require HAVE_EO_V02.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…sion

The coefficient_type parameter is supported in emerging_optimizers >= 0.1,
so there's no need to gate it behind HAVE_EO_V02 (>= 0.2).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mchrzanowski

Copy link
Copy Markdown
Contributor Author

/ok to test 10bf5eb

@mchrzanowski
mchrzanowski added this pull request to the merge queue Mar 26, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/23577425224

Merged via the queue into NVIDIA:main with commit 0842ca2 Mar 26, 2026
63 checks passed
@mchrzanowski
mchrzanowski deleted the add-muon-coefficient-type branch March 26, 2026 04:57
yangbofun pushed a commit to xlm-research/Megatron-LM that referenced this pull request May 22, 2026
Co-authored-by: root <root@pool0-0084.cm.cluster>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: root <root@pool0-0393.cm.cluster>
Co-authored-by: root <root@pool0-0154.cm.cluster>
Co-authored-by: root <root@pool0-0021.cm.cluster>
Co-authored-by: root <root@pool0-0331.cm.cluster>
Co-authored-by: root <root@pool0-0079.cm.cluster>
Co-authored-by: root <root@pool0-0137.cm.cluster>
yhgalaxy pushed a commit to yhgalaxy/Megatron-LM that referenced this pull request Jun 17, 2026
Co-authored-by: root <root@pool0-0084.cm.cluster>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: root <root@pool0-0393.cm.cluster>
Co-authored-by: root <root@pool0-0154.cm.cluster>
Co-authored-by: root <root@pool0-0021.cm.cluster>
Co-authored-by: root <root@pool0-0331.cm.cluster>
Co-authored-by: root <root@pool0-0079.cm.cluster>
Co-authored-by: root <root@pool0-0137.cm.cluster>
Signed-off-by: yhgalaxy <yhgalaxy@outlook.com>
jon-barker pushed a commit to jon-barker/Megatron-LM that referenced this pull request Jul 10, 2026
Co-authored-by: root <root@pool0-0084.cm.cluster>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: root <root@pool0-0393.cm.cluster>
Co-authored-by: root <root@pool0-0154.cm.cluster>
Co-authored-by: root <root@pool0-0021.cm.cluster>
Co-authored-by: root <root@pool0-0331.cm.cluster>
Co-authored-by: root <root@pool0-0079.cm.cluster>
Co-authored-by: root <root@pool0-0137.cm.cluster>
Signed-off-by: Jon Barker <jbarker@aws-cmh-slurm-1-vscode-02.cm.cluster>
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
Co-authored-by: root <root@pool0-0084.cm.cluster>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: root <root@pool0-0393.cm.cluster>
Co-authored-by: root <root@pool0-0154.cm.cluster>
Co-authored-by: root <root@pool0-0021.cm.cluster>
Co-authored-by: root <root@pool0-0331.cm.cluster>
Co-authored-by: root <root@pool0-0079.cm.cluster>
Co-authored-by: root <root@pool0-0137.cm.cluster>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants