3.3 — Momentum and Nesterov accelerated gradient
Goal: Derive the momentum update, see why it accelerates in valleys and damps oscillations, then upgrade to Nesterov's look-ahead variant.
1. Why this session exists
Plain SGD treats every gradient as a fresh truth: . If the loss surface is an elongated valley — large curvature in some directions, small in others — SGD oscillates across the steep walls and crawls down the gentle floor. The fix is one of the oldest ideas in numerical optimisation: don't move along the instantaneous gradient, move along an average of recent gradients.
This is momentum. It uses the EMA of §3.2 directly. Nesterov's variant adds one cosmetic-looking but provably better twist: evaluate the gradient at the look-ahead point.
2. The classical momentum update
Maintain a velocity , initialised to . At each step:
This is the EMA of §3.2 applied to the gradient, followed by a step in . Typical , so averages the last gradients.
3. Why this helps: the elongated-valley intuition
Consider the quadratic with — a long, narrow valley along the axis. The gradient is .
Plain SGD. Step is . To make progress along the slow direction (), has to be large. But large in the fast direction () overshoots: flips sign if , oscillating. For stable progress in , ; in , the effective rate is then — tiny. The condition number caps how fast SGD can move.
With momentum. Along the gradient alternates sign on consecutive steps (because of the oscillation). The EMA averages those out — successive contributions cancel. Along the gradient has consistent sign, so the EMA accumulates. Net effect: the optimiser damps motion across the steep walls and accelerates along the slow floor.
Quantitatively (Polyak, 1964; proof on a quadratic)[1], the optimal momentum coefficient is
and the convergence rate improves from (plain GD) to (momentum). A square-root speedup in condition number. For (entirely realistic for deep nets), that is a acceleration on the worst directions.[3, 4]
4. The damped-oscillator analogy
Polyak called this method heavy-ball. The update
(the un-normalised form, after substituting ) reads like the discretisation of the second-order ODE
i.e. a ball with mass rolling on the loss surface, subject to friction . The mass smooths short-term gradient fluctuations (high curvature directions); friction prevents endless oscillation. The discrete coefficients correspond to a time-step and mass/friction ratio.
For Luan: this is the same kind of damped-oscillator analysis you do in classical mechanics. The "tuning" of is the same as picking a critically-damped friction in a mass-spring system — you want enough damping to avoid ringing but not so much that the ball gets stuck.
5. Nesterov accelerated gradient
Nesterov (1983)[2] noticed: if we are about to move to anyway (because of momentum), then the next gradient we care about is the one there, not the one at . Evaluate the gradient at the look-ahead point.
The gradient is evaluated after taking a "momentum-only" partial step. Intuition: it's the difference between driving toward a wall and braking after you hit it versus seeing the wall coming and starting to brake earlier. The correction is small per step but compounds.
For convex smooth problems, Nesterov's method achieves the optimal rate for first-order methods — provably faster than plain GD's on the same class. Deep nets aren't convex, but Nesterov still tends to outperform classical momentum on many problems and is the default in some frameworks (torch.optim.SGD(nesterov=True)).
6. Implementation note: the "look-ahead trick"
The form in §5 is awkward to implement because is not stored. A standard reparametrisation (Sutskever et al., 2013) keeps the iterate equal to at all times, so the gradient is always evaluated at the iterate. Define . Then the update can be rewritten as
This is what most deep-learning frameworks actually compute. No need to remember the previous — the bookkeeping lives entirely in .
7. What momentum buys in deep learning
Three things, in practice.
(a) Better conditioning for free. Deep-net Hessians are notoriously ill-conditioned. Momentum's rate is a real win.
(b) Variance reduction in mini-batch noise. The EMA averages out short-scale mini-batch noise (§3.1), so the optimiser sees a smoother trajectory than the raw gradient stream. This is one of the reasons momentum + SGD is competitive with adaptive methods on vision tasks.
(c) Cheap. One extra vector of memory (the same shape as ). One extra FMA per parameter per step. Negligible compared to the forward/backward cost.
Modern LLMs use Adam (§3.5), which is momentum + an adaptive per-parameter scale. Vision models often still use plain SGD with momentum because it generalises slightly better empirically. Both stories are real.
8. Takeaways
- Momentum is just an EMA of gradients used as the descent direction.
- On an elongated valley, it damps oscillations in steep directions and accumulates motion in shallow ones.
- Optimal convergence rate on quadratics: vs for GD — a square-root improvement in condition number.
- Nesterov's look-ahead variant evaluates the gradient at ; the same EMA but on the look-ahead point.
- Implementation: PyTorch's
SGD(momentum=β, nesterov=True)ships both.
(a) On with , , simulate 50 steps of plain GD with from . Then redo with momentum, . Compare the trajectories.
(b) Derive Polyak's optimal rate for momentum on a 1-D quadratic by writing the update as a linear recurrence on , solving the characteristic polynomial, and finding the choice of that minimises the spectral radius.
(c) Show that classical momentum and the un-normalised form , are equivalent up to a learning-rate rescaling. What is the relation between the two LRs?
(d) Nesterov vs classical: on a strongly convex quadratic, both have rate . For , what is the asymptotic improvement of Nesterov over momentum? (Hint: rate with a different constant .)
References
- [1]
Polyak, B. T. (1964). "Some methods of speeding up the convergence of iteration methods". USSR Comp. Math., 4(5), 1–17. — Heavy-ball momentum (3.3).
↩ - [2]
Nesterov, Y. (1983). "A method for solving the convex programming problem with convergence rate ". Soviet Math. Dokl., 27, 372–376. — Nesterov accelerated gradient (3.3).
↩ - [3]
Rae, J. W., Borgeaud, S., Cai, T., et al. (2021). "Scaling language models: Methods, analysis & insights from training Gopher" (MassiveText). arXiv:2112.11446 — Heuristic data-filtering rules (7.1 §3.3).
↩ - [4]
Narayanan, D., Harlap, A., Phanishayee, A., et al. (2019). "PipeDream: Generalized pipeline parallelism for DNN training". arXiv:1806.03377 — 1F1B pipeline schedule (7.9 §3.3).
↩