Skip to content

fix: make Muon gradient clipping configurable - #2047

Merged
jayhenry merged 1 commit into
InternLM:mainfrom
Denny991:fix/muon-clip-grad-mode
Sep 3, 2026
Merged

fix: make Muon gradient clipping configurable#2047
jayhenry merged 1 commit into
InternLM:mainfrom
Denny991:fix/muon-clip-grad-mode

Conversation

@Denny991

@Denny991 Denny991 commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR makes the Muon gradient clipping policy configurable.

adamw_only remains the default policy. The historical qwen3-5-sft-ep2-mtp4-vl E2E case explicitly uses all to align with its existing baseline.

Problem

After d1ecfdd, the Qwen3.5 E2E case showed larger grad_norm fluctuations and persistent loss differences, while LR and token counts remained identical.

The existing baseline was generated with all-group clipping, but d1ecfdd changed the default to AdamW-only clipping.

Failing run: https://github.com/InternLM/xtuner/actions/runs/32438896110

Changes

  • Add MuonConfig.clip_grad_mode:
    • adamw_only: clip only AdamW parameter groups.
    • all: clip both Muon and AdamW parameter groups.
  • Keep adamw_only as the default.
  • Set clip_grad_mode="all" only for the historical Qwen3.5 E2E case.
  • Add tests for both policies and optimizer state loading.

Validation

  • 8-GPU A/B confirmed that the clipping policy caused the loss and grad_norm differences.
  • Explicit all reproduced the pre-change behavior within observed run-to-run noise.
  • Lint passed.
  • Unit test and 16-GPU E2E are pending.

Related change: #2001

@Denny991
Denny991 force-pushed the fix/muon-clip-grad-mode branch from 80364c8 to f557f2a Compare August 26, 2026 06:49
@windreamer
windreamer requested a review from jayhenry August 26, 2026 08:29
Comment thread xtuner/v1/config/optim.py Outdated
clip_grad_mode: Annotated[
Literal["all", "adamw_only"],
Parameter(help="Gradient clipping policy: clip all parameters or only the AdamW parameter groups"),
] = "all"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

默认改为更正确的 adamw_only, 在端到端测试中显式设置为 all 来对齐baseline

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

默认情况下是更正确的adamw_only,在最终测试中显着方式设置为所有的横向基线

好,已经修改了

@Denny991
Denny991 force-pushed the fix/muon-clip-grad-mode branch from f557f2a to 75aa651 Compare August 26, 2026 10:14
@Denny991
Denny991 force-pushed the fix/muon-clip-grad-mode branch from 75aa651 to d74c89c Compare September 3, 2026 03:34
@jayhenry
jayhenry merged commit c30fd9d into InternLM:main Sep 3, 2026
8 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