Scaling Up

Dive into Deep Learning · §9.9

Width Parameterization and μP Scaling
standard parametrization drift · coherent first Adam step · Maximal Update Parametrization (μP) · coordinate check · spectral scaling

Why Proxy Learning Rates Fail as Networks Widen

Motivation

  • Standard Parametrization (SP) drift: Tuning Adam on a narrow proxy (n = 128, \eta^\star \approx 3.9 \times 10^{-3}) and transferring to a 64\times wider network (n = 8{,}192) wipes out the entire 1{,}000\times parameter increase (\approx 0.33 vs. retuned \approx 0.22 loss) because \eta^\star drifted down 16\times.
  • Maximal Update Parametrization (\mu\text{P}, Yang et al., 2022): Scales layer LRs and readout multipliers by m = n/n_{\text{base}} so \eta^\star transfers zero-shot across widths.

Fan-In and Fan-Out Growth Across Network Widths

Layer Taxonomy

In our 3-hidden-layer ReLU MLP 784 \to n \to n \to n \to 10 across n \in \{128, 512, 2048, 8192\}, the four linear layers belong to three distinct scaling classes:

  • 1. Input layer (fc_in, 784 \to n): Fan-in is fixed (784); only fan-out grows with n.
  • 2. Hidden layers (fc_h1, fc_h2, n \to n): Both fan-in and fan-out grow with n.
  • 3. Output readout (fc_out, n \to 10): Fan-in grows with n; fan-out is fixed (10).
  • Standard Parametrization (SP): Initializes every weight matrix from \mathcal{N}(0, 1/\text{fan-in}), biases at 0, and assigns a single global Adam learning rate \eta to all layers.
class MLP(nn.Module):
    """A three-hidden-layer ReLU network under standard parametrization."""
    def __init__(self, width):
        super().__init__()
        self.fc_in = nn.Linear(784, width)
        self.fc_h1 = nn.Linear(width, width)
        self.fc_h2 = nn.Linear(width, width)
        self.fc_out = nn.Linear(width, 10)
        for lin in (self.fc_in, self.fc_h1, self.fc_h2, self.fc_out):
            nn.init.normal_(lin.weight, std=lin.in_features ** -0.5)
            nn.init.zeros_(lin.bias)

    def features(self, X):
        h = F.relu(self.fc_h1(F.relu(self.fc_in(X))))
        return F.relu(self.fc_h2(h))

    def forward(self, X):
        return self.fc_out(self.features(X))

    def configure_adam(self, lr):
        return torch.optim.Adam(self.parameters(), lr)

Under SP, Optimal Learning Rate Drifts Downward 16–32×

Measuring SP Drift

  • Sweeping Adam across 10 log-spaced learning rates \eta \in \{2^{-14}, \ldots, 2^{-5}\} over 400 steps (b = 512, 2 seeds) for widths n \in \{128, 512, 2048, 8192\}:
    • As width n increases 64\times (128 \to 8{,}192), the U-shaped loss curves shift steadily to the left.
    • The optimal learning rate falls 16\text{--}32\times with a log–log slope of -0.7 to -0.8.
    • At width 8{,}192, the width-128 optimum sits high up on the unstable right wall of the curve.

best lr: 3.9e-03  2.0e-03  4.9e-04  2.4e-04    slope -0.70

Why Initialization Is Θ(1) While Adam Step 1 Is Θ(ηn)

Coherent vs. Incoherent Sums

  • At initialization (incoherent random signs \to \Theta(1)): W_{ij} \sim \mathcal{N}(0, 1/n) is independent of h_j = \Theta(1), so z_i = \sum_{j=1}^n W_{ij}h_j sums in quadrature to \operatorname{Var}(z_i) = \Theta(1).
  • After 1 Adam step (aligned signs \to \Theta(\eta n)): \Delta\mathbf{W} = -\eta\operatorname{sign}(\boldsymbol{\delta})\operatorname{sign}(\mathbf{h})^\top aligns every sign with \mathbf{h}: (\Delta\mathbf{W}\,\mathbf{h})_i = -\eta\,\operatorname{sign}(\delta_i)\sum_{j=1}^n |h_j| = -\eta\,\operatorname{sign}(\delta_i)\,n\,\overline{|h|}

The Fan-In Law: One Adam Step Shifts Outputs by Θ(ηn)

Quantitative Scaling Breakdown

Because all n terms |h_j| > 0 add with the same sign, a single Adam step changes a hidden unit’s pre-activation by \Theta(\eta n) relative to its initial \Theta(1) scale:

Hidden Width n Fan-In of fc_h1, fc_h2, fc_out First-Step Feature Shift \eta n at \eta = 2^{-8} \approx 0.0039 Regime at Fixed \eta = 0.0039
n = 128 128 0.50\times activation scale Stable feature refinement
n = 512 512 2.00\times activation scale Moderately large step
n = 2{,}048 2{,}048 8.00\times activation scale Overshoots initial representation
n = 8{,}192 8{,}192 32.0\times activation scale Catastrophic layer blow-up

Why hidden learning rates must scale as 1/n: Keeping (\Delta\mathbf{W}\,\mathbf{h})_i = \Theta(1) invariant across widths requires scaling the Adam learning rate of every hidden matrix with fan-in n as \eta_{\text{hidden}} \propto 1/n (log–log slope -1).

Maximal Update Parametrization (μP) Rules for Adam

Three Per-Layer Rules

  • Relative to base width n_{\text{base}} with width multiplier m = n / n_{\text{base}}, \mu\text{P} (Yang et al., 2022) keeps every layer’s activations and updates \Theta(1) as m \to \infty:
    • 1. Input weights & 1D biases: Init variance 1/\text{fan-in}, Adam LR \eta.
    • 2. Hidden matrices (n \times n): Init variance 1/n, scaled Adam LR \eta / m.
    • 3. Output readout (n \to d_{\text{out}}): Init variance 1/n_{\text{base}}, Adam LR \eta, forward multiplier 1/m.

Why the Output Layer Must Average (1/n) and Base Width

Output Scaling & Reference Anchor

  • 1. Readout weight update \frac{1}{m}\Delta\mathbf{W}_{\text{out}}\,\mathbf{h}: Sums n sign-aligned terms; dividing logits by m = n/n_{\text{base}} keeps the logit update \Theta(1) at LR \eta.
  • 2. Incoming feature update \frac{1}{m}\mathbf{W}_{\text{out}}\,\Delta\mathbf{h}: Aligned \Delta\mathbf{h} sums n terms of size |\frac{1}{m}W_{\text{out},ij}|; keeping unscaled init variance at 1/n_{\text{base}} makes effective weights O(1/n) so the sum stays \Theta(1).
  • Base width n_{\text{base}}: At n = n_{\text{base}} (m = 1), \mu\text{P} coincides identically with SP.

Implementing μP in 15 Lines of Code

Subclassing Standard Parametrization

  • Setting base_width=8192 (m = 1 at n = 8{,}192) makes MuMLP identical to MLP at the widest network so both sweeps share the exact same anchor at n = 8{,}192:
    • Rule 1 (__init__): Multiply fc_out weights (initialized at std 1/\sqrt{n}) by \sqrt{m} = \sqrt{n / n_{\text{base}}} so variance becomes \frac{1}{n} \cdot \frac{n}{n_{\text{base}}} = \frac{1}{n_{\text{base}}}.
    • Rule 2 (forward): Divide features entering fc_out by m.
    • Rule 3 (configure_adam): Set hidden matrix learning rate to lr / self.m.
class MuMLP(MLP):
    """The same network under muP, relative to a width-8,192 base."""
    def __init__(self, width, base_width=8192):
        super().__init__(width)
        self.m = width / base_width
        # Rule 1: output init variance 1/base_width at every width
        with torch.no_grad():
            self.fc_out.weight.mul_(self.m ** 0.5)

    def forward(self, X):
        # Rule 2: scale the output matrix's logits; the bias is untouched
        return self.fc_out(self.features(X) / self.m)

    def configure_adam(self, lr):
        hidden = [self.fc_h1.weight, self.fc_h2.weight]
        rest = [p for p in self.parameters()
                if not any(p is q for q in hidden)]
        return torch.optim.Adam([
            {'params': rest, 'lr': lr},
            {'params': hidden, 'lr': lr / self.m}])  # Rule 3: hidden LR / m

The One-Step Coordinate Check: SP Blows Up as O(n³)

Verifying Scaling Before Training

  • The coordinate check (Yang et al., 2022) takes 1 Adam step on a single minibatch across widths n \in \{128, 256, \ldots, 8192\} and plots the mean absolute activation \overline{|h_\ell|} of each layer.
  • Under Standard Parametrization (MLP):
    • Layer 1 (fc_in, fan-in 784): Flat across all widths (\Theta(1)).
    • Layer 2 (fc_h1, fan-in n): Grows linearly with width as O(n) (slope +1).
    • Layer 3 (fc_h2): Compounds Layer 2’s input blow-up with its own O(n) update to grow as O(n^2) (slope +2).
    • Output logits (fc_out): Explodes 1{,}000\times across the width range as O(n^3) (slope +3).

Under μP, Every Layer’s Coordinate Check Is Flat

Width-Invariant Feature Updates

  • Running the exact same 1-step coordinate check on MuMLP across n \in \{128, 256, \ldots, 8192\} produces four completely flat curves (\Theta(1) at every layer and every width).
  • Diagnostic asymmetry to remember:
    • Rising curves on a coordinate check immediately convict a broken \mu\text{P} implementation (e.g., forgetting the 1/m logit scale or \eta/m hidden LR).
    • Flat curves rule out exploding updates (\gg \Theta(1)), but an over-shrunk learning rate (such as \eta/m^2) also looks flat after 1 step because weights barely move from initialization.

Zero-Shot Learning-Rate Transfer Across Widths Under μP

Aligned Optima Across a 64× Width Range

  • Repeating the 400-step learning-rate sweep across n \in \{128, 512, 2048, 8192\} under \mu\text{P}:
    • The U-shaped curves now align vertically across the entire 64\times width range (135K to 141M parameters).
    • The log–log slope of \eta^\star(n) collapses from about -0.7 under SP to near 0.0 (the optimum stays at 2.4 \times 10^{-4} or within one grid step at every width).
    • Wider networks achieve strictly lower training loss at the exact same shared learning rate.

best lr: 2.4e-04  2.4e-04  1.2e-04  2.4e-04    slope -0.05

Quantifying the Transfer Penalty: SP vs. μP

Cost of Proxy-to-Target Transfer

  • How much loss do we pay at width 8{,}192 when we use the learning rate tuned on the 1{,}000\times smaller width-128 proxy instead of retuning at width 8{,}192?
    • Under SP: Loses 0.09\text{--}0.15 nats (\approx 0.33 vs. \approx 0.22), no better than the narrow width-128 proxy itself.
    • Under \mu\text{P}: Loses \le 0.003 nats (\approx 0.22 either way), completely indistinguishable from seed noise.
  • Notice also that under \mu\text{P}, narrower proxy networks rise sooner on the right of \eta^\star (where step size \eta/m reaches initial weight size 1/\sqrt{n} at \eta = \sqrt{n}/n_{\text{base}}), so a rate stable on the narrow proxy is guaranteed to be stable on the wide target.
SP  best loss per width: 0.323  0.300  0.259  0.222
    width 8192 at the width-128 lr 0.333  (seeds 0.330  0.337)
    width 8192 at its own lr       0.222  (seeds 0.222  0.222)
muP best loss per width: 0.327  0.261  0.237  0.222
    width 8192 at the width-128 lr 0.222  (seeds 0.222  0.222)
    width 8192 at its own lr       0.222  (seeds 0.222  0.222)

Extending μP to Transformers: The 1/d_k Attention Rule

Transformer Parameterization

  • Embeddings & 1D norms/biases (fan-in = 1): Standard init, full AdamW learning rate \eta.
  • Internal 2D matrices (qkv, proj, mlp): Init variance 1/\text{fan-in}, scaled AdamW LR \eta / m (m = d/d_{\text{base}}).
  • Readout head (d \to V): Init variance 1/d_{\text{base}}, forward logits \times 1/m, LR \eta.
  • Attention scores (\mathbf{q}^\top\mathbf{k} over d_k \propto d): Scale by 1/d_k instead of 1/\sqrt{d_k} because aligned updates \Delta\mathbf{q}, \Delta\mathbf{k} sum d_k coherent products (\Theta(d_k)).

The Spectral Condition: ||ΔW||₂ = Θ(√(d_out/d_in))

Operator-Norm Unification

  • Universal spectral condition (Yang, Simon & Bernstein, 2023): Keeping activations \mathbf{h} \in \mathbb{R}^{d_{\text{in}}} and \mathbf{z} = \mathbf{W}\mathbf{h} \in \mathbb{R}^{d_{\text{out}}} at \Theta(1) per entry requires: \|\mathbf{W}\|_2 = \Theta\!\left(\sqrt{\frac{d_{\text{out}}}{d_{\text{in}}}}\right), \quad \|\Delta\mathbf{W}\|_2 = \Theta\!\left(\sqrt{\frac{d_{\text{out}}}{d_{\text{in}}}}\right)
  • Adam step 1 is a rank-1 sign outer product: \|\Delta\mathbf{W}\|_2 = \eta\|\mathbf{s}\|_2\|\mathbf{t}\|_2 = \Theta(\eta\sqrt{d_{\text{out}}d_{\text{in}}}), which matches \Theta(\sqrt{d_{\text{out}}/d_{\text{in}}}) iff \eta \propto 1/d_{\text{in}}.

Width Scaling for Spectral Optimizers (Muon vs. AdamW)

Comparing Update Spectral Norms

  • For an n \times n hidden matrix, requiring \|\Delta\mathbf{W}\|_2 = \Theta(\sqrt{n/n}) = \Theta(1) dictates how \eta scales with width n:
    • AdamW: \|\Delta\mathbf{W}\|_2 = \Theta(\eta n) \implies \eta \propto 1/n (\eta/m).
    • Muon (0.2\sqrt{n}\,\mathrm{NS}_5): \|\Delta\mathbf{W}\|_2 = \Theta(\eta\sqrt{n}) \implies \eta \propto 1/\sqrt{n} (\eta/\sqrt{m}).
    • Spectral-scaled Muon (\sqrt{d_{\text{out}}/d_{\text{in}}}\,\mathrm{NS}_5): \|\Delta\mathbf{W}\|_2 = \Theta(\eta) \implies \eta = \Theta(1) (transfers with no 1/m factor).

Concept Check: Coherent Sums, Coordinate Checks, and μP

Check Your Understanding

Test your grasp of width parameterization on three concrete problems:

  1. Doubling width under SP: If you double the hidden width n of our MLP at a fixed Adam learning rate \eta, by what factor does the first Adam step change the output of (a) the input matrix fc_in (784 \to n), (b) the hidden matrix fc_h1 (n \to n), and (c) the readout matrix fc_out (n \to 10)?
  2. Reading a broken coordinate check: You implement \mu\text{P} with m = n/n_{\text{base}} \ge 1, remembering to set the hidden matrix learning rate to \eta/m but forgetting to divide the output logits by m. What will the 4 curves of the 1-step coordinate check look like?

Answers:

  1. Step 1 shifts a layer’s output by \Theta(\eta \cdot \text{fan-in}): (a) fc_in has fixed fan-in 784 \to 1\times (unchanged); (b) fc_h1 and (c) fc_out both have fan-in n \to 2\times larger shift.
  2. Layers 1, 2, and 3 (h1, h2, h3) will be completely flat (\Theta(1)), while the output logit curve will grow linearly with width as O(n) (slope +1) because \Delta\mathbf{W}_{\text{out}}\,\mathbf{h} sums n aligned terms without the 1/m divisor.

Concept Check: Scaling Hidden Learning Rates with Width

Check Your Understanding

  1. Scaling down learning rates from n = 128 to n = 2{,}048 (m = 16): By what factor must the hidden-matrix learning rate be divided when widening 16\times under (a) Adam with \mu\text{P}, (b) Muon with the 0.2\sqrt{\max(m,n)} factor, and (c) Muon with the \sqrt{d_{\text{out}}/d_{\text{in}}} factor?

Answer:

  1. For a 16\times widening (m = 16): (a) Adam \mu\text{P} divides by m = 16\times; (b) AdamW-scaled Muon divides by \sqrt{m} = 4\times; (c) operator-scaled Muon divides by 1\times (no change).

Summary: Width Parameterization and μP Scaling

Key Takeaways

Concept / Rule Mathematical Mechanism Scaling Behavior vs. Width n (m = n/n_{\text{base}}) Practical Engineering Role
SP First-Step Drift (\Delta\mathbf{W}\,\mathbf{h})_i = -\eta\operatorname{sign}(\delta_i)\,n\,\overline{|h|} Coherent sum of n aligned signs grows as \Theta(\eta n) Causes \eta^\star(n) to drift down 16\text{--}32\times from n=128 \to 8{,}192
\mu\text{P} Hidden Layer Rule Init variance 1/n, Adam LR \eta / m (\eta/m)\,n\,\overline{|h|} = \eta\,n_{\text{base}}\,\overline{|h|} = \Theta(1) Cancels the O(n) fan-in sum on internal n \times n matrices
\mu\text{P} Output Layer Rule Init variance 1/n_{\text{base}}, forward logits \times 1/m, LR \eta Effective weights & updates scale as O(1/n) Keeps both \Delta\mathbf{W}_{\text{out}}\mathbf{h} and \mathbf{W}_{\text{out}}\Delta\mathbf{h} at \Theta(1)
1-Step Coordinate Check Plot \overline{|h_\ell|} vs. n \in \{128, \ldots, 8192\} after 1 step SP explodes as O(n), O(n^2), O(n^3); \mu\text{P} is flat Catches missing \mu\text{P} multipliers in seconds before training
Spectral Condition \|\Delta\mathbf{W}\|_2 = \Theta(\sqrt{d_{\text{out}}/d_{\text{in}}}) Unifies Adam (\eta \propto 1/n) and Muon (\eta \propto 1/\sqrt{n} or 1) Enables zero-shot hyperparameter transfer from small proxies