Skip to content

feat(megatron): expose muon_coefficient_type for the Muon optimizer - #9591

Merged
Jintao-Huang merged 1 commit into
modelscope:mainfrom
yuchenwang3:feat/muon-coefficient-type
Jun 18, 2026
Merged

feat(megatron): expose muon_coefficient_type for the Muon optimizer#9591
Jintao-Huang merged 1 commit into
modelscope:mainfrom
yuchenwang3:feat/muon-coefficient-type

Conversation

@yuchenwang3

Copy link
Copy Markdown
Contributor

What

Megatron-SWIFT's MegatronArguments exposes 8 Muon hyperparameters (muon_momentum, muon_split_qkv, muon_use_nesterov, muon_scale_mode, muon_fp32_matmul_prec, muon_num_ns_steps, muon_tp_mode, muon_extra_scale_factor) but is missing muon_coefficient_type, which Megatron-Core supports:

  • Megatron CLI: --muon-coefficient-type (megatron/training/arguments.py), default 'quintic'
  • Megatron config: OptimizerConfig.muon_coefficient_type (megatron/core/optimizer/optimizer_config.py)

muon_coefficient_type selects the Newton–Schulz coefficient set (quintic, polar_express, …), which affects convergence. Without it exposed, recipes that rely on a non-default coefficient set (e.g. polar_express) cannot be expressed through Megatron-SWIFT.

Change

  • Add muon_coefficient_type: str = 'quintic' to MegatronArguments (matching Megatron's CLI default and type=str).
  • Document it in the zh/en command-line-parameters docs.

No forwarding code is needed: MegatronArguments is forwarded to Megatron via the existing asdict() mechanism (swift/megatron/pipelines/train/sft.py), exactly like the other muon_* args, and Megatron already has the matching --muon-coefficient-type argument.

Notes

Typed as str (rather than a Literal) to mirror Megatron's own CLI, since the supported set is version-dependent and validated by Megatron at runtime (emerging_optimizers.validate_coefficient_type). Happy to switch to a Literal if preferred. Verified against current main; the field was the only muon_* argument absent relative to Megatron's CLI.

ms-swift exposes 8 Muon hyperparameters but not muon_coefficient_type, which
Megatron-Core supports (--muon-coefficient-type / OptimizerConfig.muon_coefficient_type,
default 'quintic'). It selects the Newton-Schulz coefficient set (quintic,
polar_express, ...) and affects convergence; recipes using non-default
coefficients cannot currently be expressed via Megatron-SWIFT.

Add the field (str, matching Megatron's CLI type/default); it forwards through
the existing asdict()-based mechanism like the other muon_* args. Add zh/en docs.

Signed-off-by: yuchenwang3 <eang333cms@gmail.com>

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a new command-line parameter muon_coefficient_type for the Muon optimizer, updating both the Python arguments configuration and the Chinese and English documentation. The feedback points out minor markdown formatting issues in both documentation files, specifically unbalanced backticks around the --muon-coefficient-type parameter name.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

- muon_use_nesterov: 是否在内部 SGD 中使用 Nesterov 风格的动量,默认为False。
- muon_scale_mode: Muon 优化器的缩放模式。可选为'spectral', 'unit_rms_norm', 'shape_scaling'。默认为'spectral'。
- muon_fp32_matmul_prec: Newton-Schulz 迭代的 FP32 矩阵乘法精度,可选为'low', 'medium', 'high'。默认为'medium'。
- muon_coefficient_type: Muon 优化器 Newton-Schulz 迭代的系数类型,传递给 Megatron 的 `--muon-coefficient-type`。可选值取决于所安装的 emerging_optimizers 版本(如'quintic', 'polar_express', 'simple', 'cans', 'aol', 'deepseekv4', 'cubic5', 'custom')。默认为'quintic'。

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.

medium

There is a markdown formatting issue on this line. The backticks around --muon-coefficient-type are unbalanced (two backticks at the start and one at the end: `--muon-coefficient-type`). Please update it to use single backticks for proper rendering:

- muon_coefficient_type: Muon 优化器 Newton-Schulz 迭代的系数类型,传递给 Megatron 的 `--muon-coefficient-type`。可选值取决于所安装的 emerging_optimizers 版本(如'quintic', 'polar_express', 'simple', 'cans', 'aol', 'deepseekv4', 'cubic5', 'custom')。默认为'quintic'。

- muon_use_nesterov: Whether to use Nesterov-style momentum in the internal SGD. Default is False.
- muon_scale_mode: Scale mode for the Muon optimizer. Options include 'spectral', 'unit_rms_norm', and 'shape_scaling'. Default is 'spectral'.
- muon_fp32_matmul_prec: FP32 matrix multiplication precision for Newton-Schulz iteration. Options include 'low', 'medium', and 'high'. Default is 'medium'.
- muon_coefficient_type: Newton-Schulz coefficient type for the Muon optimizer, forwarded to Megatron's `--muon-coefficient-type`. Available options depend on the installed emerging_optimizers version (e.g. 'quintic', 'polar_express', 'simple', 'cans', 'aol', 'deepseekv4', 'cubic5', 'custom'). Default is 'quintic'.

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.

medium

There is a markdown formatting issue on this line. The backticks around --muon-coefficient-type are unbalanced (two backticks at the start and one at the end: `--muon-coefficient-type`). Please update it to use single backticks for proper rendering:

- muon_coefficient_type: Newton-Schulz coefficient type for the Muon optimizer, forwarded to Megatron's `--muon-coefficient-type`. Available options depend on the installed emerging_optimizers version (e.g. 'quintic', 'polar_express', 'simple', 'cans', 'aol', 'deepseekv4', 'cubic5', 'custom'). Default is 'quintic'.

@Jintao-Huang
Jintao-Huang merged commit 8cf2e5b into modelscope:main Jun 18, 2026
2 of 3 checks passed
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