Muon

Dive into Deep Learning · §9.6

Matrix Preconditioning and Muon
steepest descent under norm balls · spectral norm & UVᵀ · Newton–Schulz quintic · RMS alignment · Muon+AdamW hybrid

Weight Matrices Are Linear Operators, Not Flat Vectors

Motivation

  • Permutation blindness of entrywise methods: SGD, Momentum, and AdamW treat \mathbf{W} \in \mathbb{R}^{m \times n} as mn independent coordinates—shuffling entries of \mathbf{W} leaves AdamW’s steps unchanged.
  • Operator geometry (83.5\% of TinyLM): Internal 2D weight matrices map layer activations \mathbf{x} \in \mathbb{R}^n \mapsto \mathbf{y} = \mathbf{W}\mathbf{x} \in \mathbb{R}^m.
  • Central question: What is the steepest descent direction when we bound the activation shift \Delta\mathbf{y} = \Delta\mathbf{W}\,\mathbf{x}?

Steepest Descent Depends on the Norm Ball

Geometry of Steepest Descent

Given the first-order Taylor expansion f(\mathbf{x} + \mathbf{d}) \approx f(\mathbf{x}) + \langle\mathbf{g}, \mathbf{d}\rangle, the steepest descent step of radius \eta > 0 under a norm \|\cdot\| solves (Bernstein & Newhouse, 2024):

\mathbf{d}^\star = \operatorname*{argmin}_{\|\mathbf{d}\| \le \eta}\; \langle\mathbf{g}, \mathbf{d}\rangle

  • 1. Euclidean ball (\|\mathbf{d}\|_2 \le \eta): Minimized along the negative gradient \mathbf{d}^\star = -\eta\,\frac{\mathbf{g}}{\|\mathbf{g}\|_2} (the direction of SGD).
  • 2. Coordinate box (\|\mathbf{d}\|_\infty = \max_i |d_i| \le \eta): Pushes every coordinate to its corner \mathbf{d}^\star = -\eta\,\operatorname{sign}(\mathbf{g}) (sign descent, smoothed by Adam).

Measuring Matrix Steps by the Spectral Operator Norm

Matrix Operator Geometry

  • Spectral norm bounds activation shift: \|\Delta\mathbf{W}\,\mathbf{x}\|_2 \le \|\Delta\mathbf{W}\|_2\,\|\mathbf{x}\|_2, \quad \|\Delta\mathbf{W}\|_2 = \sigma_1(\Delta\mathbf{W})
  • SVD vs. Frobenius norm: For \mathbf{G} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top = \sum_{i=1}^r \sigma_i\mathbf{u}_i\mathbf{v}_i^\top, \|\mathbf{G}\|_2 = \sigma_1 measures the max directional stretch, whereas \|\mathbf{G}\|_F = \sqrt{\sum_i \sigma_i^2} overstates an orthogonal r=128 update by \sqrt{128} \approx 11.3\times.

Under the Spectral Norm, Steepest Descent Is UVᵀ

The Orthogonalized Gradient

  • Spectral steepest descent replaces every active singular value with 1: \Delta\mathbf{W}^\star = \operatorname*{argmin}_{\|\Delta\mathbf{W}\|_2 \le \eta}\; \langle\mathbf{G}, \Delta\mathbf{W}\rangle = -\eta\,\mathbf{U}\mathbf{V}^\top
  • Proof via trace duality: For \|\mathbf{A}\|_2 \le 1, \langle\mathbf{G}, \mathbf{A}\rangle = \sum_{i=1}^r \sigma_i (\mathbf{U}^\top\mathbf{A}\mathbf{V})_{ii} \ge -\sum_{i=1}^r \sigma_i = -\|\mathbf{G}\|_*, achieved at \mathbf{A} = -\mathbf{U}\mathbf{V}^\top.

Why Entrywise Sign Descent Can Collapse to Rank 1

Entrywise vs. Spectral Equalization

  • Consider \mathbf{G} = \begin{bmatrix}3 & 1\\ 1 & 1\end{bmatrix} (\sigma_1 \approx 3.41, \sigma_2 \approx 0.59):
    • Euclidean (-\mathbf{G}/\|\mathbf{G}\|_F): Singular values (0.99, 0.17) starve the second direction.
    • Coordinate box (-\operatorname{sign}(\mathbf{G}) = -\mathbf{1}\mathbf{1}^\top): Singular values (2.00, 0.00) collapse to rank 1.
    • Spectral (-\mathbf{U}\mathbf{V}^\top = -\mathbf{I}_2): Singular values (1.00, 1.00) take a full step along every orthogonal feature mode.

Three Norm Geometries and Connection to Shampoo

Unifying Preconditioners

Norm Constraint on Update Steepest Direction Linearized Decrease Suited Parameter Group
Euclidean (\|\mathbf{d}\|_2 \le \eta) -\eta\,\mathbf{g}/\|\mathbf{g}\|_2 \eta\,\|\mathbf{g}\|_2 Unstructured vector (SGD)
Coordinate Box (\|\mathbf{d}\|_\infty \le \eta) -\eta\,\operatorname{sign}(\mathbf{g}) \eta\,\|\mathbf{g}\|_1 Embeddings, 1D norms/biases, readout head (AdamW)
Spectral (\|\Delta\mathbf{W}\|_2 \le \eta) -\eta\,\mathbf{U}\mathbf{V}^\top \eta\,\|\mathbf{G}\|_* = \eta\sum_i \sigma_i Dense 2D hidden projection matrices (Muon)
  • Muon is memoryless Shampoo: Shampoo (Gupta et al., 2018) accumulates left and right Gram matrices \mathbf{L}_t = \sum_{s \le t}\mathbf{G}_s\mathbf{G}_s^\top and \mathbf{R}_t = \sum_{s \le t}\mathbf{G}_s^\top\mathbf{G}_s to precondition via \mathbf{L}_t^{-1/4}\mathbf{G}_t\mathbf{R}_t^{-1/4}. Evaluated on a single matrix \mathbf{G} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top: (\mathbf{G}\mathbf{G}^\top)^{-1/4}\,\mathbf{G}\,(\mathbf{G}^\top\mathbf{G})^{-1/4} = \mathbf{U}\boldsymbol{\Sigma}^{-1/2}\mathbf{U}^\top \cdot \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top \cdot \mathbf{V}\boldsymbol{\Sigma}^{-1/2}\mathbf{V}^\top = \mathbf{U}\mathbf{V}^\top

Orthogonalization Without SVD: Odd Matrix Polynomials

Newton–Schulz Iteration

  • Odd matrix polynomials preserve singular vectors: For \mathbf{X} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^\top and \mathbf{A} = \mathbf{X}\mathbf{X}^\top = \mathbf{U}\boldsymbol{\Sigma}^2\mathbf{U}^\top: p(\mathbf{X}) = (a\mathbf{I} + b\mathbf{A} + c\mathbf{A}^2)\mathbf{X} = \mathbf{U}\,p(\boldsymbol{\Sigma})\,\mathbf{V}^\top
  • Two-step GPU recipe:
    1. Normalize \mathbf{X}_0 = \mathbf{G} / (\|\mathbf{G}\|_F + \epsilon) so \sigma_i \in [0, 1].
    2. Apply \mathbf{X}_{k+1} = p(\mathbf{X}_k) for 5 fast matmul steps so p^{(5)}(\sigma_i) \approx 1.

Jordan et al.’s Tuned Quintic Newton–Schulz Polynomial

Trading Exact Asymptotics for 5-Step Speed

  • The classical cubic p(x) = 1.5x - 0.5x^3 converges to 1 asymptotically, but its small slope at the origin (p'(0) = 1.5, so 1.5^5 \approx 7.6) lifts small singular values far too slowly over 5 iterations.
  • Muon’s tuned quintic (Jordan et al., 2024) maximizes initial slope p'(0) = 3.4445 (3.4445^5 \approx 485\times amplification): p(x) = 3.4445\,x - 4.7750\,x^3 + 2.0315\,x^5
  • After 5 iterations, every singular value in [0.0015, 1] lands inside the band [0.68, 1.13].

Implementing Newton–Schulz and Its FLOP Cost

Fast GPU Orthogonalization

  • Transposing tall matrices (m > n): When m > n, we transpose \mathbf{X} \leftarrow \mathbf{M}^\top so the Gram matrix \mathbf{A} = \mathbf{X}\mathbf{X}^\top has the smaller dimension \min(m,n) \times \min(m,n).
  • Negligible FLOP overhead at scale:
    • For an m \times n matrix (m \le n) and token batch size B, 5 Newton–Schulz steps cost 5(4m^2 n + 2m^3) FLOPs vs. 6mnB FLOPs for forward + backward.
    • Overhead is \sim \frac{5m}{B}: <1\% at production batch sizes (B \sim 5 \times 10^5 tokens) and \sim 12\% on TinyLM (m = 128, B = 4{,}096).
def newton_schulz(M, num_iters=5, a=3.4445, b=-4.7750, c=2.0315, eps=1e-7):
    """Approximate the orthogonalization U V^T of M by num_iters steps of
    the odd polynomial a x + b x^3 + c x^5 (Jordan et al.'s tuned quintic)."""
    tall = M.shape[0] > M.shape[1]
    X = M.T if tall else M  # Keep the Gram factor X @ X.T small
    X = X / (X.norm() + eps)
    for _ in range(num_iters):
        A = X @ X.T
        X = a * X + (b * A + c * A @ A) @ X
    return X.T if tall else X

Singular Value Spectrum Collapse Under Newton–Schulz

Spectrum Flattening

  • Applying newton_schulz to a 96 \times 64 Gaussian matrix \mathbf{G} (whose normalized singular values span [0.02, 0.22]) shows rapid spectrum collapse:
    • k = 1: Lifted by up to 3.44\times.
    • k = 3: Entire spectrum compressed into [0.68, 1.20].
    • k = 5: Flattened into [0.68, 1.13].
  • Built-in noise damping: Any trailing singular value below 0.15\% of \|\mathbf{G}\|_F (0.68 / 3.4445^5 \approx 0.0014) stays small rather than being amplified to 1.

after 3 iterations: [0.68, 1.20]
after 5 iterations: [0.68, 1.13]

The Complete Muon Update and Entrywise RMS Alignment

Matching AdamW’s Learning Rate

  • Muon update (\beta = 0.95, Liu et al., 2025): \mathbf{W}_{t+1} = (1-\eta\lambda)\mathbf{W}_t - 0.2\eta\sqrt{\max(m,n)}\;\mathrm{NS}_5(\mathbf{G}_t + \beta\mathbf{M}_t)
  • Why average before \mathrm{NS}_5? Extracts persistent singular directions over 20 steps before applying nonlinear orthogonalization.
  • Why 0.2\sqrt{\max(m, n)}? Since \text{RMS}(\mathbf{U}\mathbf{V}^\top) = 1/\sqrt{\max(m,n)}, this multiplier sets the entrywise step RMS to 0.2\,\eta, matching AdamW so both share a single \eta and \lambda.

Implementing Muon from Scratch

Code Implementation

Muon keeps one momentum buffer (buf) per parameter, half of AdamW’s optimizer state:

class Muon(torch.optim.Optimizer):
    """Steepest descent under the spectral norm: orthogonalized momentum."""
    def __init__(self, params, lr, momentum=0.95, weight_decay=0.0):
        super().__init__(params, dict(lr=lr, momentum=momentum,
                                      weight_decay=weight_decay))

    @torch.no_grad()
    def step(self):
        for group in self.param_groups:
            for p in group['params']:
                if p.grad is None:  # A parameter that received no gradient
                    continue
                state = self.state[p]
                if not state:  # First step: allocate the momentum buffer
                    state['buf'] = torch.zeros_like(p)
                buf = state['buf'].mul_(group['momentum']).add_(p.grad)
                G = p.grad + group['momentum'] * buf  # Nesterov momentum
                M = G.reshape(len(G), -1)             # Flattens conv kernels
                O = newton_schulz(M).reshape(p.shape)
                rms_scale = 0.2 * math.sqrt(max(M.shape))  # AdamW's RMS
                p.mul_(1 - group['lr'] * group['weight_decay'])  # Decoupled
                p.add_(O, alpha=-group['lr'] * rms_scale)

Partitioning Parameters: The Muon + AdamW Hybrid

Hybrid Architecture

  • Spectral-norm geometry applies specifically to dense linear transformations between continuous activation vectors:
    • Routed to Muon (8 tensors, 393{,}216 params, 83.5\%): All internal 2D block matrices (qkv, proj, mlp1, mlp2 across both Transformer blocks), with decoupled weight decay \lambda = 0.1.
    • Routed to AdamW (22 tensors, 77{,}568 params, 16.5\%): Token/position embedding lookup tables, 1D biases and LayerNorm scales, and the vocabulary readout head (\lambda = 0).
  • 42% optimizer-state memory reduction: Storing 1 buffer on 83.5\% of parameters and 2 buffers on 16.5\% uses 0.835(1) + 0.165(2) = 1.165 buffers/param instead of 2.0 (58\% of AdamW’s state memory).
Muon:   8 tensors,  393216 parameters
AdamW: 22 tensors,   77568 parameters

Benchmarking Muon + AdamW vs. AdamW on TinyLM

Training & Validation Trajectories

  • Sweeping both AdamW and the Muon + AdamW hybrid across \eta \in \{10^{-3}, 3{\times}10^{-3}, 10^{-2}, 3{\times}10^{-2}, 10^{-1}\} (\lambda = 0.1 on hidden matrices, 2{,}000 steps from identical initial weights):
    • Fast early progress: At step 500, Muon+AdamW leads validation loss by >0.10 nats (about 1.7–1.75 vs. 1.88 nats).
    • Earlier threshold crossing: Crosses 1.60 validation nats at least 250 steps earlier than AdamW.

validation loss  lr     step 500  step 2000  below 1.6  within 0.15
AdamW            0.003  1.884     1.584      1750       0.001 to 0.01
Muon+AdamW       0.003  1.762     1.548      1500       0.001 to 0.03

High-Rate Stability: Muon+AdamW Trains at 3× Higher LR

Usable Learning-Rate Window

  • AdamW learning-rate sweep:
    • At \eta = 0.03 (3\times above the top of its usable window, \eta = 0.01), AdamW stalls above 2.4 nats because early rank-1 sign updates have spectral norm \sqrt{\min(m,n)} \approx 11\times larger than an orthogonalized update of equal entry RMS.
lr 0.001: final loss 1.685, validation loss 1.660
lr 0.003: final loss 1.610, validation loss 1.584
lr 0.01: final loss 1.667, validation loss 1.646
lr 0.03: final loss 2.745, validation loss 2.735
lr 0.1: final loss 2.967, validation loss 2.974
  • Muon + AdamW hybrid sweep:
    • By bounding the spectral norm of every hidden matrix update, the hybrid remains trainable at \eta = 0.03 (validation loss about 1.67), expanding the usable LR window upward by 3\times.
lr 0.001: final loss 1.624, validation loss 1.598
lr 0.003: final loss 1.573, validation loss 1.548
lr 0.01: final loss 1.602, validation loss 1.578
lr 0.03: final loss 1.693, validation loss 1.673
lr 0.1: final loss 2.063, validation loss 2.010

Scaling Muon to Long Pretraining Runs and QK-Clip

Long-Horizon Pretraining Caveats

  • Step reductions shrink with size: ≈1.4× at 0.1B to ≈1.1× at 1.2B parameters (Wen et al., 2025). Kimi K2 (1T, 2025) trains with Muon, with no AdamW run to compare. Long runs need two safeguards:
  • 1. Decoupled weight decay (\lambda > 0) is mandatory: Because \mathrm{NS}_5 normalizes singular values to \sim 1 at every step, weight norms \|\mathbf{W}\|_F grow unboundedly without (1-\eta\lambda) shrinkage.
  • 2. Bilinear QK-Clip: Attention logits \mathbf{q}^\top\mathbf{k} = \mathbf{x}^\top\mathbf{W}_Q^\top\mathbf{W}_K\mathbf{x} are a product of two matrices; rescaling \mathbf{W}_Q, \mathbf{W}_K when max logits exceed 100 prevents softmax saturation.

Concept Check: Spectral Norm, Quintic, and RMS Scale

Check Your Understanding

Work out the exact numerical answer for each Muon design question:

  1. Entrywise RMS matching: For TinyLM’s first MLP matrix \mathbf{W} \in \mathbb{R}^{512 \times 128}, what is the Frobenius norm and entrywise RMS of an exact orthogonal matrix \mathbf{U}\mathbf{V}^\top \in \mathbb{R}^{512 \times 128}, and what does the multiplier 0.2\sqrt{\max(512, 128)} turn that entrywise RMS into?
  2. Why embeddings stay with AdamW: Suppose a minibatch contains token A 500 times and token B once, so the embedding gradient matrix \mathbf{G} has two nonzero rows \mathbf{g}_A \perp \mathbf{g}_B with \|\mathbf{g}_A\|_2 = 500\,\|\mathbf{g}_B\|_2. What does exact orthogonalization \mathbf{U}\mathbf{V}^\top do to those two rows, and what does AdamW do instead?
  3. 3-step vs. 5-step Newton–Schulz reach: Given initial quintic slope p'(0) = 3.4445, how large must a normalized singular value \sigma / \|\mathbf{G}\|_F be to reach 0.68 in 3 iterations versus 5 iterations?

Concept Check: Spectral Norm, Quintic, and RMS Scale (answers)

Check Your Understanding

Answers:

  1. \mathbf{U}\mathbf{V}^\top has \min(512, 128) = 128 unit singular values, so \|\mathbf{U}\mathbf{V}^\top\|_F = \sqrt{128} across 512 \times 128 = 65{,}536 entries, giving entry RMS \sqrt{\frac{128}{512 \times 128}} = \frac{1}{\sqrt{512}} \approx 0.0442. Multiplying by 0.2\sqrt{512} \approx 4.525 yields an exact entrywise RMS of 0.2.
  2. Both active rows of \mathbf{U}\mathbf{V}^\top get unit \ell_2 norm (coupling rare and frequent token directions across the vocabulary), whereas AdamW normalizes each row entry by its own historical EMA \sqrt{\hat{v}_{t,ij}} independently.
  3. Three steps amplify small values by at most 3.4445^3 \approx 40.9, requiring \sigma/\|\mathbf{G}\|_F \ge 0.68/40.9 \approx 1.66\%; five steps amplify by 3.4445^5 \approx 485, reaching down to 0.14\%.

Summary: Norm Balls, Newton–Schulz, and Muon

Key Takeaways

Concept / Component Mathematical Formula Computational / Memory Property Deep Learning Role
Spectral Steepest Descent \operatorname*{argmin}_{\|\Delta\mathbf{W}\|_2 \le \eta}\langle\mathbf{G}, \Delta\mathbf{W}\rangle = -\eta\,\mathbf{U}\mathbf{V}^\top Sets all active singular values of \mathbf{G} to 1; decrease \eta\|\mathbf{G}\|_* Bounds worst-case activation shift \|\Delta\mathbf{W}\mathbf{x}\|_2 / \|\mathbf{x}\|_2 \le \eta
Newton–Schulz Quintic p(\mathbf{X}) = 3.4445\mathbf{X} - 4.7750\mathbf{A}\mathbf{X} + 2.0315\mathbf{A}^2\mathbf{X} 5 matmul iterations lift \sigma/\|\mathbf{G}\|_F \ge 0.15\% into [0.68, 1.13] Approximates \mathbf{U}\mathbf{V}^\top on GPUs with \sim 5m/B < 1\% FLOP overhead
Muon Update & Scale \mathbf{W}_{t+1} = (1-\eta\lambda)\mathbf{W}_t - 0.2\eta\sqrt{\max(m,n)}\,\mathrm{NS}_5(\mathbf{G}_t+\beta\mathbf{M}_t) 1 momentum buffer per matrix (\beta = 0.95); entry RMS \approx 0.2\eta Shares \eta and \lambda directly with AdamW; cuts state memory by 42\%
Muon + AdamW Hybrid Muon on hidden 2D matrices (84\%); AdamW on emb/head/1D (16\%) 3\times higher upper stable LR on TinyLM; \approx 1.4\times fewer steps at 0.1B, \approx 1.1\times at 1.2B Pair with decoupled weight decay \lambda > 0 (and QK-Clip at extreme scale)