Repository navigation
Open
Labels
Description
Motivation
DeepSpeed now supports the Muon optimizer across ZeRO stages 1/2/3. In 2026, two frontier labs independently converged on the same refinement for attention projections: orthogonalizing per attention head rather than over the full projection matrix.
- Kimi K3 (arXiv:2607.24653, §2.5, "Per-Head Muon"): partitions the momentum of Q/K/V projections along the head dimension and orthogonalizes each head's block separately. Their motivation: full-matrix orthogonalization treats all heads as a single coupled block, so heads with larger gradient/momentum scales dominate the shared update direction while smaller-scale heads receive insufficiently normalized updates. Per-head orthogonalization equalizes update scale across heads, improves stability at larger scales, and is cheaper (Newton–Schulz on tall per-head blocks costs less than on the full projection).
- Zhipu GLM-5 "Muon Split" (arXiv:2602.15763): the same idea applied to MLA up-projection matrices (split by attention head, orthogonalize each head independently), closing the performance gap between MLA and GQA under Muon.
Today in DeepSpeed, muon_update() (deepspeed/runtime/zero/muon/original_muon.py) applies Newton–Schulz to the full 2D parameter matrix — i.e., the "coupled block" behavior both papers describe.
Proposal
- Optimizer kernel: add a per-head mode to
muon_update— reshape the update/momentum to[..., num_heads, head_dim]and run the existing bmm-based Newton–Schulz on the batched per-head blocks (the NS implementations already support batched inputs, so this is mostly a view/reshape branch). Apply the existingmax(1, m/n)**0.5scaling per head block. - Parameter metadata pipeline: tag attention projection parameters with head structure (
num_heads,head_dim, fused-vs-split QKV layout), similar to the existinguse_muontagging. The AutoTP model scan / presets already identify attention head structure, so this metadata can be sourced from there. - ZeRO integration: the engine call site (post-unflatten, per-parameter
muon_update) stays unchanged — just pass the head shape so the update can be viewed per-head and reshaped back before being applied to the flat buffer. - Config surface: opt-in switch, e.g.
optimizer.params.per_head_muon: true(or per param-group), following the precedent of separatemuon_lr/adam_lr. - Tests: unit tests for per-head vs full-matrix orthogonalization equivalence on synthetic attention-shaped params, plus convergence sanity on a small model.
References
- Kimi K3 technical report §2.5: https://arxiv.org/abs/2607.24653
- Muon Split (GLM): https://arxiv.org/abs/2602.15763
- Current Muon implementation:
deepspeed/runtime/zero/muon/original_muon.py,deepspeed/runtime/zero/muon/muon_optimizer.py, ZeRO call site indeepspeed/runtime/zero/stage_1_and_2.py
Happy to help implement this.
Reacted by iLeGend
Reacted by pengdurice
Reacted by alanhuangyoo
Reacted by pengdurice
Activity
alanhuangyoo commentedon Sep 1, 2026
I would like to take this one, if nobody is on it yet.
Read through the current implementation to check the shape of the work. Confirming your point 1:
both Newton–Schulz kernels in
original_muon.pyare already batch-safe —assert G.ndim >= 2,.mT,size(-2)/size(-1), andnorm(dim=(-2, -1), keepdim=True)— andmuon_updatealreadyhas a batched branch with per-block scaling:
which is the same shape the per-head path needs. So the kernel side really is a view/reshape
plus reusing that branch, and the substance is in 2–4: sourcing
num_heads/head_dimand thefused-vs-split QKV layout, threading it to the call site, and the config surface.
Two things I would want your steer on before I write much:
Where the head metadata comes from. You mention the AutoTP model scan. Would you rather it
be read off
AutoTPMeta(which now carriesnum_kv_heads/num_attention_headsafter[AutoTP] Replace tp_shard process-wide globals with per-model AutoTPMeta #8241), or tagged onto the parameter next to
use_muonso non-AutoTP users can set it too?The second is more code but does not tie per-head Muon to AutoTP being enabled.
Fused QKV. For a fused
[3 * num_heads * head_dim, hidden]projection, I assume the splitshould be per head within each of Q/K/V rather than treating the fused matrix as
3 * num_headsuniform heads — and with GQA the K/V blocks have a different head count thanQ. Is that the layout you have in mind, or would you rather the first cut only handle split
QKV and skip fused?
On validation: I have 8×H100 available, so beyond the unit tests I can run a small-model
convergence comparison (full-matrix vs per-head, matched seeds/steps) and report loss curves
rather than just asserting shapes.
[muon] Tag attention projections with their head count and wire it th…
alanhuangyoo commentedon Sep 2, 2026
@delock implementation is up in #8384, built to the five points in your proposal.
Kernel, metadata, ZeRO integration and the config switch are all there;
per_head_muonisopt-in and off by default. Verified rather than asserted:
derived from the kernel's own compute dtype rather than tuned to pass.
the four head update norms land within 1.5× of each other. This is the case that fails if
num_headsis ignored.q_proj→8,k_proj/v_proj→2under GQA; gpt_neox/falcon tag nothing, which is where a naive name match would wrongly catch
dense_h_to_4h.q=8 k=2 v=2 o=None mlp=None embed=None.(max/min 1.009 → 1.266) while per-head stays flat at 1.015.
Two questions from my earlier comment are still open and shape the remaining work, so I left
both on the conservative side for now: fused QKV stays on the full-matrix path, and
o_projisexcluded because its head structure is on the input axis. Happy to extend either once you say
which layout you want assumed.
[muon] Support MLA up-projections and read head counts from AutoTPMeta
[muon] Per-head Newton-Schulz for attention projections (deepspeedai#…
alanhuangyoo commentedon Sep 18, 2026
@0z5a I'm not working on it, so it's yours as far as I'm concerned (@delock has the final say). One pointer: #8384 deliberately leaves the fused projections on the full-matrix path.
_FUSED_QKV_LEAVESindeepspeed/__init__.pyis the list, and the reason is that the Q/K/V layout inside the fused weight (concatenated vs. per-head interleaved) differs between models, so the head split has to come from the model rather than from the shape.