Skip to content

[Fix] Add GLM-5.2 MuonSplit and AdamW-only gradient clipping - #2001

Open
JT-Ushio wants to merge 1 commit into
InternLM:mainfrom
JT-Ushio:fix/muonsplit-and-clipsplit
Open

[Fix] Add GLM-5.2 MuonSplit and AdamW-only gradient clipping#2001
JT-Ushio wants to merge 1 commit into
InternLM:mainfrom
JT-Ushio:fix/muonsplit-and-clipsplit

Conversation

@JT-Ushio

@JT-Ushio JT-Ushio commented Aug 8, 2026

Copy link
Copy Markdown

Summary

  • Apply Muon independently to GLM-5.2 MLA head/component blocks, including per-block LR scaling (GLM-5, reference implementation).
  • Clip only auxiliary AdamW gradients while retaining the full gradient norm for safety checks. This is motivated by Muon's scale-invariant orthogonalization, Ortho(cG) = Ortho(G) (rationale).

Tests

  • Ruff lint and format checks
  • GPU tests not run locally

Copilot AI lite review requested due to automatic review settings August 8, 2026 03:24

Copilot AI 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.

Pull request overview

This PR extends the Muon optimizer integration to support GLM-5.2-style “MuonSplit” (independent orthogonalization/LR scaling per logical row block) and adjusts training-time gradient clipping so only auxiliary (non-Muon) gradients are clipped while still computing the full global grad norm for safety checks.

Changes:

  • Add MuonSplit support in Muon via per-parameter logical row block definitions and a split-aware Newton–Schulz callback.
  • Plumb MuonSplit metadata from model modules (e.g., DSA MLA projections) into optimizer construction.
  • Update TrainEngine.clip_grad_norm behavior and add tests covering MuonSplit equivalence + AdamW-only clipping behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
xtuner/v1/optim/muon.py Adds MuonSplit grouping and split-aware Newton–Schulz orthogonalization with per-block LR scaling.
xtuner/v1/module/attention/dsa_mla.py Exposes GLM MLA projection split sizes for MuonSplit via get_muon_split_sizes().
xtuner/v1/engine/train_engine.py Clips only auxiliary gradients when Muon is present while keeping full grad norm for checks/logging.
xtuner/v1/config/optim.py Collects muon_split_sizes from modules and passes them into the Muon optimizer.
tests/optim/test_muon.py Adds unit coverage for MuonSplit behavior and AdamW-only clipping semantics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread xtuner/v1/optim/muon.py
Comment on lines +371 to +372
if sum(split_sizes) > p.shape[-2]:
raise ValueError(f"MuonSplit sizes {split_sizes} exceed parameter shape {tuple(p.shape)}")
Comment on lines +267 to +272
clip_params = (
p
for group in self.optimizer.param_groups
if group.get("algorithm") != "muon"
for p in group["params"]
)
@windreamer
windreamer requested a review from jayhenry August 8, 2026 03:31
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