Lecture 13 · Modern Optimizers and Architectures

Scalable AI: Bridging Theory, Understanding, and Practice · Lecture 13。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: UC Berkeley EE 290/194 Scalable AI, Fall 2026 Lecture 10, Modern Optimizers and Architectures (slides lecture10.pdf): Muon at scale, stable optimizers, evaluating optimizer claims, memory-aware architecture. Also drawn on: Spring 2026 Lecture 10, Looking to the Future: Emerging Optimizers (guest lecture by Boxiang Wang, NVIDIA; slides lecture10.pptx): Muon, Shampoo, SOAP, distributed Muon in Megatron-LM, MuonClip. Recommended reading: Jordan et al., Muon (blog and muon.py, 2024); Liu et al., Muon is Scalable for LLM Training (Moonlight, arXiv:2502.16982); Amsel et al., The Polar Express (arXiv:2505.16932); Gupta, Koren and Singer, Shampoo (arXiv:1802.09568); Vyas et al., SOAP (arXiv:2409.11321); Kimi K2 (arXiv:2507.20534); Wen et al., Fantastic Pretraining Optimizers and Where to Find Them (arXiv:2509.02046) and Fantastic Pretraining Optimizers II: Hyperball Optimization (arXiv:2606.16899); DeepSeek, Engram (arXiv:2601.07372) and mHC (arXiv:2512.24880). Code: code/lecture13/ contains matrix_opt.py (Newton–Schulz with four coefficient schedules, a Polar Express minimax solver, Muon, Shampoo, SOAP, AdamH/MuonH, QK-clip), muon_dist.py (sharding, owners, a real distributed Muon over gloo), memory_arch.py (Engram, Sinkhorn hyper-connections) and seven demos. Reading time: ~2.5 hours for the prose; ~12 minutes to run all demos (two have a --quick mode).


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Explain Muon. Say what its update computes (the orthogonalised momentum UV⊤UV^\top), why that helps (gradients are dominated by a few directions), and how Newton–Schulz computes it with matrix multiplies only. Read a Newton–Schulz coefficient set as a polynomial on singular values.
  2. Place Muon in the family. Shampoo, SOAP and Kron; why Muon is “Shampoo that forgets”; what each costs in memory and compute.
  3. Evaluate an optimizer claim. Name the seven questions to ask (baseline tuning, own hyperparameters, end of schedule, model size, tokens per parameter, tokens vs wall-clock, architecture tuned for AdamW) and apply them to a real result.
  4. Run Muon at scale. Explain why a 1%-of-FLOPs algorithm still needs infrastructure: the three broken assumptions, flat sharded buffers, matrix owners and load balance, the communication trade-off of distributing every GEMM, and Dion.
  5. Keep a run stable. Weight growth without decay, attention-logit growth, QK-clip vs QK-norm, gated attention, and which fixes act through the learning rate.
  6. Read weight decay as an angular step size, and explain the fixed-norm optimizers (AdamH, MuonH) that replace it.
  7. Design for the memory hierarchy. Say which sparse parameters can live in host memory (addresses known early), and what a wider residual stream costs.

0.2 Prerequisites and scope

  • Prerequisites:
    • Lecture 12: optimizers from scratch, steepest descent under the spectral norm (UV⊤UV^\top), µP.
    • Lecture 9: the pre-training stack and Atlas World.
    • Lecture 5: ZeRO / FSDP sharding and collectives.
    • Lecture 4: MLA.
    • Linear algebra: the SVD.
  • Scope: matrix optimizers and their systems cost, stability controls, optimizer evaluation methodology, memory-traffic-aware architecture.
  • Not in scope: Kron/PSGD in detail (described, not implemented); custom Newton–Schulz GPU kernels (described with their published numbers).

0.3 Section → code map

SectionIdeaCode in code/lecture13/
§1from AdamW to Muon; Newton–Schulz; coefficients; costmatrix_opt.py, 01_newton_schulz.py
§1.6Shampoo, SOAP, Kron; memory02_matrix_optimizers.py
§2evaluating optimizer claims fairly03_fair_comparison.py
§3Muon at scale: sharding, owners, designsmuon_dist.py, 04_muon_at_scale.py
§4controlling scale: weights, logits, activations05_stability.py
§5weight decay as angular step; AdamH / MuonH06_fixed_norm.py
§6architecture and memory trafficmemory_arch.py, 07_memory_architecture.py

0.4 Notation

  • W∈RA×BW \in \mathbb{R}^{A\times B} is a weight matrix and GG its gradient. MM is the momentum and μ\mu its factor.
  • G=UΣV⊤G = U\Sigma V^\top is the (compact) SVD, with singular values σi\sigma_i.
  • NS(X)\mathrm{NS}(X) is the Newton–Schulz approximation of UV⊤UV^\top (also written msign(X)\mathrm{msign}(X), the “matrix sign”).
  • TT is the number of Newton–Schulz steps. SS is the number of data-parallel ranks. BB is the batch size in tokens.
  • η\eta is the learning rate and λ\lambda the weight decay.

1. From AdamW to Muon

1.1 An AdamW step is elementwise and bandwidth-bound

Recall the AdamW update from Lecture 12. Each parameter is updated from its own gradient, momentum and variance:

θ←θ−η(m^v^+ϵ+λθ).\theta \leftarrow \theta - \eta\Big(\frac{\hat m}{\sqrt{\hat v} + \epsilon} + \lambda\theta\Big).

No entry looks at any other entry. Two consequences follow, one for hardware and one for systems.

  • It is bandwidth-bound. Per parameter, the step reads and writes about 28 bytes:

    • an FP32 master weight, mm and vv (read and write each);
    • a BF16 gradient.

    It does only about 15 FLOPs. That is an arithmetic intensity (算术强度) of about 0.5 FLOP/byte, against an H100 ridge point of about 300 (Lecture 2). A 1B-parameter AdamW step moves about 28 GB, a few milliseconds of HBM time.

  • Any slicing works. Because the update is elementwise, ZeRO and FSDP (Lecture 5) can give each rank any slice of the parameters. The optimizer step then needs no communication of its own.

Keep both properties in mind: Muon gives up the second one.

1.2 Muon: replace the update with its nearest orthogonal matrix

For a weight matrix W∈RA×BW \in \mathbb{R}^{A\times B} with gradient GG, Muon (Jordan et al., 2024) does:

M←μM+G,O=NS(M)≈UV⊤ where M=UΣV⊤,M \leftarrow \mu M + G, \qquad O = \mathrm{NS}(M) \approx UV^\top \text{ where } M = U\Sigma V^\top,

W←W−η (0.2max⁡(A,B)  O+λW).W \leftarrow W - \eta\,\big(0.2\sqrt{\max(A,B)}\; O + \lambda W\big).

In words:

  • keep the directions U,VU, V of the momentum;
  • set every singular value to 1;
  • scale, and add decoupled weight decay.

Adam rescales each coordinate separately. Muon rescales the matrix along its singular directions. Lecture 12 §2 derived where UV⊤UV^\top comes from: it is the steepest-descent direction under the spectral norm. The step that most decreases the loss, among all steps whose largest singular value is at most η\eta, is −η UV⊤-\eta\,UV^\top.

Why it helps (intuition). The gradient of a weight matrix is dominated by a few directions. Our demo 01 measured this on the first MLP matrix of Lecture 9’s model (width 128):

  • the top 10 of its 128 singular directions hold 59% of the squared norm;
  • its stable rank (稳定秩, ∑σi2/σ12\sum\sigma_i^2/\sigma_1^2, a soft count of the directions that matter) is 9.0.

A gradient step moves mostly along those few directions. The rare directions, which may matter just as much for learning, get a tiny step. Orthogonalising gives every direction the same step size.

Demo 02 shows the effect on one real step (step 150, a 160 × 64 matrix):

matrixstable rankenergy in top 5 directionsσ1\sigma_1 / median σ\sigma
gradient GG8.144%5.7
AdamW update m^/(v^+ϵ)\hat m/(\sqrt{\hat v}+\epsilon)9.638%4.0
Muon update NS(M)\mathrm{NS}(M)39.4 (of 64)13%1.4

AdamW’s elementwise normalisation barely changes the spectrum. Muon’s step uses most directions of the matrix.

The factor 0.2max⁡(A,B)0.2\sqrt{\max(A,B)} is Moonlight’s RMS matching (均方根匹配). An orthogonal A×BA \times B matrix with all singular values 1 has Frobenius norm min⁡(A,B)\sqrt{\min(A,B)}, so its RMS is 1/max⁡(A,B)1/\sqrt{\max(A,B)}. Multiplying by 0.2max⁡(A,B)0.2\sqrt{\max(A,B)} makes the update RMS exactly 0.2 at every shape. Demo 02 checks this for 64 × 176 up to 1024 × 4096, and also measures AdamW’s update RMS on our model:

  • 0.22–0.25 from step 50 on;
  • 0.50 at step 10, before vv settles.

So the two optimizers’ updates have the same size, and AdamW’s learning rate and weight decay can be reused as a starting point.

Which parameters. Only hidden 2-D matrices (attention and MLP weights) use Muon. The embedding table, the output head, norm gains and biases stay on AdamW:

  • an embedding row is updated only when its token appears, so orthogonalising the whole table makes no sense;
  • the head’s scale sets the logits directly.

matrix_opt.muon_mask makes this split, and every matrix optimizer in the code hands the rest to an inner AdamW.

Memory. Muon keeps one moment instead of two. In the guest lecture’s mixed-precision accounting:

  • AdamW = 16 bytes per parameter (BF16 weight 2 + BF16 gradient 2 + FP32 master 4 + FP32 m,vm, v 8);
  • Muon = 12 bytes per parameter, 25% less.

1.3 Newton–Schulz: orthogonalising with matrix multiplies only

Computing UV⊤UV^\top by SVD is slow on a GPU. cuSOLVER’s SVD is slower than 15 GEMMs, and it does not use tensor cores. Newton–Schulz (牛顿-舒尔茨迭代) gets there with GEMMs alone. The key identity:

X=UΣV⊤  ⟹  XX⊤X=UΣ3V⊤.X = U\Sigma V^\top \implies XX^\top X = U\Sigma^3V^\top.

Multiplying by XX⊤XX^\top raises every singular value to a higher power and leaves UU and VV alone. So one step

X←aX+b(XX⊤)X+c(XX⊤)2XX \leftarrow aX + b(XX^\top)X + c(XX^\top)^2X

applies the odd polynomial p(σ)=aσ+bσ3+cσ5p(\sigma) = a\sigma + b\sigma^3 + c\sigma^5 to every singular value at once, without ever computing them. In code (newton_schulz), with the short side first so that XX⊤XX^\top is the small Gram matrix:

X = G / ||G||_F                  # every sigma now in (0, 1]
for (a, b, c) in schedule:
    A = X @ X.T                  # 1 GEMM
    B = b*A + c*(A @ A)          # 1 GEMM
    X = a*X + B @ X              # 1 GEMM

That is three GEMMs per step. For an m×nm\times n matrix (m≤nm \le n) a step costs 4m2n+2m3≤6m2n4m^2n + 2m^3 \le 6m^2n FLOPs, where AdamW costs O(mn)O(mn).

Two consequences matter.

The scalar map is the algorithm. Newton–Schulz never mixes singular values. So the 1-D curve σ↦pT(⋯p1(σ))\sigma \mapsto p_T(\cdots p_1(\sigma)) completely describes what it does to a matrix. matrix_opt’s self-test checks this: the singular values of the matrix output equal the scalar map of the input’s singular values to 10−910^{-9}.

Normalise first. Muon’s polynomial has p(σ)>σp(\sigma) > \sigma for every σ\sigma above 1.264 (demo 01). A singular value there grows at every step without bound. Dividing by the Frobenius norm, which is always ≥ the largest singular value, puts every σ\sigma in (0,1](0, 1].

1.4 The coefficients trade speed for accuracy

A perfect orthogonaliser would map every input σ∈(0,1]\sigma \in (0, 1] to exactly 1. Demo 01 computes where each schedule actually sends a singular value:

scheduleGEMMsσ=10−3\sigma = 10^{-3}10−210^{-2}0.11range for σ∈[10−3,1]\sigma \in [10^{-3}, 1]
classic cubic (1.5,−0.5,0)(1.5, -0.5, 0) × 5150.0080.0760.6591.000[0.008, 1.000]
Muon’s quintic (3.4445,−4.7750,2.0315)(3.4445, -4.7750, 2.0315) × 5150.4710.6990.7120.696[0.471, 1.202]
DeepSeek-V4: 8 Muon steps + 2 of (2,−1.5,0.5)(2, -1.5, 0.5)301.0001.0001.0001.000[1.000, 1.001]
Polar Express × 5 (computed here)150.8631.0971.0280.887[0.863, 1.113]

How to read the table:

  • The classic cubic converges to exactly 1, but its slope at 0 is only 1.5. A value of 10−310^{-3} needs about 16 steps just to reach 0.5.
  • Muon’s tuned quintic has slope 3.44 at zero, so small singular values grow fast. The price is sloppiness: after 5 steps the outputs land anywhere in about [0.47, 1.20]. Jordan and the guest lecture found this harmless. As long as outputs stay within about ±0.3 of 1, the loss curve does not change (“fast and sloppy” is the right trade for deep learning, unlike HPC).
  • DeepSeek-V4 spends twice the GEMMs on precision. Its final polynomial (2,−1.5,0.5)(2, -1.5, 0.5) has p(1)=1p(1) = 1 and p′(1)=0p'(1) = 0, a flat fixed point.

Polar Express (Amsel et al.) asks a better question. If you know the interval [ℓk,uk][\ell_k, u_k] the singular values lie in, choose the polynomial that shrinks it the most. That is a minimax problem (极小极大逼近): the odd quintic minimising max⁡σ∈[ℓ,u]∣1−p(σ)∣\max_{\sigma \in [\ell,u]}|1 - p(\sigma)|.

Chebyshev’s theorem says the optimum’s error equioscillates, reaching +E+E and −E-E alternately at 4 points. The Remez exchange algorithm finds it: guess 4 points, solve the linear system p(σk)+(−1)kE=1p(\sigma_k) + (-1)^kE = 1, move the points to the error’s peaks, and repeat. matrix_opt.remez_odd implements this in 30 lines. The image [1−E,1+E][1-E, 1+E] becomes the next step’s interval.

Our greedy schedule from ℓ=10−3\ell = 10^{-3} (demo 01, Part B):

stepinterval in(a,b,c)(a, b, c)max ∣1−p∣\lvert 1-p\rvert on it
1[0.001,1][0.001, 1](8.4703, −25.1081, 18.6293)0.99
2[0.0085,1.99][0.0085, 1.99](4.1828, −3.1087, 0.5806)0.96
3[0.035,1.97][0.035, 1.97](3.9619, −2.9541, 0.5630)0.86
4[0.14,1.86][0.14, 1.86](3.2866, −2.4647, 0.5074)0.55
5[0.45,1.55][0.45, 1.55](2.2737, −1.6447, 0.4162)0.11
6[0.887,1.113][0.887, 1.113](1.8887, −1.2652, 0.3765)9×10−49\times10^{-4}
7[0.9991,1.0009][0.9991, 1.0009](1.8750, −1.2500, 0.3750)5×10−105\times10^{-10}

Early polynomials are steep, to lift tiny singular values. Late ones are gentle, and converge to (15/8,−10/8,3/8)(15/8, -10/8, 3/8): the quintic with p(1)=1p(1) = 1 and p′(1)=p′′(1)=0p'(1) = p''(1) = 0.

Our first polynomial (8.47, −25.1, 18.6) is close to the published ≈(8.29, −23.6, 17.3). The paper adds small adjustments for stability, which we do not reproduce exactly. The paper also evaluates p(σ/1.01)p(\sigma/1.01) instead of p(σ)p(\sigma) on all but the last step. This “safety factor” keeps BF16 rounding from pushing a value just outside the interval the next polynomial was designed for.

On a hard matrix (256 × 512, singular values from 1 down to 10−610^{-6}; demo 01, Part C), the spectral error ∥NS(X)−UV⊤∥2\lVert\mathrm{NS}(X) - UV^\top\rVert_2 behaves as follows:

schedule (FP64)5 steps101530
classic cubic1.0001.0001.0000.939
Muon quintic (repeated)1.0000.9250.3180.318
Polar Express (ℓ=10−6\ell = 10^{-6})0.9990.6540.0001.2×10−101.2\times10^{-10}

The fixed quintic stalls at about 0.32 however long it runs, because it was never meant to converge. Polar Express keeps improving.

In BF16, on a matrix inside the design range, every converged schedule bottoms out at a spectral error near 0.12. This happens although its output singular values are within 1% of 1. Rounding the input to BF16’s 8 significant bits already turned its weakest singular directions, and no polynomial applied afterwards can repair that. The 1.01 safety factor made no measurable difference in this test (largest output 1.007 with and without it). It is insurance, not a measurable gain here.

On the real gradient (demo 01, Part D):

  • Muon’s 5 steps reach a cosine of 0.986 to the exact UV⊤UV^\top;
  • Polar Express’s 5 steps reach 0.997;
  • DeepSeek-V4’s 10 steps reach 1.0000.

All are good enough for training. The differences matter more at scale, where a few percent of a step’s direction compounds over hundreds of thousands of steps.

1.5 What it costs on one GPU

Per optimizer step, an m×nm \times n weight with batch BB tokens costs:

  • forward + backward: 6mnB6mnB;
  • TT Newton–Schulz steps: at most 6Tm2n6Tm^2n.

So

NS FLOPstraining FLOPs≤TmB.\frac{\text{NS FLOPs}}{\text{training FLOPs}} \le \frac{Tm}{B}.

The update is paid once per batch, so a larger batch hides it. Demo 01 computes it exactly and as the bound:

matrix (batch)NS / training, exactbound Tm/BTm/Bslide
NanoGPT 124M, 768 × 3072 (0.5M tokens)0.58%0.77%0.7%
Llama 3 405B, 16384 × 53248 (16M tokens)0.39%0.51%0.5%

Under 1% either way.

NS vs SVD, measured on this laptop’s CPU (FP32, best of 3):

matrix5 NS stepsSVDSVD / NS
256 × 2561.2 ms3.5 ms2.6–2.8×
1024 × 102418.7 ms81.7 ms4.4×
2048 × 2048110 ms423 ms3.8–4.0×

At 2048 the NS GEMMs run at about 2.3 TFLOP/s on the CPU’s matrix units. On a GPU the gap is far larger, because the GEMMs run on tensor cores and the SVD does not.

On one node it pays. In the NanoGPT speedrun (124M, 8×H100), Muon reaches each loss in fewer tokens at 142 ms per step vs 139 ms for Adam, so it also wins in wall-clock (Jordan et al.). SOAP needs even fewer tokens, but its 301 ms steps make it slowest.

Moonlight’s compute-optimal scaling fits report Muon needing 0.52× AdamW’s FLOPs for the same loss. Essential AI found Muon keeps its data efficiency at larger batches: it has a larger critical batch size (Lecture 12 §5). For systems that matters as much as the FLOPs. With more devices the global batch grows, and past the critical batch each token does less work. An optimizer with a larger critical batch can use more data parallelism before it stops paying off. We return to the 2× figure in §2, which asks how much of it survives a fair comparison.

1.6 Shampoo, SOAP and Kron: the other matrix optimizers

Shampoo (Gupta, Koren, Singer 2018) keeps two running statistics per matrix, its Kronecker factors (克罗内克因子), and preconditions on both sides:

L←L+GG⊤,R←R+G⊤G,W←W−η L−1/4 G R−1/4.L \leftarrow L + GG^\top,\quad R \leftarrow R + G^\top G,\qquad W \leftarrow W - \eta\,L^{-1/4}\,G\,R^{-1/4}.

It is a block-diagonal AdaGrad (one block per layer) with each block approximated by a Kronecker product. With no accumulation, L=GG⊤L = GG^\top and R=G⊤GR = G^\top G, so

L−1/4GR−1/4=UΣ−1/2U⊤ UΣV⊤ VΣ−1/2V⊤=UV⊤.L^{-1/4}GR^{-1/4} = U\Sigma^{-1/2}U^\top\,U\Sigma V^\top\,V\Sigma^{-1/2}V^\top = UV^\top.

Muon is Shampoo that forgets past gradients. Forgetting is what lets it replace the matrix roots (an eigendecomposition) with Newton–Schulz.

Demo 02 measures how fast Shampoo’s direction leaves UV⊤UV^\top as its memory grows. The figure is the mean cosine to the current gradient’s UV⊤UV^\top on real gradients:

β2\beta_2 of L,RL, R0 (no memory)0.50.90.991.0 (sum)
cosine1.00000.9270.8410.7930.783

Shampoo whitens with the average gradient statistics, Muon with the current momentum only.

SOAP (Vyas et al.) runs Adam in Shampoo’s eigenbasis:

  • rotate G′=QL⊤GQRG' = Q_L^\top GQ_R;
  • keep an Adam second moment there;
  • step, rotate back;
  • refresh the basis every kk steps.

Kron (PSGD) fits a Kronecker-factored preconditioner online, with no roots or eigendecompositions (described here, not implemented).

Where each wins. Demo 02 builds a problem with exactly Shampoo’s structure: matrix least squares whose curvature is a Kronecker product B⊗AB \otimes A, condition number 100 on each side. We run it axis-aligned and with random rotations, 300 steps, each optimizer at its best of 25 learning rates:

optimizeraligned: final/initial lossrotated
GD4.3×10−34.3\times10^{-3}4.9×10−34.9\times10^{-3}
GD + momentum2.7×10−52.7\times10^{-5}2.6×10−52.6\times10^{-5}
Adam (diagonal)1.1×10−13\mathbf{1.1\times10^{-13}}2.5×10−62.5\times10^{-6}
Muon5.5×10−95.5\times10^{-9}6.1×10−96.1\times10^{-9}
Shampoo4.4×10−124.4\times10^{-12}2.4×10−112.4\times10^{-11}
SOAP1.3×10−111.3\times10^{-11}6.4×10−126.4\times10^{-12}

This is Lecture 12’s rotation lesson, one level up:

  • Aligned curvature: Adam’s diagonal scaling is ideal.
  • Rotated: Adam falls back by seven orders of magnitude. Muon, Shampoo and SOAP do not change, because they act through singular vectors or Gram matrices, which rotate with the matrix.

What each costs (Llama 3 8B’s hidden matrices, bytes per parameter including 8 bytes of weights, gradients and master copy; demo 02):

optimizerstatebytes / parameter
AdamWm,vm, v16
Muonmm12
Dion (rank d/16d/16)mm, a low-rank factor12.2
Shampoo, whole matricesm,L,Rm, L, R, both roots40
Shampoo, 1024 × 1024 blockssame, per block28
SOAP, whole matricesm,v,L,R,QL,QRm, v, L, R, Q_L, Q_R44

A 14336-wide MLP matrix has a 14336² factor. Blocking (as Distributed Shampoo does) caps that, but ignores correlations across blocks.


2. Is it really better? Evaluating optimizer claims

Before paying the engineering cost of §3, a lab must know whether the speedup is real. The slide’s cautionary example is NVIDIA’s own 3B-active / 30B-total MoE on 1T tokens with a 24M-token batch:

  • AdamW’s loss and gradient norm spike repeatedly; Muon’s do not;
  • Muon’s final validation loss is lower (1.195 vs 1.206).

But the Muon run also used QK layer norm and split Q, K, V for Newton–Schulz. And its logged wall-clock was 5.1 days vs 1.7 for AdamW at the same step, on an experimental branch. How much of the result belongs to Muon?

2.1 What a controlled comparison found

Wen, Hall, Ma and Liang (Fantastic Pretraining Optimizers) compared eleven optimizers:

  • models of 130M–1.2B parameters;
  • 1–8× Chinchilla data;
  • every hyperparameter of every optimizer tuned by coordinate descent, at each scale.

Speedup is measured in data. Fit AdamW’s loss as a function of tokens, then ask how many tokens AdamW would need to reach the other optimizer’s final loss.

Their findings:

  • Tuning one learning rate gives AdamW a 2× speedup. Raising its peak rate from GPT-3’s 6×10−46\times10^{-4} to 8×10−38\times10^{-3} halves the steps to a given loss (130M).
  • Each optimizer has its own best values. The best weight decay is 0.1 for AdamW and 0.6 for Lion.
  • Loss curves cross during learning-rate decay. Muon leads for most of a run; AdamW catches up in the final decay.
  • Speedups shrink with size. Against a tuned AdamW no optimizer beats ≈1.4×. Muon and SOAP fall from ≈1.4× at 130M to ≈1.1× at 1.2B.
  • The winner depends on tokens per parameter. Muon is best at 1–4× Chinchilla; SOAP and Kron pass it at 8× and beyond. Muon throws away the singular values of the momentum, while SOAP and Kron keep a second-moment estimate that becomes accurate only over many steps. (Lecture 9: modern small models train at 100× Chinchilla or more, where no one has run this comparison.)

2.2 The same questions on our LM (demo 03)

Demo 03 runs the comparison on Lecture 9’s model (width 64, 600 steps, cosine schedule). Each optimizer gets its own learning-rate sweep.

optimizerlearning rates swept → final loss (bits/byte; floor ≈ 0.72)best
AdamW6e-4: 0.9026 · 1e-3: 0.8194 · 2e-3: 0.7825 · 4e-3: 0.7749 · 8e-3: 0.7740 · 1.6e-2: 0.79410.7740
Muon3e-3: 0.7828 · 1e-2: 0.7683 · 3e-2: 0.7690 · 0.1: 0.78120.7683
SOAP2e-3: 0.7809 · 4e-3: 0.7679 · 8e-3: 0.7660 · 1.6e-2: 0.76790.7660
Lion3e-4: 1.1491 · 1e-3: 0.7855 · 3e-3: 0.7770 · 1e-2: 0.79820.7770

Question 1: was the baseline tuned? AdamW at GPT-3’s 6×10−46\times10^{-4} ends at 0.9026. Tuned AdamW reaches that loss in 2.88× fewer tokens, a larger factor than the slide’s 2×. An optimizer compared against the untuned baseline would inherit that whole factor.

Question 2: is the gain above the noise floor? Three seeds each:

seedsspread
AdamW0.7740, 0.7749, 0.77530.0014
Muon0.7683, 0.7684, 0.76710.0012

Muon’s advantage, 0.0068 on the means, is about 5× the spread. It is real.

Question 3: own hyperparameters? Here the measurement surprised us: Muon is remarkably insensitive.

  • 0.7683–0.7691 over learning rates 0.008–0.03;
  • 0.7691 with Jordan’s original update scale (about 1.6× smaller steps);
  • 0.7685 without weight decay.

Copying AdamW’s setting would not have changed the conclusion at this scale. RMS matching (§1.2) is what makes that reuse safe in production recipes. The slide’s 6× weight-decay gap between AdamW and Lion is the kind of mismatch that does mislead.

Question 4: compared at the end of a decayed schedule?

optimizerloss at step 300 (lr still high)rankfinalrank
AdamW0.815940.77403
Muon0.808620.76832
SOAP0.803110.76601
Lion0.811230.77704

AdamW and Lion swap places during the decay. Compare only final checkpoints of complete schedules.

Question 5: tokens or wall-clock? AdamW at four horizons gives its loss-vs-tokens curve: 150 steps 0.9854, 300 steps 0.8107, 600 steps 0.7740, 1200 steps 0.7605, 2400 steps 0.7508. Interpolating it:

run (600 steps)AdamW-equivalent stepstoken speeduptime/step vs AdamW (this CPU)wall-clock speedup
Muon8041.34×1.06×1.26×
SOAP9031.51×1.05×1.43×
Lion5670.95×0.89×1.06×

On a tiny model Newton–Schulz is a noticeable share of the step, so part of Muon’s token gain disappears in time (1.34× → 1.26×; the step-time ratio varied between 1.06× and 1.11× across our runs). A 2× slower step would cancel a 2× token saving entirely.

Question 6: at what size? Muon’s loss advantage over tuned AdamW, each with three learning rates:

width3264128
AdamW − Muon (bits/byte)+0.0080+0.0057+0.0046

It shrinks as the model widens, the same direction as the controlled benchmark. (A loss gap is not a speedup, and three toy widths are not a scaling law.)

Question 7: was the architecture tuned for AdamW? Norm placement, warm-up and other defaults were tuned for AdamW over a decade. A new optimizer runs on its competitor’s recipe. The guest lecture’s phrase: “neural networks (maybe) evolved to make Adam the best optimizer”. We cannot test this at our scale; keep it on the list.

A second benchmark (Semenov, Pagliardini and Jaggi) reached the same conclusions about tuning and training horizon, with a different ranking of winners.

2.3 Checking Moonlight’s 2× claim

questionMoonlight’s scaling-law runs
baseline tuned?yes: AdamW grid-searched at each compute-optimal size
own hyperparameters?no: Muon reused AdamW’s, through RMS matching
model size399M to 1.5B
tokens per parameter≈22–26, near Chinchilla, where Muon does best
end of a decayed schedule?not reported (“trained to convergence”)
tokens or wall-clock?training FLOPs

The baseline was tuned and Muon was not, which favours AdamW. But the runs sit where Muon does best: small sizes near Chinchilla. With every AdamW hyperparameter tuned by coordinate descent, the controlled benchmark measured about 1.3–1.4× at similar sizes. Neither study goes past 1.5B.

Their fitted scaling law even predicts Muon slightly behind AdamW at 7B, yet trillion-parameter production runs (Kimi K2, GLM-4.5/5) chose Muon. What could explain the difference? Candidates:

  • stability (no spikes, §4);
  • a larger critical batch;
  • and, from §5, the fixed-norm variant that raises Muon’s speedup at 1.2B to 20–30%.

3. Muon at scale

3.1 If the FLOPs are so small, why the infrastructure?

The <1% estimate of §1.5 makes three assumptions:

  1. each matrix is orthogonalised once, not once per rank;
  2. the whole matrix is on one GPU;
  3. the GEMMs run at full tensor-core speed.

At scale none of these holds by default. We take them in turn.

3.2 Newton–Schulz needs the whole matrix, but each rank holds a slice

AdamW updates each entry from that entry’s gradient and state, so every rank updates its own slice. Muon’s update multiplies the matrix by its transpose: every entry of NS(M)\mathrm{NS}(M) depends on every row of MM. A rank cannot compute its part of the update from its slice alone. This breaks assumption 2.

Sharded buffers make it worse. Megatron’s distributed optimizer and ZeRO flatten all parameters into one buffer and cut it into equal shards. The cuts ignore matrix boundaries. Buckets, added so communication overlaps the backward pass, add more cuts. FSDP2 splits every matrix across every rank.

Demo 04 counts the matrices a flat buffer cuts in Llama 3 8B’s 224 hidden matrices:

ranksbucketsmatrices split
810 (the 32 identical layers divide evenly, 4 per rank: a coincidence of the shapes)
64132
81696
6416192
6464224
64FSDP2224

3.3 The simplest fix repeats Newton–Schulz on every rank

Moonlight’s Distributed Muon:

  1. reduce-scatters gradients (as in ZeRO-1);
  2. updates momentum on the local shard;
  3. all-gathers the full matrix (BF16);
  4. runs Newton–Schulz;
  5. keeps only its own shard of the result;
  6. all-gathers the updated parameters.

Every rank repeats the same Newton–Schulz, which breaks assumption 1. Each rank does all of NS while its share of the training work shrinks by SS. The NS share therefore grows SS-fold (demo 04, Part A):

model (batch)NS share, once per matrixreplicated on 8 ranks32128
NanoGPT 124M (0.5M)0.62%5%20%80%
Llama 3 8B (4M)0.40%3%13%51%
Llama 3 405B (16M)0.41%3%13%52%

The slide’s estimate for 405B on 128 FSDP ranks is 0.5% × 128 ≈ 64%. Cheap at 8-way sharding, prohibitive at 128.

3.4 Give each matrix one owner

The fix is to make one rank the owner of each matrix:

  • the summed gradient goes to the owner (a reduce instead of a reduce-scatter);
  • the owner runs Newton–Schulz once;
  • the owner broadcasts the result (an uneven all-gather, “all-gather-v”).

Each matrix is orthogonalised once, and the work is split SS ways. This restores assumption 1, and it moves the same volume as ZeRO-1, just in uneven pieces. Megatron-LM’s LayerwiseDistributedOptimizer and Essential AI’s layer sharding work this way.

Load balance. Matrix sizes differ, so owners get unequal work (demo 04, Part C; load = NS FLOPs, imbalance = max/mean):

ranksround-robin (sorted by size)greedy (largest first, to least-loaded)idle ranks
641.2641.0570
1281.4531.0570
2562.1142.11432

The largest single matrix carries 0.83% of all NS work. So with SS ranks the imbalance can never beat max⁡(1,0.0083S)\max(1, 0.0083S). At 256 ranks, more ranks than matrices, 32 sit idle. DeepSeek-V4 packs dense matrices onto ranks with a knapsack solver (under 10% padding) and stacks same-shaped matrices into one batched GEMM. The guest lecture’s Megatron implementation uses a “ping-pong” ordering for the same reason, and treats MoE and attention layers differently because of expert parallelism.

3.5 Move whole matrices, or communicate inside every GEMM?

The four designs for Llama 3 8B on 64 data-parallel ranks (demo 04, Part D; per rank, per optimizer step; extra traffic relative to ZeRO-1 AdamW, which needs none of its own):

designNS FLOPs / rankat 50% of H100 BF16 peakextra bytes receivedvs ZeRO-1’s own traffic
replicated6.7×10146.7\times10^{14}1.35 s13.7 GB0.50×
owners (greedy)1.1×10131.1\times10^{13}0.02 s00
sharded matmul1.0×10131.0\times10^{13}0.02 s54 GB1.97×
Dion (rank d/16d/16)1.1×10111.1\times10^{11}~01.2 GB0.04×

For scale, the training step itself is 2.6×10152.6\times10^{15} FLOPs per rank (5.3 s at 50%).

The slide says Distributed Muon’s communication is “at most 1.25× that of ZeRO-1”. That counts ZeRO-1 as 8 bytes per parameter (FP32 both ways). With BF16 everywhere, the extra gather adds 0.5×.

Sharded matmul keeps each matrix sharded along its long side and distributes every GEMM. XX⊤XX^\top is then a sum over shards and needs an all-reduce of the m×mm \times m Gram matrix in every NS step. This is the tensor-parallel trade-off again (Lecture 6): communicate inside each of the 3T3T GEMMs, or move whole matrices once before and once after. Essential AI measured Muon’s share of step time for a 2B model on 8 MI300Xs:

designMuon’s share of step time
replicated43%
sharded matmul26%
layer sharding10%

With this engineering in Megatron-Core, Kimi K2 on 256 GB300s runs at 1,029 model TFLOP/s per GPU with Muon vs 1,051 with AdamW, about 2% slower.

The real thing, small (demo 04, Part E). Four gloo processes run three Muon steps on a 4-layer, d=256d = 256 transformer’s 28 matrices, in both designs:

designmax |W − single-process Muon|NS FLOPs / step (all ranks)bytes received / step (busiest rank)time / step
replicated8.0×10−88.0\times10^{-8}8.4×10108.4\times10^{10}28.5 MB89.2 ms
owners8.9×10−88.9\times10^{-8}2.1×10102.1\times10^{10}19.0 MB54.8 ms

Both give the same answer as one process. Replicated does 4× the work and three model-sized collectives instead of two. The owners design wins on this laptop, even though it issues two small collectives per matrix instead of three large ones.

3.6 Assumption 3: kernels

Plain PyTorch does not run these GEMMs at full speed. Two kernel tricks help:

  • XX⊤XX^\top is symmetric, so a kernel can compute only half of its tiles;
  • Gram Newton–Schulz iterates on the small m×mm \times m matrix XX⊤XX^\top and multiplies by the rectangular XX only at the ends.

Together these make NS about twice as fast. With a large pre-training batch, NS was about 2% of Kimi K2’s step. In fine-tuning with a small batch it was 17% for Llama 3 70B, which is where such kernels matter most (Zhang, Amsel, Chen, Dao; Flash-Muon).

3.7 Dion: adapt the optimizer to the layout

Dion (Ahn et al.) replaces Newton–Schulz with one step of power iteration per update:

  • it keeps a rank-rr factorisation warm between steps;
  • error feedback carries the discarded part to the next step;
  • its traffic is O((m+n)r)O((m+n)r) instead of O(mn)O(mn), and it works on shards directly.

Owners and layer sharding adapt the parallel layout to Muon. Dion adapts the optimizer to the existing layout. On the 405B configuration (FSDP 128, TP 8, PP 16), Dion at rank d/16d/16 cuts the optimizer step time by about an order of magnitude relative to Muon.

3.8 Shampoo’s way out: do expensive work less often, or elsewhere

Shampoo’s inverse roots need an eigendecomposition. The usual fix is to recompute them every kk steps and reuse the stale roots in between. Distributed Shampoo’s measured step overhead (ResNet-50, 8 V100s; demo 04, Part F):

refresh every kk steps12050100
overhead53%12.8%5.2%2.0%
overhead × kk53256260200

From k=20k = 20 on, overhead × kk is roughly constant: 1/kk amortisation of a fixed refresh cost. The every-step figure is far below what that law predicts (~250%), so that configuration must use a cheaper or overlapped path. The table supports “refresh every 50–100 steps costs a few percent”, not one cost model.

SOAP runs Adam in the eigenbasis, so a stale basis costs less than a stale Shampoo root.

Or move the work off the critical path. Anil et al. computed Shampoo’s roots on the idle host CPUs in FP64 while the accelerators kept training with the previous preconditioner. On WMT this gave 1.95× fewer steps and 16% slower steps, for 40% less wall-clock. Work whose inputs are known early can move to the host. The same idea returns in §6.

optimizerstate per paramupdate computefits ZeRO / FSDP slices?usual fix
AdamWm,vm, velementwise, bandwidth-boundyesnone needed
Muonmm3T3T GEMMs per matrix, every stepno, needs whole matricesowners, batched NS, symmetric kernels
Dionmm, low-rank factorpower iteration, rank rryesnone needed
Shampoom,L,Rm, L, Reigendecompositionnorefresh every kk, block, distribute, or move to CPU
SOAPm,v,L,Rm, v, L, RAdam in a rotated basisnosame as Shampoo

All matrix optimizers pay per matrix, per step. They are cheap in total FLOPs and expensive in how the work has to be placed.


4. Controlling scale

Adam and Muon both normalise their updates. The step size does not shrink as the gradient shrinks. Weights, attention logits and activations therefore need explicit bounds.

4.1 Without weight decay, the weights keep growing

Moonlight trained Muon with and without weight decay:

  • without it, Muon leads early and falls behind by the end;
  • with it, Muon stays ahead of AdamW with weight decay.

The weights and layer outputs grow for the whole run, past the range where BF16 is precise. Muon makes this more pressing: its update sets every singular value to 1, so each step pushes on all directions of a matrix at once.

Demo 05 measures it on our model (1,200 steps, best learning rates):

runhidden-matrix RMS @100@300@600@1200max activation @1200final loss
AdamW, wd 0.10.0340.0500.0580.06070.7605
Muon, wd 0.10.0570.1110.1320.129370.7537
Muon, wd 00.0590.1240.1640.178640.7528

Under Muon the weights are twice AdamW’s size even with decay, the full-rank steps of §1.2 at work. Without decay they keep growing, and the largest activation nearly doubles.

At this horizon the loss does not suffer (0.7528 vs 0.7537, within noise). Moonlight saw the no-decay run fall behind only after ~24,000 iterations. A 1,200-step toy run shows the mechanism, not the consequence.

4.2 Attention logits explode more often under Muon

In a vanilla 53B MoE trained with Muon, the largest attention logit climbed past 1,000 and showed no sign of converging (Kimi K2). Kimi K2 bounds the logits with QK-clip (查询键裁剪), which rescales weights after each optimizer step:

For every head hh whose largest pre-softmax logit SmaxhS^h_{max} in the batch exceeds τ\tau, set γ=τ/Smaxh\gamma = \tau/S^h_{max} and multiply that head’s WqW_q and WkW_k by γ\sqrt\gamma.

The head’s largest logit then becomes exactly τ\tau (= 100 in K2).

Why not QK-norm (Lecture 9)? MLA (Lecture 4) never materialises the full keys at inference, so K2 could not normalise them. Monitoring is free: the fused attention kernel already tracks each row’s maximum for its online softmax (Lecture 7). In K2, 12.7% of heads were clipped early in training, and after that the clip never fired. matrix_opt.qk_clip implements the rule per head, with the GQA edge case: a shared key head is left alone and only WqW_q is scaled.

Demo 05 provokes logit growth by training at 10× the tuned learning rate:

runmax logit @100@300@600@1200peak max activationfinal loss
AdamW, tuned (3e-3)1325252370.7605
Muon, tuned (1e-2)5161821410.7537
AdamW lr 3e-210716991464550.7737
Muon lr 0.130623156236912,8400.7727
Muon lr 0.1 + QK-clip (τ\tau = 30)303431273,8910.7709
Muon lr 0.1 + QK-norm111735452,8060.7680

The slide’s claim reproduces: at a high rate Muon’s logits climb an order of magnitude higher than AdamW’s (1,562 vs 181 at their peaks), and its activations further still.

  • QK-clip holds every logit at the cap without touching the learning rate, cuts the activation peak to a third, and slightly improves the loss.
  • QK-norm gives the best loss of the three.
  • Neither fixes the cause (the learning rate is 10× too high); they keep it from blowing up.

How often the clip fires:

steps1–120121–300301–600601–900901–1200
head-steps clipped2.8%30.0%40.2%34.6%18.0%

Unlike K2’s well-tuned run, the logits here keep pushing against the cap, because the rate is deliberately wrong.

4.3 A gate after attention removes sinks and outlier activations

Large values also show up in activations, with any optimizer. Gated attention (Qiu et al.) multiplies each head’s attention output elementwise by σ(xWg)\sigma(xW_g). A head with nothing to contribute can then output zero, instead of dumping its attention on the first token (an attention sink). In their 48-layer models:

  • attention to the first token fell from 46.7% to 4.8%;
  • the maximum activation fell from 1,053 to 94;
  • a learning rate of 8×10−38\times10^{-3} that diverged without the gate trained with it.

Smaller outliers make BF16, FP8 and FP4 easier to scale (Lecture 9). Qwen3-Next uses the gate; gpt-oss and DeepSeek-V4 clamp SwiGLU outputs for the same reason.

Demo 05 adds the gate (pretrain.add_attn_gate) to our model:

runmax activation @1200sink share @1200final loss
AdamW70.0370.7605
AdamW + gate40.0350.7597
Muon370.0370.7537
Muon + gate220.0390.7511

The gate cuts the largest activation by about 40%, at no loss cost (slightly better).

Plan vs reality: there is no attention sink in this 2-layer model to remove. The share of attention on the window’s first position is 0.035–0.039, below the 0.059 that uniform causal attention would give. The 46.7% → 4.8% result needs deep models trained long enough to develop sinks, and cannot be reproduced at this scale.

4.4 What kept recent Muon runs stable

runwhat kept it stable
Moonlightweight decay; update RMS matched to AdamW
Kimi K2QK-clip on MLA heads (no spikes over 15.5T tokens)
GLM-4.5QK-norm; Muon on all matrices except embeddings
GLM-5Muon applied to each head’s Q, K, V separately (“MuonSplit”: 15 × 64 small GEMMs instead of 15 large ones)
DeepSeek-V4RMSNorm on queries and KV entries; 8 + 2 NS schedule; SwiGLU outputs clamped to [−10, 10]

Switching a run from AdamW to Muon midway can fail. Marin tried it on its 32B run and the loss rose; moving to a backbone with QK-norm fixed the instability.

Two of the fixes change the effective learning rate:

fixknob it addsacts through η\eta?
update RMS matchingupdate scaleyes, it multiplies η\eta
decoupled weight decayλ\lambdayes, through ηλ\eta\lambda
QK-cliplogit cap τ\tauno, a bound
SwiGLU clampclamp rangeno, a bound

Logits and activations get hard bounds, set once and rarely touched. The weights get no bound of their own: their norm is controlled indirectly through η\eta and λ\lambda. So a new learning rate or a new model size means retuning both. The next section asks what weight decay actually controls, then replaces it with a direct bound.


5. Weight decay as an angular step size

5.1 What weight decay controls

Behind a normalisation layer, a weight’s direction matters and its scale does not. With decoupled weight decay, a weight’s norm settles where growth from updates balances shrinkage from decay. Lecture 12 §6 derived the equilibrium:

  • ∥W∥2≈η∥u∥2/(2λ)\lVert W\rVert^2 \approx \eta\lVert u\rVert^2/(2\lambda);
  • so the angle the weight rotates per step is

θ≈η∥u∥∥W∥≈2ηλ.\theta \approx \frac{\eta\lVert u\rVert}{\lVert W\rVert} \approx \sqrt{2\eta\lambda}.

At equilibrium the rotation rate depends on the product ηλ\eta\lambda alone. Weight decay is an indirect way of setting the angular learning rate, and it takes a time of order 1/(ηλ)1/(\eta\lambda) to reach that equilibrium. Wen et al. show two AdamW runs with the same ηλ\eta\lambda: their losses match while their query and key weight norms differ by 2×.

Demo 06 repeats the experiment. AdamW on the hidden matrices runs at a constant learning rate for 1,200 steps, with ηλ=2×10−3\eta\lambda = 2\times10^{-3} in four ways:

η\etaλ\lambdaweight RMS (end)η/λ\sqrt{\eta/\lambda}angle per step (rad)loss (constant lr)
0.00151.330.0280.0340.0130.7871
0.0030.6670.0440.0670.0160.7885
0.0060.3330.0830.1340.0160.7917
0.0120.1670.1650.2680.0170.7988
0.003 (ηλ=5×10−4\eta\lambda = 5\times10^{-4})0.1670.0710.1340.0100.7803

What reproduces, and what does not:

  • The norms differ, the rotation does not. The weight RMS spans a 6× range, ordered like η/λ\sqrt{\eta/\lambda}. Yet every matrix rotates 0.013–0.017 rad per step in all four runs. A different ηλ\eta\lambda rotates at a different rate (0.010). The angle is set by ηλ\eta\lambda.
  • The formula’s constant is off by about 4×. 2ηλ=0.063\sqrt{2\eta\lambda} = 0.063 rad, against 0.016 measured. The derivation assumes successive updates are uncorrelated, a random walk that decay balances. Adam’s momentum makes successive updates correlated, so the weights settle larger and rotate more slowly. The rate is still governed by ηλ\eta\lambda. (Lecture 12 demo 06 found the same kind of gap for the equilibrium norm.)
  • The losses agree only roughly. They span 0.012, about 10× the seed noise. Our model is not fully scale-invariant: without QK-norm, the scales of WqW_q and WkW_k set the attention logits, and SwiGLU’s gate is not scale-invariant either. So the weight scale still matters a little beyond the angle.

5.2 MuonH and AdamH: keep every matrix at a fixed norm

The hyperball optimizers (Wen et al., Fantastic Pretraining Optimizers II) drop weight decay and fix the norm directly:

Wt+1=R⋅Wt−ηtR ut/∥ut∥F∥Wt−ηtR ut/∥ut∥F∥F,R=∥W0∥F.W_{t+1} = R\cdot\frac{W_t - \eta_t R\,u_t/\lVert u_t\rVert_F}{\big\lVert W_t - \eta_t R\,u_t/\lVert u_t\rVert_F\big\rVert_F},\qquad R = \lVert W_0\rVert_F.

The update direction utu_t depends on the variant:

  • AdamH: ut=m^t/(v^t+ϵ)u_t = \hat m_t/(\sqrt{\hat v_t}+\epsilon);
  • MuonH: ut=NS(Mt)u_t = \mathrm{NS}(M_t).

Take a step of length ηtR\eta_tR, then project back onto the sphere of radius RR. There is no weight decay, and ηt\eta_t is directly the relative step ∥ΔW∥F/∥W∥F\lVert\Delta W\rVert_F/\lVert W\rVert_F (good values 0.0025–0.01). It is applied to attention and MLP matrices; embeddings, norm gains and scalars use Adam. The systems cost is two Frobenius norms per matrix per step. On a sharded matrix each is one scalar all-reduce. matrix_opt.Hyperball implements both.

Demo 06 sets AdamH’s relative step to the angle the AdamW runs actually rotate (0.0155):

  • it rotates 0.015 rad per step at a fixed norm, with no weight decay and no 1/(ηλ)1/(\eta\lambda) wait for equilibrium;
  • it reaches 0.8018, against 0.787–0.799 for the AdamW runs.

The rotation rate is reproduced directly. The loss is a little worse, a first hint of §5.3’s finding that on this model the fixed radius itself is a hyperparameter.

5.3 With a fixed norm, the best learning rate moves less

Wen et al. swept depths from 4 to 512 (width 128, 10B tokens each):

  • the best learning rate drifts by ≈1.4× across depth and width for AdamH and MuonH;
  • it drifts by 3–4× for AdamW and MuonW.

A rate tuned on a small model is closer to right on the large one. That is the goal of µP (Lectures 9 and 12), reached here by fixing the norm.

Demo 06 sweeps width instead of depth (400 steps, cosine schedule). The hidden matrices get the swept optimizer; embeddings and norms use AdamW at a fixed 3×10−33\times10^{-3} in every run.

optimizerwidth 32 bestwidth 64 bestwidth 128 bestdriftloss lost at width 128 with width 32’s best setting
AdamW (λ\lambda = 0.1)0.0080.0040.0024.0×+0.0275
AdamH (relative step)0.040.040.022.0×+0.0006

The transfer property reproduces. AdamW’s best rate halves with every doubling of width (Lecture 9 measured the same drift under standard parametrisation), so a rate tuned at width 32 costs 0.0275 bits/byte at width 128. AdamH’s best step barely moves, and carrying it over costs almost nothing.

The quality does not reproduce at this scale:

at width 64, 400 stepsbest loss
AdamW0.7924
AdamH0.8340
MuonW (λ\lambda = 0.1)0.7923
MuonH0.8865

Part of the reason is the radius. With RR fixed at the initial norm (RMS 0.02), the attention logits of a model without QK-norm stay small. With R=3∥W0∥R = 3\lVert W_0\rVert, MuonH improves to 0.8014, while AdamH at the same step gets worse (0.8743). On a model that is not scale-invariant, the radius is a real hyperparameter. The paper’s models put the normalisation where it makes the scale irrelevant.

5.4 A change that holds up: MuonH at 1.2B

In the same controlled benchmark as §2, with every optimizer tuned:

  • MuonW (Muon with weight decay) gives ≈10% over AdamW at 1.2B;
  • MuonH gives 20–30%, and the gap grows with the data budget.

MuonH starts at a higher loss and overtakes during the decay, one more reason to compare only final checkpoints.

Our 400-step toy runs reproduce the transfer property of §5.3, not this quality gain (§5.3’s second table). The 1.2B result rests on a model built for fixed norms and on long data budgets, where the gap grew. It is the kind of claim §2’s questions say to check at your own scale before adopting it.


6. Architecture and memory traffic

6.1 Parameters can live in three tiers of memory

tiercapacitybandwidth
HBM80–288 GB per GPU3–8 TB/s
host DRAM1–2 TB per nodePCIe ≈ 64 GB/s per GPU
NVMetens of TBa few GB/s per drive

Host memory is about 10× larger than HBM and about 50× slower to reach. A parameter can live there if the GPU knows which rows it needs early enough to copy them before the layer runs.

  • Dense weights fail this test: every one is used every step.
  • MoE experts fail it too: which experts a token uses depends on the hidden state at that layer.

6.2 Engram: hashed n-gram tables

Engram (DeepSeek) adds hashed n-gram lookup tables to a MoE:

  1. For each position, take the last 2 and 3 tokens.
  2. Several hash functions map each n-gram to a row of its own table, and the rows are concatenated.
  3. The hidden state decides how much of the retrieved vector to use, through a sigmoid gate.
  4. The result is added to the residual stream at a few early layers, before attention.

Frequent local patterns (names, phrases, code idioms) become a table lookup, so attention and experts do not have to rebuild them.

Results reported in the paper:

  • Split of sparse parameters. At fixed total parameters and FLOPs, loss is lowest when about a quarter of the inactive parameters go to memory (ρ≈\rho \approx 75–80% to experts).
  • Benchmarks. At 26.7B total / 3.8B active and 262B tokens, replacing 17 of 72 routed experts by 5.7B Engram parameters raised MMLU 57.4 → 60.4, BBH 50.9 → 55.9, HumanEval 37.8 → 40.8 and multi-query needle-in-a-haystack 84.2 → 97.0.
  • Host-memory table. Because the row indices depend only on the input tokens, they are known before the forward pass starts. The PCIe copy overlaps the layers before the Engram layer. With a 100B-parameter table entirely in host DRAM (H800), throughput fell only 1.9% (4B dense backbone) and 2.8% (8B).
  • Training. The tables are sharded across GPUs and rows are exchanged with an all-to-all, as in expert parallelism.
  • Placement trades quality for prefetch time. A deeper layer gives the prefetch more time, but the model does best with the lookup early (layer 2 of 12).

memory_arch.py implements a simplified Engram: 2- and 3-gram tables, 2 hash heads each, a sigmoid gate, WvW_v initialised to zero so the module starts as an exact no-op. pretrain.lm_logits gained a hook (model.pre_block) to insert it before any block.

Demo 07 trains it on our model (width 64, 2 layers, 600 steps, AdamW recipe):

modelparametersof which Engramforward FLOPs / tokenloss (all)loss (wiki)
baseline160K0254K0.77490.7254
+ Engram before block 0, 4096 rows/table430K270K270K (+6.5%)0.76700.6992
+ Engram before block 1, 4096 rows/table430K270K270K0.76780.6966
+ Engram before block 0, 1024 rows/table234K74K270K0.76830.7038
+ Engram before block 0, 16384 rows/table1,217K1,057K270K0.76580.6964
baseline, width 96320K0541K (+113%)0.77450.7233
baseline, width 128521K0909K (+258%)0.77090.7131

What the runs show:

  • Large gain for little compute. The Engram improves loss by 0.008 (about 6× the seed noise), and by 0.026 on the fact-heavy wiki domain, where multi-token entity names are exactly the “frequent local patterns” a lookup serves. It beats a model widened to 128, which costs 3.6× the FLOPs.
  • Placement. Before block 0 or block 1 makes little difference in a 2-layer model.
  • Table size. Bigger tables help with diminishing returns (0.7683 → 0.7670 → 0.7658 for 1K → 4K → 16K rows per table).

On this CPU the gather and hashing still cost time (10.0 vs 8.0 ms per step). On a GPU the rows would be prefetched, and the lookup is a memory operation rather than compute.

Prefetch arithmetic (the slide’s illustrative sizes):

  • 3 n-gram orders × 8 hash heads × 2 layers = 48 rows per token;
  • at 512 FP8 values per row, 24.6 KB per token;
  • at 20,000 tokens/s per GPU, 0.49 GB/s, 0.77% of a PCIe Gen5 link.

Computing all row addresses for a 64 × 64 batch from the token ids alone took 0.12 ms on this laptop. No model is needed, so the data loader can do it.

Lookups are Zipfian. Over the training tokens:

  • the hottest 1% of rows serve 12% of lookups;
  • the hottest 10% serve 49%.

A small cache of hot rows in HBM would absorb most of the traffic, even for tables far larger than HBM.

6.3 Production models now keep lookup tables off the accelerator

modeltablewhere it lives and what was found
DeepSeek-V4.1-Flash (Sep 2026)196B, FP8, 2 layershost memory, prefetched by background RDMA; the first production Engram
Qwen3.8-Flash-Next (Aug 2026)51B, 1 layeroff the accelerator, at layer 2 so the copy overlaps layer 1; lower loss, but no clear downstream gain over the MoE baseline
Google Gemma 3nper-layer embeddingsCPU or fast storage; 5B total, ≈2B in accelerator memory

The rule: whether a table can leave the GPU depends on when its address is known.

sparse componentaddress comes fromwhere it can live
n-gram tables (Engram, SCONE, Over-Encoding)input token idshost DRAM or NVMe, prefetched
hash routing (first MoE layers of DeepSeek-V4)input token idsexpert choice known in advance
learned MoE routinghidden state at that layerHBM; experts moved by all-to-all
product-key memory layers (Meta, UltraMem)hidden-state queryHBM, with fast gather kernels
KV cachepositionHBM, or offloaded by the serving engine

Meta’s memory layers scale to 128B memory parameters, but their lookups depend on the hidden state. They need custom gather kernels (3 TB/s on H100) and stay on the GPU.

6.4 Hyper-connections widen the residual stream

Hyper-connections keep nn residual streams instead of one, mixed by learned n×nn\times n matrices at every layer. The problem is that multiplying mixing matrices across 60 layers can amplify the signal by thousands (DeepSeek’s unconstrained 27B model peaked near 3,000).

mHC (manifold-constrained hyper-connections) projects each residual mixing matrix onto the doubly stochastic matrices (双随机矩阵: non-negative, rows and columns sum to 1) with 20 Sinkhorn–Knopp iterations. A product of doubly stochastic matrices is doubly stochastic, so its row and column sums stay 1 and the product cannot grow. DeepSeek-V4 uses mHC with n=4n = 4.

Demo 07 composes 60 random mixing matrices (n=4n = 4), unconstrained (II plus a perturbation) vs Sinkhorn-projected:

perturbationHC forward gain @10 layers@30@60max over layersmHC forward / backward (max)
0.051.361.63.13.31.0000 / 1.0000
0.101.482.75.05.01.0000 / 1.0000
0.206.2724.930.483.21.0000 / 1.0000

Small perturbations of the identity compound with depth. A doubly stochastic product keeps its gain at exactly 1 (row sums are exact after Sinkhorn’s last row normalisation; column sums to 10−410^{-4} after 20 iterations).

A wider residual stream costs memory traffic. Per token, per layer, hidden size CC (mHC paper):

plain residualmHC, n=4n = 4
elements read2C≈21C
elements writtenC≈13C
pipeline activationsC4C

The mixing is a few small matrix products, so it is bandwidth-bound, like the residual add and RMSNorm (Lecture 3). DeepSeek’s fixes:

  • fuse the mixing, norm and Sinkhorn steps into a few kernels;
  • do not store the wide stream: recompute it for blocks of layers aligned with pipeline stages;
  • overlap the 4× larger pipeline sends with compute in DualPipe.

The result is 6.7% extra time at n=4n = 4. V4.1 moves part of the mixing one block later and halves the activation traffic again; Qwen3.8 stores its widened residual in FP8.


7. Summary

  • Muon replaces each hidden matrix’s update with the orthogonalised momentum UV⊤UV^\top, computed by Newton–Schulz: odd polynomials applied to all singular values at once with three GEMMs per step. Gradients are dominated by a few directions (stable rank 9 of 128 here); Muon gives every direction the same step.
  • Coefficients trade speed for accuracy. Muon’s quintic is fast and sloppy ([0.47, 1.20]). Polar Express picks a minimax polynomial per step and converges; DeepSeek-V4 adds flat final steps. BF16 rounding of the input limits all of them.
  • Shampoo is Muon with memory (β2=0\beta_2 = 0 gives exactly UV⊤UV^\top). On Kronecker-structured curvature, matrix optimizers are rotation-invariant where Adam is not.
  • Evaluate claims carefully. Tuning AdamW’s learning rate was worth 2.9× in tokens here. Against a tuned baseline, Muon gave 1.34× and SOAP 1.51× in tokens, less in wall-clock. Muon’s advantage shrank with width. Mid-run rankings differed from final ones.
  • Matrix optimizers add few FLOPs but need whole matrices. Replicated Newton–Schulz grows SS-fold. Give each matrix one owner and balance greedily, or distribute GEMMs (more traffic), or change the algorithm (Dion). Do expensive work less often or off the critical path (Shampoo refreshes, host CPUs).
  • Normalised updates need explicit bounds. Weight decay (or a fixed norm) for the weights; QK-clip or QK-norm for the logits; gates or clamps for the activations.
  • Weight decay sets the angular step size ≈2ηλ\approx\sqrt{2\eta\lambda}; hyperball optimizers set it directly.
  • Architecture follows the memory hierarchy. Tables addressed by token ids can live off the GPU. A wider residual stream must be constrained (Sinkhorn) and costs bandwidth.

8. Common pitfalls

  • Applying Muon to embeddings, the output head or norm gains. Only hidden 2-D matrices.
  • Forgetting to normalise before Newton–Schulz. Singular values above 1.26 blow up under Muon’s quintic.
  • Comparing against an untuned baseline, or at one learning rate per optimizer, or mid-run.
  • Quoting a token speedup as a time speedup.
  • Replicating Newton–Schulz on every rank at large data-parallel degree.
  • Round-robin owners on unequal matrices, or more ranks than matrices.
  • Muon without weight decay on a long run. The weights grow without bound.
  • QK-norm on MLA. The keys are never materialised at inference; use QK-clip.
  • Moving a table to host memory whose address depends on the hidden state.

9. Exercises

  1. Newton–Schulz by hand. One step of Muon’s quintic on σ=0.1\sigma = 0.1 and on σ=1\sigma = 1. Then one step of the classic cubic on the same values. Which brings 0.10.1 closer to 1?
Answer

Muon: p(0.1)=0.34445−0.004775+0.0000203=0.3397p(0.1) = 0.34445 - 0.004775 + 0.0000203 = 0.3397; p(1)=3.4445−4.775+2.0315=0.701p(1) = 3.4445 - 4.775 + 2.0315 = 0.701. Cubic: p(0.1)=0.15−0.0005=0.1495p(0.1) = 0.15 - 0.0005 = 0.1495; p(1)=1.0p(1) = 1.0. Muon’s step lifts 0.1 to 0.34 (2.3× more than the cubic) at the price of mapping 1 to 0.70; the cubic keeps 1 exact but barely moves 0.1.

  1. Muon’s FLOP share. A 4096 × 14336 MLP matrix, 5 NS steps, batch 2M tokens. NS FLOPs as a share of the matrix’s training FLOPs? And if the run uses 64-way replicated Distributed Muon?
Answer

m=4096m = 4096, n=14336n = 14336. NS: 5×(4⋅40962⋅14336+2⋅40963)=5×(9.62×1011+1.37×1011)=5.5×10125 \times (4 \cdot 4096^2 \cdot 14336 + 2 \cdot 4096^3) = 5 \times (9.62\times10^{11} + 1.37\times10^{11}) = 5.5\times10^{12}. Training: 6⋅4096⋅14336⋅2×106=7.05×10146 \cdot 4096 \cdot 14336 \cdot 2\times10^6 = 7.05\times10^{14}. Share 0.78% (bound Tm/B=1.0%Tm/B = 1.0\%). Replicated on 64 ranks: each rank does all of it while its training share is 1/64, so ~50%.

  1. Shampoo = Muon. Show that for G=UΣV⊤G = U\Sigma V^\top with all σi>0\sigma_i > 0, (GG⊤)−1/4G(G⊤G)−1/4=UV⊤(GG^\top)^{-1/4}G(G^\top G)^{-1/4} = UV^\top. What changes with L=βL+GG⊤L = \beta L + GG^\top accumulated over steps?
Answer

GG⊤=UΣ2U⊤GG^\top = U\Sigma^2U^\top so (GG⊤)−1/4=UΣ−1/2U⊤(GG^\top)^{-1/4} = U\Sigma^{-1/2}U^\top; likewise (G⊤G)−1/4=VΣ−1/2V⊤(G^\top G)^{-1/4} = V\Sigma^{-1/2}V^\top. The product is UΣ−1/2ΣΣ−1/2V⊤=UV⊤U\Sigma^{-1/2}\Sigma\Sigma^{-1/2}V^\top = UV^\top. With accumulation, LL and RR are averages over many gradients; their eigenvectors no longer match the current GG‘s singular vectors, so the result is a whitened gradient, not UV⊤UV^\top (demo 02: cosine 0.84 at β2=0.9\beta_2 = 0.9).

  1. Owner balance. Ten matrices with NS costs 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 go to 3 owners. Give the round-robin (sorted) and greedy (largest-first to least-loaded) loads and imbalances.
Answer

Round-robin (sorted, rank r gets items r, r+3, …): rank 0 gets 10, 7, 4, 1 = 22; rank 1 gets 9, 6, 3 = 18; rank 2 gets 8, 5, 2 = 15. Mean 18.33, imbalance 22/18.33 = 1.20. Greedy: 10→r0, 9→r1, 8→r2; 7→r2 (15); 6→r1 (15); 5→r0 (15); now all three are at 15, so 4→r0 (19), 3→r1 (18), 2→r2 (17), 1→r2 (18). Loads 19, 18, 18: imbalance 19/18.33 = 1.04.

  1. Angular step. AdamW with η=3×10−4\eta = 3\times10^{-4}, λ=0.1\lambda = 0.1. Equilibrium angle per step, and the time to reach it? What hyperball step ηH\eta_H gives the same angle?
Answer

2ηλ=6×10−5=7.7×10−3\sqrt{2\eta\lambda} = \sqrt{6\times10^{-5}} = 7.7\times10^{-3} rad per step. Timescale 1/(ηλ)=33,0001/(\eta\lambda) = 33{,}000 steps: many runs never reach equilibrium. A hyperball optimizer gets the same rotation from step 1 with ηH≈7.7×10−3\eta_H \approx 7.7\times10^{-3}, inside the paper’s good range 0.0025–0.01.

  1. Engram prefetch. A table has 2 n-gram orders × 4 heads at each of 3 layers, rows of 256 BF16 values. At 50,000 tokens/s per GPU, what host-to-GPU bandwidth is needed? What share of a 64 GB/s PCIe link?
Answer

Rows per token: 2 × 4 × 3 = 24; bytes per row 512; 12.3 KB per token; × 50,000 = 0.61 GB/s, about 1% of the link. A hot-row cache in HBM cuts it further (Zipfian lookups).

  1. mHC gain. Why can a product of doubly stochastic matrices not amplify a signal in the infinity norm? What about an unconstrained product of matrices I+ElI + E_l with ∥El∥∞=0.1\lVert E_l\rVert_\infty = 0.1?
Answer

A non-negative matrix with rows summing to 1 has ∥A∥∞=1\lVert A\rVert_\infty = 1, and products of doubly stochastic matrices are doubly stochastic, so the product has infinity norm exactly 1. For I+ElI + E_l the bound is ∏(1+0.1)=1.160≈304\prod(1 + 0.1) = 1.1^{60} \approx 304 over 60 layers; in the worst case the growth is exponential in depth.

The Fall 2026 assignments do not ask for a Muon implementation. The methodology of §2 applies directly to the pre-training assignment, though, whenever you compare two recipes on your node:

  • tune each recipe’s learning rate;
  • compare final checkpoints of complete schedules;
  • measure a seed noise floor;
  • report speedups in both tokens and wall-clock.

If your project compares optimizers, §3’s question “does it fit my sharding?” decides whether the comparison survives your parallel layout. No assignment solutions are given here.

11. Research directions

  • Optimizers for the overtrained regime. No controlled comparison exists at 100× Chinchilla, where small production models train.
  • Precision of orthogonalisation. When does the sloppiness of a fixed quintic cost loss at scale? Can coefficients be chosen for BF16/FP8 GEMMs?
  • Communication-native matrix optimizers. Dion-style low-rank updates, or optimizers that orthogonalise blocks that match the sharding.
  • Co-designing architecture with the optimizer. Norm placement, warm-up and initialisation were tuned for AdamW; what is the best architecture for Muon?
  • Memory hierarchy as a design input. Which other components can be addressed early (from token ids or positions) and moved off the GPU?

12. Further reading

  • Jordan et al., Muon: An optimizer for hidden layers in neural networks (2024), and github.com/KellerJordan/Muon.
  • Liu et al., Muon is Scalable for LLM Training (Moonlight, arXiv:2502.16982); Essential AI, Practical Efficiency of Muon for Pretraining (arXiv:2505.02222) and Layer Sharding for Large-Scale Training with Muon (blog, 2025).
  • Amsel et al., The Polar Express (arXiv:2505.16932); Zhang, Amsel, Chen, Dao, Gram Newton–Schulz (2026).
  • Gupta, Koren, Singer, Shampoo (arXiv:1802.09568); Shi et al., Distributed Shampoo (arXiv:2309.06497); Vyas et al., SOAP (arXiv:2409.11321); Anil et al., Scalable Second Order Optimization (arXiv:2002.09018).
  • Bernstein and Newhouse, Old Optimizer, New Norm (arXiv:2409.20325); Ahn et al., Dion (arXiv:2504.05295).
  • Kimi K2 (arXiv:2507.20534); Qiu et al., Gated Attention for LLMs (arXiv:2505.06708).
  • Wen et al., Fantastic Pretraining Optimizers and Where to Find Them (arXiv:2509.02046) and II: Hyperball Optimization (arXiv:2606.16899); Semenov, Pagliardini, Jaggi, Benchmarking Optimizers for LLM Pretraining (arXiv:2509.01440).
  • DeepSeek, Conditional Memory via Scalable Lookup (Engram, arXiv:2601.07372), mHC (arXiv:2512.24880), DeepSeek-V4 (arXiv:2606.19348).
  • NVIDIA-NeMo, Emerging-Optimizers (github.com/NVIDIA-NeMo/Emerging-Optimizers) and Megatron-LM’s layer_wise_optimizer.py.

13. Next lecture

Lecture 14 · Running an AI/HPC Fleet. So far a “cluster” has been a number of GPUs in a formula. Lecture 14 is the operator’s view:

  • why pre-training needs a cluster (strong vs weak scaling, bandwidth tiers) and what is in one (scheduler, orchestrator, compute, network, storage, observability);
  • how a cluster is brought up and validated (GEMM, NCCL tests, application runs);
  • how success is measured: the efficiency cascade from the contract to the tensor cores, GPU counters and OFU, failure attribution and MTBI, scheduling goodput.

Lecture 1’s fleet simulator returns, now with a scheduler, a queue and health checks.


术语表 (Glossary, English → 中文)

English中文
matrix optimizer / orthogonalisation矩阵优化器 / 正交化
singular value decomposition (SVD) / singular value奇异值分解 / 奇异值
Muon / Newton–Schulz iterationMuon 优化器 / 牛顿-舒尔茨迭代
odd polynomial / fixed point奇多项式 / 不动点
minimax approximation / equioscillation / Remez algorithm极小极大逼近 / 等振荡 / Remez 算法
Polar Express / polar decompositionPolar Express / 极分解
stable rank稳定秩
RMS matching均方根匹配
Shampoo / Kronecker factor / inverse fourth rootShampoo / 克罗内克因子 / 逆四次方根
SOAP / eigenbasis / preconditioner refreshSOAP / 特征基 / 预条件器刷新
Kron (PSGD)Kron(预条件随机梯度下降)
speedup in tokens / in wall-clock按数据量的加速 / 按墙钟时间的加速
noise floor / seed噪声底 / 随机种子
flat sharded buffer / bucket扁平分片缓冲区 / 分桶
matrix owner / load balancing / knapsack矩阵属主 / 负载均衡 / 背包问题
all-gather-v / reduce / broadcast不等长全收集 / 归约 / 广播
Gram matrix格拉姆矩阵
Dion / low-rank update / error feedbackDion / 低秩更新 / 误差反馈
attention logit / QK-clip / QK-norm注意力 logit / 查询键裁剪 / 查询键归一化
gated attention / attention sink门控注意力 / 注意力汇聚点
outlier activation离群激活值
angular step size / equilibrium norm角步长 / 平衡范数
hyperball optimizer (AdamH, MuonH)超球面优化器
memory hierarchy / host memory / prefetch存储层次 / 主机内存 / 预取
Engram / hashed n-gram tableEngram / 哈希 n 元组表
hyper-connections / residual stream超连接 / 残差流
doubly stochastic matrix / Sinkhorn–Knopp双随机矩阵 / Sinkhorn-Knopp 归一化
← 返回课程目录