| Optimizer step | |
|---|---|
| parameters after update | |
| loss on the batch of update | |
| peak learning rate (Zhang et al. write ) | |
| learning rate at update , as set by the schedule | |
| decoupled weight decay coefficient: each update shrinks the weights by times their value | |
| Adam's averaging rates for the gradient and its square (0.9 and 0.95) | |
| batch size: sequences per update in the course, gradient queries per step in the noisy quadratic | |
| training loss function | |
| preconditioner exponent in | |
| Noisy quadratic model | |
| Hessian of the quadratic loss | |
| eigenvalues of the Hessian , the curvatures along its principal directions, | |
| covariance of one gradient query's noise, | |
| noise variance of one gradient query in direction , the diagonal entries of in 's eigenbasis | |
| loss in direction , | |
| heavy-ball momentum coefficient, , | |
| preconditioner of power , applied to the gradient as , with : is plain SGD and the Newton direction | |
| condition number , the ratio of the sharpest to the flattest curvature | |
| Weight norms and Hyperball | |
| a weight matrix | |
| direction of a weight matrix, | |
| Frobenius norm, the root sum of squared entries | |
| weight norm | |
| equilibrium weight norm, where growth from gradient steps balances shrinkage from weight decay | |
| gradient norm at in Lecture 3's toy case; at norm the gradient has norm | |
| Frobenius norm of Adam's update in the noise-dominated model, | |
| , the per-update shrink factor | |
| angular step, | |
| Hyperball's radius , the Frobenius norm of the matrix at initialization, kept for the whole run | |
| the base optimizer's update for a weight matrix (Adam's or Muon's), which Hyperball normalizes to unit Frobenius norm | |
| Constants | |
| curvature of the course's quadratic rule for the excess loss in of ; 0.0074 to 0.0238 across budgets | |
Context. A neural-network training step is SGD: stochastic gradient descent stepping against the current batch gradient plus three additions that matter in practice: batch averaging, a preconditionera positive definite matrix applied to the gradient before the step, , rescaling the step per direction, and momentum. AdamW with running averages of the gradient and its square (rates ): decoupled weight decay acts on directly instead of passing through combines momentum, a diagonal preconditioner, and decoupled weight decay. Lecture 3 of Hashimoto and Kotha's Stanford course CS 312 (Deep Learning Alchemy) examines how batch size interacts with momentum and preconditioning. It also asks what a learning rate means for weights whose scale the loss ignores. Deep-learning optimizers are judged by how quickly they reach a loose solution rather than by asymptotic convergence. Adam's original convergence proof was wrong, and language models never train to convergence. The lecture therefore relies on two compact models that predict real runs: Zhang et al.'s (2019) noisy quadratic model with gradient queries returning plus Gaussian noise whose variance scales as , and Wen et al.'s scale-invariant weight-norm analysis (2025) and Hyperball optimizer (2026).
Takeaways in practice. In a noisy quadratic, every direction approaches a steady-state noise floor proportional to the learning rate divided by the batch size . Momentum and preconditioning speed convergence, but they also raise that floor. Both therefore pay off mainly at large batch; at small batch, tuning erases most of momentum's benefit. For any weight matrix whose output is normalized, the loss sees only the matrix's direction. Decoupled weight decay sets an equilibrium weight norm, and that norm sets how far each step turns the direction, about radians per step for SGD. In practice, tune and jointly along lines of constant . Missing the optimum by a factor of 2 costs 0.007 to 0.009 in loss on d8 at 0.3B tokens or more. When raising batch size at a fixed token budget, scale in proportion to instead of scaling . Late in training, gradient norms of normalized layers climb as the learning rate decays; that climb reflects shrinking weight norms rather than instability. Norm-constrained optimizers like Hyperball make the turning angle directly and produce a cleaner optimal-learning-rate trend across token budgets.
The model organism. The course runs its experiments on d8, an 8-layer, width-512, 8-head Llama-style transformer with a 4,096-token vocabulary, about 35M parameters, and QK-normRMS normalization of each attention head's queries and keys before their dot product. Reading note: Small-scale proxies for large-scale Transformer training instabilities. Each run trains in one pass over fresh data at context length 1,024. The default recipe uses AdamW with peak learning rate , weight decay , Adam's averaging rates for the gradient and its square, here and equal to and , and batch size sequences of 1,024 tokens per update in d8, or gradient queries averaged per step in the noisy quadratic model equal to 64. The default run uses 1% linear warmup, linear decay to zero, and gradient clipping at norm 1. A 614.4M-token run takes about 15 minutes on one H100. Weight decay applies only to weight matrices, never to embeddings, normalization gains, or biases. All d8 measurements below come from the course's assignments and quizzes.
The noisy quadratic model and the noise floor. To see how batch size trades against learning rate, rotate a quadratic loss into the eigenbasis of its Hessian , giving with curvatures the eigenvalues of the Hessian along its principal directions. Suppose each gradient query returns with , so a batch of queries has noise covariance . Zhang et al. assume is diagonal in the same basiswhy: each eigendirection then decouples with a closed-form expected loss; they set , which holds near the data distribution and proves tight for a CNN and moderate for a transformer, with variances . Plain SGD then updates coordinate independently via for standard normal . For , the expected loss after steps splits into a decaying initial term and a steady-state floor:A larger learning rate shrinks the first term faster but raises the floor. A larger batch lowers the floor in proportion. When is small, the floor is roughly and depends only on . Doubling both and holds the floor fixed and finishes in half as many steps, giving linear scaling. That trade breaks once hits the stability boundary 2 and the sharpest direction diverges. Past this critical batchthe batch size beyond which doubling no longer halves the steps to a target loss, because extra samples mostly average noise that is already small (McCandlish et al., 2018). Reading note: Learning-rate schedules and batch size, raising can no longer be paired with a larger , and step savings saturate. In their simulations, Zhang et al. set to match an estimated CNN Hessian spectrum and take , giving condition number .
Momentum raises the floor and helps at large batch. Heavy-ball momentum, and , shifts both the noise floor and the stability barrier. By Zhang et al.'s Theorem 1, direction settles at the steady-state noise floorAt small , this matches plain SGD's floor at the effective learning rate: the plain-SGD step size with the same convergence rate and noise floor as momentum SGD at small . Whenever a direction is overdamped: both recursion roots are real so the iterate approaches the minimum without oscillating; above it, the iterate spirals in, its convergence factor is also about . Total loss is bottlenecked by the flattest direction, which optimal momentum keeps overdamped. At small batch, the noise floor forces a tiny , so momentum behaves like plain SGD with a rescaled learning rate and tuning erases its advantage. At large batch, the floor is low and plain SGD hits the stability wall . Momentum pushes the effective rate past that wall.
Preconditioning speeds noise-free convergence while amplifying flat-direction noise. Under Zhang et al.'s convention, preconditioning by multiplies the gradient by for preconditioner strength: is plain SGD and is the exact Newton step. That step is equivalent to plain SGD on a quadratic with curvatures and noise variances . The condition number : ratio of sharpest to flattest curvature, setting how many steps the flattest direction needs at the largest stable rate shrinks from to , speeding noise-free convergence by up to . Direction 's noise floor becomes . That floor grows with because preconditioning amplifies noise in flat directions, so most of the gain appears once is large enough that the floor no longer bottlenecks training. Zhang et al. test these optimizers on CNNs (MNIST, Fashion-MNIST, and CIFAR-10) and a two-layer transformer on LM1B by plotting steps-to-target against batch size. Momentum matches plain SGD at small batch and extends linear scaling to larger batches. Adam and K-FACKronecker-factored approximate curvature: approximates each layer's curvature as (input-activation covariance times output-gradient covariance), so inversion splits into two small inverses (Martens and Grosse, 2015) push linear scaling further, and K-FAC also saves a small constant factor of steps at small batch. The noisy quadratic simulation reproduces the same ordering in seconds. Exponential moving averaging (EMA) of the iterates lowers the floor without slowing convergence and becomes redundant at large batch.
Momentum on d8: flat at small batch, sharp at large batch. The course tests this prediction on d8 at 614.4M tokens by sweeping from 0 to at , holding each batch size's learning rate and weight decay fixed. At batch 8, final validation loss stays nearly flat across . All values lie within 0.041 of one another, moving from 2.973 at to 2.937 at . At batch 256, the curve turns sharp: loss drops from 3.233 at to 2.970 at , then climbs back to 3.126 at . That pattern is the characteristic momentum shape predicted by the noisy quadratic model.
Scale-invariant weights and the angular step. Consider a weight matrix whose output passes through normalization, such as or queries and keys under QK-norm. Scaling leaves the loss unchanged, so scale invariance: rescaling by any leaves the loss untouched for all . Differentiating in shows that the gradient is orthogonal to the weight, . Differentiating in shows that it scales inversely with norm, . Because the loss depends on only through its unit direction , where is the Frobenius norm, a fixed-size update rotates less when is larger. The angular step: distance the weight direction moves in one update (the turning angle in radians for small steps) measures that per-step change in direction. Without weight decay, every orthogonal gradient step lengthens , so the angular step shrinks outside the schedule's control.
Equilibrium norm and turning angle for SGD. A two-dimensional toy case shows how weight decay stabilizes the angular step. Take SGD with decoupled weight decay, , on a scale-invariant loss. Let Frobenius norm of ; denotes the equilibrium norm where gradient growth balances weight-decay shrinkage be the weight norm and the gradient norm at , so the gradient has norm . Because , Pythagoras' theorem gives the squared-norm recursion. Setting for small solves for the equilibrium:At equilibrium, the angular step is . It depends only on the product .
Equilibrium norm and turning angle for AdamW. Unlike SGD, AdamW keeps its update magnitude fixed regardless of gradient size, and its momentum correlates consecutive updates with . Wen et al. (2025, 2026) analyze this balance in a noise-dominated model where every gradient entry is i.i.d. and Adam's second moment is exact. A matrix then receives updates of Frobenius norm , the Frobenius norm of Adam's update under i.i.d. Gaussian gradients. Set the per-update multiplicative shrinkage factor from decoupled weight decay for the per-update weight-decay factor. Once training has run long enough to forget initialization, the equilibrium norm and angular step satisfyFor small , the norm simplifies to . A numpy simulation of this model at , run for this note, matches both formulas to within 0.3%.
Three predictions of the equilibrium model. First, holding constant fixes the angular step while scaling . Doubling and halving therefore leaves the loss trajectory nearly unchanged while doubling the weight norm. Second, as the schedule lowers late in training, shrinks. Because , the gradient norm climbs like even while the loss keeps falling. Defazio (2025) uses this climb to argue for decaying weight decay alongside the learning rate, setting . Third, relaxes toward by a factor per update, forgetting initialization after a few multiples of updates. At d8's defaults, gives updates. A 614.4M-token run takes 9,375 updates of 65,536 tokens, so d8's norms reach equilibrium within a run (computed here). Weight decay also has effects beyond norm control, such as regularizing the network's Jacobian, which this model leaves aside.
The loss depends mostly on the product . Experiments confirm both parts of the scaling prediction. In the Hyperball paper, two AdamW runs share : one uses and the other uses . Both trace nearly identical training-loss curves, while the second run's query and key norms sit roughly twice as high as the first's. On d8, fitting a local quadratic in across 3-by-3 grids at four budgets from 153.6M to 1.2288B tokens reveals long valleys along lines of constant . When the ratio sits at its optimum, excess validation loss over the best cell followsThe fitted curvature fitted curvature of in : 0.0238 at 153.6M tokens, 0.0084 and 0.0092 at the middle budgets, and 0.0074 at 1.2288B tokens falls from 0.0238 at 153.6M tokens to 0.0074 at 1.2288B tokens. Points away from the optimal ratio scatter slightly above this curve. As the token budget grows, the optimal product falls cleanly along a straight line on log-log axes.
Larger batches call for larger weight decay. Raising batch size at a fixed token budget cuts the number of updates in proportion. If per update stays fixed, the norm's relaxation time eats up a larger share of the run. On d8, power laws fitted over to 64 compare two ways to compensate: hold and scale with , or hold and scale with . Extrapolated to and 256, the weight-decay rule lands within 0.003 of the best grid point at both batches. The learning-rate rule misses by 0.009 at 128 and by 0.130 at 256 because the optimal learning rate stops growing at large batch. As Lecture 3 summarizes, weight decay controls the effective learning rate in one-pass training, and letting that rate drift uncontrolled is often not ideal.
def hyperball_step(W, u, lr, R):\n # W: weight matrix, u: base optimizer's update (Adam or Muon)\n # R: Frobenius norm of W at initialization\n u_hat = u / u.norm() # unit Frobenius norm\n W_trial = W - lr * R * u_hat # step of length lr * R\n return R * W_trial / W_trial.norm() # back onto the sphere of radius RTo first order, turns by radians per step regardless of matrix shape, with no weight decay. Wen et al. apply Hyperball to attention and MLP matrices, leaving embeddings, normalization gains, and other scale-sensitive parameters on Adam. For a matrix that reads a normalized input, fixing its norm removes no functions. The post-normalization gain absorbs any scale because is invariant under .Hyperball in practice: token savings and transfer. On 1.2B-parameter Qwen3-style models with QK-norm, Muon with Hyperball reaches losses that AdamW needs 20 to 30% more tokens to match, compared with about 10% for Muon with weight decay. Those runs span one to eight times the Chinchilla-optimal token count (about 20 tokens per parameter). The advantage widens with training length, as Hyperball starts slightly behind and overtakes during learning-rate decay. Hyperball also transfers better across shape on a hybrid-normalization variant trained for 10B tokens per run. Across depths 4 to 512 at width 128 and widths 128 to 2,048 at depth 4, the optimal learning rate drifts by about 1.4 times for Adam and Muon with Hyperball. Across depth, it drifts by about 3 times for AdamW and 4 times for Muon with weight decay. On d8, a sweep from 0.15B to 4.9B tokens compares AdamW against Hyperball (weight decay off, with Adam on embeddings and gains at ). Hyperball's optimal peak learning rate falls smoothly along a near-straight log-log line, whereas AdamW's at rises up to 1.2B tokens and then falls (read off a plot). Unlike AdamW's, Hyperball's line can roughly be extended to longer horizons.
Caveats. The noisy quadratic model assumes a quadratic loss with noise aligned to curvature. It predicts batch-size trade-offs well, but high-learning-rate full-batch gradient descent on real networks produces noise-like loss curves that no quadratic explains, a topic taken up later in the course. The weight-norm equilibrium formulas assume isotropicequal variance in every coordinate, as in the i.i.d. gradient entries of the noise-dominated model above, noise-dominated gradients, constant hyperparameters over a long history, and exact scale invariance. Real layers are only approximately scale-invariant, the schedule moves the equilibrium over training, and short or large-batch runs may never reach it. The d8 measurements come from one 35M-parameter model, mostly on a single seed, and the fitted curvature varies threefold across token budgets. Hyperball's width-transfer claim also held less cleanly on d8, where its optimal learning rate still fell with width under the baseline parametrization. For Muon, the overlap between successive updates follows a matrix-sign kernel for independent standard Gaussian and polar factor ; lag has and bounded by at lag . That kernel changes the angular step by a constant factor while keeping the same scaling for small .
Terms
- Noisy quadratic model
- loss , gradients with , diagonal in 's eigenbasis
- Noise floor
- per direction: grows with , falls with
- Critical batch
- batch size past which doubling the batch no longer roughly halves the steps to a target
- Momentum's effective learning rate
- : momentum SGD matches SGD at this rate when is small
- Preconditioning
- condition number , noise floor larger for larger
- Scale invariance
- ; then and
- Angular step
- ; at equilibrium for SGD, for AdamW
- Equilibrium norm (AdamW)
- ; reached after a few multiples of updates
- Product rule
- excess loss , to on d8
- Batch scaling
- at a fixed token budget, scale the weight decay with the batch size; the optimal learning rate stops growing
- Hyperball
- , , no weight decay
Sources
Lecture 3, “Optimization 1: Anatomy of an optimizer, the noisy quadratic model, norms and weight decay” (Oct 1, 2026), of Stanford CS 312 Deep Learning Alchemy, Fall 2026. Taught by Tatsunori Hashimoto and Suhas Kotha; course staff Kaiyue Wen and Tristan Thrush (CAs).
Course site Lecture slides Online quiz Quiz answers Assignment Assignment code
The lessons, experiments, figures and quiz problems in this note are the course's, shown here with the instructors' permission.
- Tatsunori Hashimoto and Suhas Kotha. CS 312 Deep Learning Alchemy, Lecture 3: Optimization 1, anatomy of an optimizer, the noisy quadratic model, norms and weight decay. Stanford, Fall 2026.
- Guodong Zhang, Lala Li, Zachary Nado, James Martens, Sushant Sachdeva, George E. Dahl, Christopher J. Shallue, and Roger Grosse. Which Algorithmic Choices Matter at Which Batch Sizes? Insights From a Noisy Quadratic Model. NeurIPS, 2019.
- Kaiyue Wen, Xingyu Dang, Kaifeng Lyu, Tengyu Ma, and Percy Liang. Fantastic Pretraining Optimizers and Where to Find Them 2.2: The Hitchhiker's Guide to the Weight Norm Theory. Blog post, 2025.
- Kaiyue Wen, Xingyu Dang, Kaifeng Lyu, Tengyu Ma, and Percy Liang. Fantastic Pretraining Optimizers and Where to Find Them II: Hyperball Optimization. arXiv preprint, 2026.
- Tatsunori Hashimoto and Suhas Kotha. CS 312 Deep Learning Alchemy, Assignment 2: Hyperparameter Scaling, and Quiz 2 answer slides. Stanford, Fall 2026.
- Sam McCandlish, Jared Kaplan, Dario Amodei, and OpenAI Dota Team. An Empirical Model of Large-Batch Training. arXiv preprint, 2018.
- James Martens and Roger Grosse. Optimizing Neural Networks with Kronecker-factored Approximate Curvature. International Conference on Machine Learning, 2015.
Connected notes
SGD's expected loss is the gradient-descent loss plus a term from noise injected while the loss is still of order one, so SGD noise matters only when the kernel decays more slowly than the gradient-descent loss.
- Softmax attention as a sum of RNNsEfficient sequence models · Fixed scales for stable training
Dividing the numerator of softmax attention by its L2 norm, which fixes the output's length, follows the softmax loss curve, while dividing by the sequence length behind a gate, with scores clamped at 5 and gradients clipped, still gives loss spikes.
- Transformers Learn In-Context by Gradient DescentIn-context learning · Hyperparameters set what the loss leaves free
In one-layer linear self-attention, the loss depends only on the product and leaves the scale split between the label-value scalar and the key-query matrix free; gradient flow conserves , which pins the limit on the hyperbola of equivalent global minima.
- Maximal update parametrizationLazy training and feature learning · Predicting large runs from small ones
Under P the optimal learning rate, initialization scale and multipliers are nearly stable in width, so they can be tuned on a small proxy and copied, and a 40M proxy beat the published 6.7B GPT-3 at a tuning cost of 7% of its pretraining cost.