The gradient-descent lesson ended with a diagnosis: it pays for ill-conditioning linearly — ten times worse, ten times the iterations — and wastes most of its motion zig-zagging across ravines. This lesson is the treatment arc: first give the iterate memory (momentum), then give each coordinate its own learning rate (adaptive methods), then combine both and fix the resulting interaction with weight decay (AdamW). By the end, the optimizer line in every modern training script should read as a sequence of deliberate design decisions rather than folklore.
Momentum: the heavy ball
Polyak’s 1964 idea: keep an exponentially-decaying memory of past gradients — a velocity — and move along it:
Two complementary readings:
As physics. These are the discretized equations of a ball with mass rolling on the loss surface with friction . Along the ravine floor, where the gradient points the same way step after step, velocity accumulates: the geometric series gives a terminal speed of — an effective learning rate of , so is a 10× amplifier in consistent directions ( is 100×, which is why cranking without dropping diverges). Across the ravine, where the gradient flips sign each step, successive contributions cancel inside the velocity — the zig-zag is averaged away. One mechanism, both benefits.
As mathematics. On the quadratic, the two-step recurrence has spectral radius minimized at with optimal , giving
The condition number enters through its square root: at , GD needs ~100 iterations per digit, momentum ~10. This is not a constant-factor tweak; it is a different complexity class, and (Nesterov proved) the best possible one for first-order methods.
Nesterov’s variant evaluates the gradient at the lookahead point rather than at — the ball measures the slope where it is about to be, and brakes before overshooting instead of after. Same cost, provably optimal rate on smooth convex problems, and a slightly better-damped trajectory you can see in the race below.
Adaptive methods: a learning rate per coordinate
Momentum still applies one global to every parameter. But real models mix parameters with wildly different gradient scales — embeddings of rare tokens receive sparse, tiny gradients while bias terms receive dense, large ones. The adaptive family normalizes each coordinate by a running estimate of its own gradient magnitude.
RMSProp (Hinton, famously published as a lecture slide) keeps an exponential moving average of squared gradients and divides by its root:
Coordinates with persistently large gradients get their steps shrunk; quiet coordinates get boosted. On a quadratic this is implicit preconditioning — it equalizes the effective curvature across axes, attacking directly rather than tolerating it as momentum does.
Adam = momentum on the first moment + RMSProp on the second + a correction for the zero-initialization of both EMAs:
The bias correction is not a detail: without it, makes the first steps systematically tiny (an EMA warm-starting from zero underestimates by the factor ), and with that shrinkage lingers for a thousand steps. Defaults , , have survived a decade of scrutiny largely intact. A useful invariance to internalize: because appears homogeneously in numerator and denominator, Adam’s step size is insensitive to the overall scale of the gradient — rescale the loss by 100× and the update barely changes, which is much of why Adam is so forgiving to tune.
On the ravine (κ=60): GD zig-zags, momentum flies down the floor, the adaptive pair equalizes the axes and walks straight. On Rosenbrock, the curved valley punishes momentum’s inertia at the turn — watch it swing wide — while RMSProp/Adam corner tightly. On two wells, momentum’s speed is enough to coast through the shallow basin that traps GD from the same start. On the saddle, GD started on the axis stalls to a crawl; the others pass through. Drag starts, sweep η, break things — divergence is part of the syllabus.
AdamW: the weight-decay fix
For SGD, adding L2 regularization to the loss and “weight decay” are the same update. For Adam they are not: an L2 term enters through and gets divided by like everything else, so heavily-updated parameters — precisely the ones you most want to regularize — receive the weakest effective decay. Loshchilov & Hutter’s fix is simply to take decay out of the gradient path:
The empirical gap this closes is why AdamW — not Adam — is the default in every
serious transformer codebase, and why setting weight_decay in Adam-with-L2 mode
silently does less than its name promises.
Choosing, in practice
| Situation | Reach for | Why |
|---|---|---|
| Convex / classical ML (logistic, linear SVM) | SGD or L-BFGS | guarantees apply; adaptivity unneeded |
| CNNs on vision benchmarks | SGD + momentum + cosine schedule | still edges out Adam on final accuracy in many settings |
| Transformers / LLMs, anything with embeddings | AdamW + warmup | heterogeneous gradient scales make per-coordinate rates near-mandatory |
| RL policy gradients | Adam, small | non-stationary objectives punish hand-tuned schedules |
| “It diverges immediately” | lower 10×, add warmup | you are past the local ; curvature is largest at init |
Starting points that respect the theory: SGD+momentum – (effective rate is — remember the 10×), AdamW –, . Every one of these is a starting point for a sweep, not a conclusion — the SGD lesson’s noise-ball logic still sets the endgame, and schedules from that lesson compose with everything here.
One paragraph of honesty about “Adam vs SGD”
Adaptive methods win on trainability and robustness; carefully-tuned SGD+momentum sometimes wins on final generalization, and the literature has gone back and forth on why (Wilson et al. 2017 vs. much subsequent work). The stable takeaway for a practitioner: the gap, where it exists, is small next to the gap between either and a badly-chosen learning rate — tune first, argue metaphysics later.
Exercises
Work these before the next lesson
- Derive the terminal velocity: for a constant gradient , show , and conclude why at fixed eventually violates the gradient-descent lesson’s stability ceiling.
Solution
Worked solutions are part of Premium — unlock all of them for £5/month →
- 4 more exercises — each with a worked solution — are part of Premium. Unlock everything for £5/month →
References
- B. T. Polyak, “Some methods of speeding up the convergence of iteration methods”, 1964 — heavy ball and the √κ rate.
- Y. Nesterov, “A method for solving the convex programming problem with convergence rate O(1/k²)”, 1983.
- G. Goh, “Why Momentum Really Works”, Distill 2017 — the interactive companion to the first half of this lesson.
- T. Tieleman & G. Hinton, RMSProp — Coursera “Neural Networks for Machine Learning”, Lecture 6.5, 2012.
- D. Kingma & J. Ba, “Adam: A Method for Stochastic Optimization”, ICLR 2015.
- I. Loshchilov & F. Hutter, “Decoupled Weight Decay Regularization”, ICLR 2019 — AdamW.
- A. C. Wilson et al., “The Marginal Value of Adaptive Gradient Methods in Machine Learning”, NeurIPS 2017 — the case for tuned SGD; read with its rebuttals.