import random9.9 Scaling Up
Neural networks are developed at small scale and deployed at large scale. Because a multi-billion-parameter pretraining run cannot afford a grid search over learning rates, practitioners tune hyperparameters on a small proxy model of the same architectural family and transfer them to the target scale.
Under the standard parametrization (SP) used by default in deep learning frameworks, where layer weights are initialized with variance \(1/\text{fan-in}\) and all layers share a single global learning rate \(\eta\), the optimal learning rate does not transfer across model width. As layer width \(n\) increases, a single Adam step changes hidden-layer pre-activations by \(O(\eta n)\) because the \(n\) terms in the matrix-vector product \(\Delta\mathbf{W}\,\mathbf{h}\) align in sign with the incoming activations \(\mathbf{h}\). Consequently, the optimal learning rate drifts downward as the model widens.
The Maximal Update Parametrization (\(\mu\text{P}\), Yang and Hu (2021); Yang et al. (2022)) eliminates this drift by scaling the learning rate and output multiplier of each layer according to its fan-in and fan-out growth, ensuring that every hidden layer experiences \(\Theta(1)\) feature updates as width \(n \to \infty\). In this section, we measure the learning-rate drift under SP across a \(64\times\) range of MLP widths (\(n = 128\) to \(8{,}192\)), derive the first-step scaling rule, implement \(\mu\text{P}\) and verify it with the one-step coordinate check (Yang et al. 2022; Dey et al. 2024), demonstrate zero-shot learning-rate transfer across widths, and extend the rules to Transformers, spectral-norm optimizers, and depth.
import random9.9.1 Learning Rate and Width Under Standard Parametrization
9.9.1.1 A Family of Widths and Learning-Rate Drift
Consider a three-hidden-layer ReLU MLP on Fashion-MNIST whose hidden width \(n\) varies across \(\{128, 512, 2048, 8192\}\) (from \(1.35 \times 10^5\) to \(1.41 \times 10^8\) parameters). Note how each weight matrix scales with \(n\):
- Input layer (
fc_in, \(784 \to n\)): fan-in is fixed (\(784\)), fan-out grows with \(n\). - Hidden layers (
fc_h1,fc_h2, \(n \to n\)): both fan-in and fan-out grow with \(n\). - Output readout (
fc_out, \(n \to 10\)): fan-in grows with \(n\), fan-out is fixed (\(10\)).
Under standard parametrization (SP), every weight matrix is initialized from \(\mathcal{N}(0, 1/\text{fan-in})\), biases are initialized to zero, and all parameters share a single Adam learning rate \(\eta\). We first flatten and normalize the \(60{,}000\) Fashion-MNIST training images onto the accelerator:
fashion = d2l.FashionMNIST()
device = d2l.try_gpu()
X = (fashion.train.data.float().reshape(-1, 784) / 255).to(device)
Y = fashion.train.targets.to(device)fashion = d2l.FashionMNIST()
X = jnp.asarray(fashion.train[0], dtype=jnp.float32).reshape(-1, 784) / 255
Y = jnp.asarray(fashion.train[1], dtype=jnp.int32)Next we define MLP(width) with layers \(784 \to n \to n \to n \to 10\) initialized with standard deviation \(\text{fan-in}^{-1/2}\) and a single Adam learning rate across all parameters:
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)class MLP(nnx.Module):
"""A three-hidden-layer ReLU network under standard parametrization."""
def __init__(self, width, *, rngs):
init = nnx.initializers.variance_scaling(1.0, 'fan_in', 'normal')
self.fc_in = nnx.Linear(784, width, kernel_init=init, rngs=rngs)
self.fc_h1 = nnx.Linear(width, width, kernel_init=init, rngs=rngs)
self.fc_h2 = nnx.Linear(width, width, kernel_init=init, rngs=rngs)
self.fc_out = nnx.Linear(width, 10, kernel_init=init, rngs=rngs)
def features(self, X):
h = nnx.relu(self.fc_h1(nnx.relu(self.fc_in(X))))
return nnx.relu(self.fc_h2(h))
def __call__(self, X):
return self.fc_out(self.features(X))
def configure_adam(self, lr):
return nnx.Optimizer(self, optax.adam(lr), wrt=nnx.Param)To measure how the optimal learning rate varies with width \(n\), train_mlp trains arch(width) for \(400\) steps of Adam (\(b = 512\)) and returns the mean loss over the final \(50\) steps (capped at \(2.5\) for diverged runs):
def train_step(model, optimizer, Xb, Yb):
loss = F.cross_entropy(model(Xb), Yb)
optimizer.zero_grad()
loss.backward()
optimizer.step()
return loss.detach()
def train_mlp(arch, width, lr, seed, num_steps=400, batch_size=512):
torch.manual_seed(seed)
model = arch(width).to(device)
optimizer = model.configure_adam(lr)
idx = torch.as_tensor(np.random.default_rng(seed).integers(
0, X.shape[0], (num_steps, batch_size)), device=device)
losses = torch.stack([train_step(model, optimizer, X[i], Y[i])
for i in idx])
v = float(losses[-50:].mean()) # Mean minibatch loss of the last 50 steps
return min(v, 2.5) if math.isfinite(v) else 2.5@nnx.jit
def train_step(model, optimizer, Xb, Yb):
def loss_fn(model):
return optax.softmax_cross_entropy_with_integer_labels(
model(Xb), Yb).mean()
loss, grads = nnx.value_and_grad(loss_fn)(model)
optimizer.update(model, grads)
return loss
def train_mlp(arch, width, lr, seed, num_steps=400, batch_size=512):
model = arch(width, rngs=nnx.Rngs(seed))
step = nnx.cached_partial(train_step, model, model.configure_adam(lr))
idx = jnp.asarray(np.random.default_rng(seed).integers(
0, X.shape[0], (num_steps, batch_size)))
losses = jnp.stack([step(X[i], Y[i]) for i in idx])
v = float(losses[-50:].mean()) # Mean minibatch loss of the last 50 steps
return min(v, 2.5) if math.isfinite(v) else 2.5The helpers sweep, print_optimum, and plot_sweep evaluate train_mlp across a grid of widths, learning rates, and seeds, fit the log–log slope of the optimal learning rate \(\eta^\star(n)\) versus \(n\), and plot the seed-averaged loss curves:
def sweep(arch, widths, lrs, seeds):
"""Score of every width and learning rate, one column per seed."""
return {w: np.array([[train_mlp(arch, w, lr, s) for s in seeds]
for lr in lrs]) for w in widths}
def print_optimum(loss, lrs):
"""Best rate of the seed-averaged loss per width; slope in log-log."""
widths = list(loss)
best = [lrs[loss[w].mean(1).argmin()] for w in widths]
slope = np.polyfit(np.log(widths), np.log(best), 1)[0]
print('best lr:', ' '.join(f'{lr:.1e}' for lr in best),
f' slope {slope:+.2f}')
def plot_sweep(loss, lrs):
d2l.plot(lrs, [l.mean(1) for l in loss.values()], 'learning rate',
'training loss', xscale='log', ylim=[0.2, 0.8],
legend=[f'width {w}' for w in loss])def sweep(arch, widths, lrs, seeds):
"""Score of every width and learning rate, one column per seed."""
return {w: np.array([[train_mlp(arch, w, lr, s) for s in seeds]
for lr in lrs]) for w in widths}
def print_optimum(loss, lrs):
"""Best rate of the seed-averaged loss per width; slope in log-log."""
widths = list(loss)
best = [lrs[loss[w].mean(1).argmin()] for w in widths]
slope = np.polyfit(np.log(widths), np.log(best), 1)[0]
print('best lr:', ' '.join(f'{lr:.1e}' for lr in best),
f' slope {slope:+.2f}')
def plot_sweep(loss, lrs):
d2l.plot(lrs, [l.mean(1) for l in loss.values()], 'learning rate',
'training loss', xscale='log', ylim=[0.2, 0.8],
legend=[f'width {w}' for w in loss])We now execute sweep on MLP across widths \(n \in \{128, 512, 2048, 8192\}\) and \(10\) log-spaced learning rates \(\eta \in \{2^{-14}, \ldots, 2^{-5}\}\) over two shared seeds:
widths = [128, 512, 2048, 8192]
lrs = [2.0 ** k for k in range(-14, -4)]
seeds = [random.getrandbits(32) for _ in range(2)] # Shared by every sweep
sp_loss = sweep(MLP, widths, lrs, seeds)
print_optimum(sp_loss, lrs)
plot_sweep(sp_loss, lrs)best lr: 3.9e-03 2.0e-03 4.9e-04 2.4e-04 slope -0.70
widths = [128, 512, 2048, 8192]
lrs = [2.0 ** k for k in range(-14, -4)]
seeds = [random.getrandbits(32) for _ in range(2)] # Shared by every sweep
sp_loss = sweep(MLP, widths, lrs, seeds)
print_optimum(sp_loss, lrs)
plot_sweep(sp_loss, lrs)best lr: 3.9e-03 2.0e-03 4.9e-04 2.4e-04 slope -0.70
Under standard parametrization, the U-shaped loss curves shift steadily to the left as width grows: the optimal learning rate drops \(16\)–\(32\times\) (from \(\sim 3.9 \times 10^{-3}\) at width \(128\) to \(\sim 1\)–\(2 \times 10^{-4}\) at width \(8{,}192\), a log–log slope of \(-0.7\) to \(-0.8\)). Applying the width-\(128\) optimal learning rate directly to the width-\(8{,}192\) model pushes it far up the unstable right arm of its curve, wiping out the benefit of the \(1{,}000\times\) larger parameter count.
9.9.1.2 Optimal Learning Rate Drift on the First Adam Step
To see why \(\eta^\star\) must fall with width \(n\), consider a square hidden weight matrix \(\mathbf{W} \in \mathbb{R}^{n \times n}\) mapping activation vector \(\mathbf{h} \in \mathbb{R}^n\) to \(\mathbf{z} = \mathbf{W}\mathbf{h}\). Because \(W_{ij} \sim \mathcal{N}(0, 1/n)\) is independent of \(\mathbf{h}\) at initialization, each coordinate \(z_i\) has variance \(\Theta(1)\) independent of \(n\).
For a single example with backpropagated output gradient \(\boldsymbol{\delta} = \partial \ell / \partial \mathbf{z}\), the weight gradient is the outer product \(\mathbf{G} = \boldsymbol{\delta}\mathbf{h}^\top\). On step \(1\), Adam’s bias-corrected update is \(\Delta\mathbf{W} = -\eta\,\operatorname{sign}(\mathbf{G}) = -\eta\,\operatorname{sign}(\boldsymbol{\delta})\operatorname{sign}(\mathbf{h})^\top\). Evaluated on the same activation vector \(\mathbf{h}\), the resulting shift in pre-activation \(z_i\) is
\[ \begin{aligned} (\Delta\mathbf{W}\, \mathbf{h})_i &= -\eta \sum_{j=1}^{n} \operatorname{sign}(\delta_i h_j)\, h_j = -\eta\, \operatorname{sign}(\delta_i) \sum_{j=1}^{n} |h_j| \\ &= -\eta\, \operatorname{sign}(\delta_i)\, n\, \overline{|h|}, \end{aligned} \tag{9.9.1}\]
where \(\overline{|h|} = \frac{1}{n}\sum_{j=1}^n |h_j| = \Theta(1)\). Because \(\Delta W_{ij}\) is correlated with \(h_j\), all \(n\) terms in the sum share the same sign and add coherently (\(O(n)\)) rather than cancelling like random-sign initialization terms (\(O(\sqrt{n})\)). To keep the feature update \((\Delta\mathbf{W}\,\mathbf{h})_i = \Theta(1)\) invariant to width \(n\), the learning rate of a hidden matrix with fan-in \(n\) must scale as \(\eta \propto 1/n\) (log–log slope \(-1\); the empirical slope of \(-0.7\) to \(-0.8\) on the full MLP reflects a compromise between the \(n \times n\) hidden matrices and the fixed-fan-in input layer and biases).
9.9.2 Maximal Update Parametrization (\(\mu\text{P}\))
9.9.2.1 The \(\mu\text{P}\) Scaling Rules
Rather than forcing a single global learning rate across layers with different fan-in scaling, Maximal Update Parametrization (\(\mu\text{P}\), Yang and Hu (2021); Yang et al. (2022)) scales each layer relative to a reference base width \(n_{\text{base}}\) via the width multiplier \(m = n / n_{\text{base}}\) (Table 9.9.1):
- Input weights and 1D biases/norms (fixed fan-in): Keep initial variance \(1/\text{fan-in}\) and learning rate \(\eta\) unchanged.
- Hidden matrices (fan-in and fan-out \(\propto n\)): Keep initial variance \(1/\text{fan-in} = 1/n\) and scale the Adam learning rate as \(\eta / m\), so that \((\eta / m)\,n\,\overline{|h|} = \eta\,n_{\text{base}}\,\overline{|h|} = \Theta(1)\) at every width.
- Output readout matrix (fan-in \(\propto n\), fixed fan-out): Because both \(\Delta\mathbf{W}_{\text{out}}\,\mathbf{h}\) and \(\mathbf{W}_{\text{out}}\,\Delta\mathbf{h}\) sum \(n\) correlated terms into the output logits, \(\mathbf{W}_{\text{out}}\) must have entry magnitude \(O(1/n)\) rather than \(O(1/\sqrt{n})\). Fixing the unscaled weight initialization variance at \(1/n_{\text{base}}\), multiplying the output logits by \(1/m\) in the forward pass, and keeping the Adam learning rate at \(\eta\) ensures that both the effective output weights and their updates scale as \(O(1/n)\), producing \(\Theta(1)\) logit updates at every width.
| Parameter group | Initial variance | Adam learning rate | Forward multiplier |
|---|---|---|---|
| Input weights & all biases | \(1/\textrm{fan-in}\) (biases \(0\)) | \(\eta\) | \(1\) |
| Hidden matrices (\(n \times n\)) | \(1/\textrm{fan-in} = 1/n\) | \(\eta / m\) | \(1\) |
| Output readout (\(n \times d_{\text{out}}\)) | \(1/n_{\textrm{base}}\) | \(\eta\) | \(1/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 / mclass MuMLP(MLP):
"""The same network under muP, relative to a width-8,192 base."""
def __init__(self, width, base_width=8192, *, rngs):
super().__init__(width, rngs=rngs)
self.m = width / base_width
# Rule 1: output init variance 1/base_width at every width
self.fc_out.kernel[...] *= self.m ** 0.5
def __call__(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):
def label(path, _):
name = jax.tree_util.keystr(path)
return 'hidden' if 'fc_h' in name and 'kernel' in name else 'rest'
tx = optax.multi_transform(
{'hidden': optax.adam(lr / self.m), # Rule 3: hidden LR / m
'rest': optax.adam(lr)},
lambda params: jax.tree_util.tree_map_with_path(label, params))
return nnx.Optimizer(self, tx, wrt=nnx.Param)(Setting base_width=8192 makes MuMLP identical to MLP at the largest width \(n = 8{,}192\), allowing direct comparison with the SP sweep above; in production, base_width is set to the small proxy width and \(m > 1\) scales up to the target model.)
9.9.2.2 The Coordinate Check and Learning-Rate Transfer
To verify a \(\mu\text{P}\) implementation before launching a sweep, the coordinate check (Yang et al. 2022; Dey et al. 2024) takes a single Adam step across widths \(n \in \{128, 256, \ldots, 8192\}\) and measures the mean absolute activation \(\overline{|h_\ell|}\) of each layer via activations and coord_check:
def activations(model, Xb):
with torch.inference_mode():
h1 = F.relu(model.fc_in(Xb))
h2 = F.relu(model.fc_h1(h1))
h3 = F.relu(model.fc_h2(h2))
return [float(h.abs().mean()) for h in (h1, h2, h3, model(Xb))]
def coord_check(arch, widths, lr, seed, num_steps=1):
Xb, Yb = X[:256], Y[:256]
sizes = []
for width in widths:
torch.manual_seed(seed)
model = arch(width).to(device)
optimizer = model.configure_adam(lr)
for _ in range(num_steps):
train_step(model, optimizer, Xb, Yb)
sizes.append(activations(model, Xb))
return list(zip(*sizes))def activations(model, Xb):
h1 = nnx.relu(model.fc_in(Xb))
h2 = nnx.relu(model.fc_h1(h1))
h3 = nnx.relu(model.fc_h2(h2))
return [float(jnp.abs(h).mean()) for h in (h1, h2, h3, model(Xb))]
def coord_check(arch, widths, lr, seed, num_steps=1):
Xb, Yb = X[:256], Y[:256]
sizes = []
for width in widths:
model = arch(width, rngs=nnx.Rngs(seed))
optimizer = model.configure_adam(lr)
for _ in range(num_steps):
train_step(model, optimizer, Xb, Yb)
sizes.append(activations(model, Xb))
return list(zip(*sizes))Running coord_check on the standard-parametrization MLP across seven widths \(n \in \{128, 256, \ldots, 8192\}\) at width \(128\)’s optimal learning rate lr_128 reveals severe activation blow-up with width:
check_widths = [128 * 2 ** k for k in range(7)] # 128 to 8,192
lr_128 = lrs[sp_loss[128].mean(1).argmin()] # SP's best rate at width 128
sp_acts = coord_check(MLP, check_widths, lr_128, seeds[0])
d2l.plot(check_widths, list(sp_acts), 'width', 'mean |activation|',
xscale='log', yscale='log', ylim=[0.05, 1000],
legend=['layer 1', 'layer 2', 'layer 3', 'logits'])check_widths = [128 * 2 ** k for k in range(7)] # 128 to 8,192
lr_128 = lrs[sp_loss[128].mean(1).argmin()] # SP's best rate at width 128
sp_acts = coord_check(MLP, check_widths, lr_128, seeds[0])
d2l.plot(check_widths, list(sp_acts), 'width', 'mean |activation|',
xscale='log', yscale='log', ylim=[0.05, 1000],
legend=['layer 1', 'layer 2', 'layer 3', 'logits'])Running the exact same one-step coord_check on MuMLP at the base-width learning rate lr_base confirms that \(\mu\text{P}\) keeps all three hidden layers and the output logits invariant across widths:
lr_base = lrs[sp_loss[8192].mean(1).argmin()] # Best at the base width
mup_acts = coord_check(MuMLP, check_widths, lr_base, seeds[0])
d2l.plot(check_widths, list(mup_acts), 'width', 'mean |activation|',
xscale='log', yscale='log', ylim=[0.05, 1000],
legend=['layer 1', 'layer 2', 'layer 3', 'logits'])lr_base = lrs[sp_loss[8192].mean(1).argmin()] # Best at the base width
mup_acts = coord_check(MuMLP, check_widths, lr_base, seeds[0])
d2l.plot(check_widths, list(mup_acts), 'width', 'mean |activation|',
xscale='log', yscale='log', ylim=[0.05, 1000],
legend=['layer 1', 'layer 2', 'layer 3', 'logits'])Under SP (MLP), layer \(2\) grows as \(O(n)\), layer \(3\) compounds to \(O(n^2)\), and the output logits explode as \(O(n^3)\) (increasing \(1{,}000\times\) from width \(128\) to width \(8{,}192\) after a single step). Under \(\mu\text{P}\) (MuMLP), every layer’s activation and logit scale remains flat across all seven widths.
Repeating the \(400\)-step learning-rate sweep under \(\mu\text{P}\) confirms that the optimal learning rate aligns across the entire \(64\times\) width range:
mup_loss = sweep(MuMLP, widths[:-1], lrs, seeds)
mup_loss[widths[-1]] = sp_loss[widths[-1]] # At the base width muP is SP
print_optimum(mup_loss, lrs)
plot_sweep(mup_loss, lrs)best lr: 2.4e-04 2.4e-04 1.2e-04 2.4e-04 slope -0.05
mup_loss = sweep(MuMLP, widths[:-1], lrs, seeds)
mup_loss[widths[-1]] = sp_loss[widths[-1]] # At the base width muP is SP
print_optimum(mup_loss, lrs)
plot_sweep(mup_loss, lrs)best lr: 2.4e-04 1.2e-04 2.4e-04 2.4e-04 slope +0.05
Finally, we compare the training loss achieved at width \(8{,}192\) when transferring the learning rate tuned on the narrow width-\(128\) proxy versus tuning directly at width \(8{,}192\) under both SP and \(\mu\text{P}\):
for name, loss in (('SP', sp_loss), ('muP', mup_loss)):
mean = {w: l.mean(1) for w, l in loss.items()}
print(f'{name:3s} best loss per width:',
' '.join(f'{m.min():.3f}' for m in mean.values()))
small, wide = widths[0], widths[-1]
tuned, own = mean[small].argmin(), mean[wide].argmin()
for label, i in ((f'the width-{small} lr', tuned), ('its own lr', own)):
runs = ' '.join(f'{v:.3f}' for v in loss[wide][i])
print(f' width {wide} at {label:16s} {mean[wide][i]:.3f}'
f' (seeds {runs})')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)
for name, loss in (('SP', sp_loss), ('muP', mup_loss)):
mean = {w: l.mean(1) for w, l in loss.items()}
print(f'{name:3s} best loss per width:',
' '.join(f'{m.min():.3f}' for m in mean.values()))
small, wide = widths[0], widths[-1]
tuned, own = mean[small].argmin(), mean[wide].argmin()
for label, i in ((f'the width-{small} lr', tuned), ('its own lr', own)):
runs = ' '.join(f'{v:.3f}' for v in loss[wide][i])
print(f' width {wide} at {label:16s} {mean[wide][i]:.3f}'
f' (seeds {runs})')SP best loss per width: 0.321 0.294 0.260 0.221
width 8192 at the width-128 lr 0.324 (seeds 0.317 0.331)
width 8192 at its own lr 0.221 (seeds 0.221 0.221)
muP best loss per width: 0.324 0.262 0.232 0.221
width 8192 at the width-128 lr 0.221 (seeds 0.221 0.221)
width 8192 at its own lr 0.221 (seeds 0.221 0.221)
Under \(\mu\text{P}\), the log–log slope of \(\eta^\star(n)\) collapses from \(-0.7\) or steeper under SP to near zero (the optimum moves by at most one grid step across the \(64\times\) width range): transferring the learning rate tuned at width \(128\) directly to width \(8{,}192\) incurs \(\le 0.003\) nats of suboptimality (well below seed noise), compared to a \(0.10\text{--}0.15\)-nat penalty under SP.
9.9.3 Extensions to Transformers and Spectral Optimizers
9.9.3.1 \(\mu\text{P}\) Rules for a Transformer
Applying \(\mu\text{P}\) to a Transformer such as TinyLM (Section 9.3.1) with model dimension \(d\) and width multiplier \(m = d / d_{\text{base}}\) follows the exact same fan-in/fan-out classification, with one additional rule for attention logits (Table 9.9.2): because learned query and key vectors align during training, their dot product \(\mathbf{q}^\top\mathbf{k}\) over head dimension \(d_k \propto d\) grows as \(O(d_k)\), requiring attention scaling by \(1/d_k\) (an extra factor of \(1/\sqrt{m}\) relative to standard \(1/\sqrt{d_k}\) scaling (Yang et al. 2022)).
| Component | Scaling reason | \(\mu\text{P}\) rule |
|---|---|---|
| Embeddings, 1D biases, LayerNorm scales/shifts | Fixed fan-in (lookup or elementwise) | Learning rate \(\eta\) |
Internal block matrices (qkv, proj, mlp1, mlp2) |
Both fan-in and fan-out \(\propto d\) | Learning rate \(\eta/m\), init variance \(1/\text{fan-in}\) |
Output readout head |
Fan-in \(\propto d\), fixed vocabulary size \(V\) | Init variance \(1/d_{\text{base}}\), logits \(\times 1/m\), learning rate \(\eta\) |
| Attention dot-product scores | Inner product of aligned \(d_k\)-vectors | Scale scores by \(1/d_k\) (extra factor \(1/\sqrt{m}\)) |
| Residual branches, when the depth \(L\) also grows | \(L\) branch outputs add in the residual stream | Multiply each branch by \(L_{\text{base}}/L\) (Section 9.9.3.3) |
9.9.3.2 The Spectral Scaling Condition and Muon
As Yang et al. (2023) show, all \(\mu\text{P}\) rules can be unified under a single operator-norm principle: for a layer mapping \(\mathbf{h} \in \mathbb{R}^{d_{\text{in}}}\) with \(\|\mathbf{h}\|_2 = \Theta(\sqrt{d_{\text{in}}})\) to \(\mathbf{z} \in \mathbb{R}^{d_{\text{out}}}\) with \(\|\mathbf{z}\|_2 = \Theta(\sqrt{d_{\text{out}}})\), preserving \(\Theta(1)\) entrywise activations and updates requires both the weight matrix \(\mathbf{W}\) and its update \(\Delta\mathbf{W}\) to have spectral norm
\[ \|\Delta\mathbf{W}\|_2 = \Theta\!\left(\sqrt{\frac{d_{\textrm{out}}}{d_{\textrm{in}}}}\right). \tag{9.9.2}\]
For a square \(n \times n\) hidden matrix, Equation 9.9.2 requires \(\|\Delta\mathbf{W}\|_2 = \Theta(1)\). Under Adam, a rank-\(1\) sign update has \(\|\Delta\mathbf{W}\|_2 = \Theta(\eta n)\), requiring \(\eta \propto 1/n\). Under Muon (Section 9.6), the orthogonalized update \(\mathrm{NS}_5(\cdot)\) has unit spectral norm by construction; if scaled by \(\sqrt{d_{\text{out}}/d_{\text{in}}}\) (Bernstein 2025), its learning rate transfers across widths directly with no \(1/m\) correction (whereas the AdamW-matched factor \(0.2\sqrt{\max(d_{\text{out}}, d_{\text{in}})}\) of Section 9.6 has spectral norm \(\Theta(\eta\sqrt{n})\) and therefore scales as \(\eta \propto 1/\sqrt{n}\); Exercise 3).
9.9.3.3 Depth, Weight Decay, and Finite Size
So far we have varied the width alone. A real scale-up also adds layers, and under AdamW the weight decay has to follow whatever is done to the learning rate. Both need a rule of their own.
Consider depth first. In a network of \(L\) residual blocks, the residual stream is the sum of \(L\) branch outputs. If every branch contributes \(\Theta(1)\), the sum grows with \(L\), and so does the effect of one optimizer step, since every block moves the output. The remedy has the same form as the logit multiplier: multiply each residual branch by \((L_{\text{base}}/L)^{\alpha}\). Two exponents have been proposed. With \(\alpha = 1/2\) the branch outputs add like independent random terms, which they are at initialization (Bordelon et al. 2024; Yang et al. 2024). With \(\alpha = 1\) they add like aligned terms, which they become once training has correlated them. This is the argument that gave the readout \(1/n\) and not \(1/\sqrt{n}\). Dey et al. (2025) find that in Transformers only \(\alpha = 1\) keeps every block learning features as \(L\) grows, and that the learning rate then transfers across depth as it does across width.
Weight decay comes next. Under AdamW, the decay timescale \(\tau = 1/(\eta\lambda)\) sets how fast the weights approach their equilibrium norm (Section 9.5). A rule that divides a layer’s learning rate by \(m\) and leaves \(\lambda\) alone makes that layer’s \(\tau\) grow \(m\)-fold, so the wide model is regularized differently from the small one it was tuned on. One consistent choice is to hold \(\tau\) fixed: multiply \(\lambda\) by \(m\) wherever \(\eta\) is divided by \(m\) (Wang and Aitchison 2025).
Finally, all of these rules are exact only in the limit of infinite size. At practical widths the optimum still drifts a little; in our own sweep it moved by one grid step. A transferred learning rate is therefore best used as the center of a narrow sweep at the target size, not as a substitute for one.
9.9.4 Summary
Under standard parametrization (SP), a single Adam step changes the output of a hidden layer with fan-in \(n\) by \(\Theta(\eta n)\), causing the optimal learning rate \(\eta^\star(n)\) to drift downward as the network widens. Maximal Update Parametrization (\(\mu\text{P}\)) scales hidden-matrix learning rates by \(1/m\) (where \(m = n/n_{\text{base}}\)), fixes output-layer initialization variance at \(1/n_{\text{base}}\) while scaling logits by \(1/m\), and scales Transformer attention scores by \(1/d_k\), achieving \(\Theta(1)\) feature updates and zero-shot learning-rate transfer across widths. A one-step coordinate check verifies across a geometric progression of widths that layer activation magnitudes remain flat after an optimizer step. Extending hyperparameter transfer to full scale-ups additionally scales residual branches by \(L_{\text{base}}/L\) with depth and holds the AdamW decay timescale \(\tau = 1/(\eta\lambda)\) constant as layer learning rates vary, providing an asymptotic anchor around which narrow target-scale sweeps can be centered.
9.9.5 Exercises
[code] Diagnosing broken \(\mu\text{P}\) rules with the coordinate check. Set
base_width=128inMuMLPand usecoord_checkatlr_128to test three deliberate bugs one at a time: (a) omitting the \(1/m\) logit multiplier, (b) omitting the \(\eta/m\) hidden learning-rate scaling, and (c) scaling the hidden learning rate by \(\eta/m^2\). Identify which errorscoord_checkcatches immediately and why over-shrinking updates (\(\eta/m^2\)) requires a multi-step loss sweep to detect.[code] Effect of the reference base width. Rerun the \(\mu\text{P}\) sweep with
base_width=128across widths \(\{128, 512, 2048, 8192\}\), verify that the log–log slope of \(\eta^\star(n)\) remains near zero, and identify which constant ratio (input-to-hidden learning-rate ratio vs. initial logit scale) accounts for the loss difference at width \(8{,}192\).Spectral norm condition across layers and optimizers. ● Using Equation 9.9.2, verify that the \(\mu\text{P}\) rules of Table 9.9.1 give input, hidden, and output layers updates of spectral norm \(\Theta(\sqrt{d_{\text{out}}/d_{\text{in}}})\) under a rank-\(1\) Adam step, and derive the width scaling of \(\eta\) required for Muon (Section 9.6) on the four block matrices of
TinyLM.[code] Implementing \(\mu\text{P}\) and the coordinate check on
TinyLM. ● Apply Table 9.9.2 tod2l.TinyLMacrossd_model\(\in \{64, 128, 256, 512, 1024\}\) (num_heads=2,base_width=64) and verify with a one-step coordinate check at \(\eta = 3 \times 10^{-3}\) that all sublayer output and logit magnitudes remain flat with width.