3.2.3 · D2Training Deep Networks

Visual walkthrough — Momentum and Nesterov momentum

2,217 words10 min readBack to topic

We build on the idea of plain gradient descent and the smoothing trick of an exponentially weighted moving average. Everything else we grow from scratch.


Step 1 — The hill, the ball, and the arrow that points downhill

WHAT. Picture a landscape. The height at each spot is the loss — call it . Low ground = good (small loss). We stand at a location described by a number (or a list of numbers) called — the parameters of our model.

WHY. Before any update rule, we need a single honest arrow that says "downhill is that way." That arrow is the gradient, written . Read it as: "the direction of steepest increase of the loss." So its opposite, , points downhill.

PICTURE. In the figure the gray curves are contour lines (lines of equal height, like a topographic map). The blue arrow at the ball is : the steepest-descent direction, perpendicular to the contour it sits on.

Figure — Momentum and Nesterov momentum

The plain-GD rule is just "step downhill by ":

The subscript is just a step counter: is the start, after one step, and so on.


Step 2 — Why one arrow is not enough: the zig-zag valley

WHAT. Squash the bowl so it is a narrow valley: very steep across, very gentle along. This is the ill-conditioned case the parent note warns about.

WHY. In a narrow valley the downhill arrow mostly points across the valley (into the steep wall), only a little along it (toward the true minimum). Plain GD must keep tiny or it launches up the opposite wall — so it zig-zags and crawls.

PICTURE. The orange path bounces wall-to-wall. Notice the key fact: the across-valley part of the arrow keeps flipping sign every step (left, right, left, right), while the along-valley part always points the same way (toward the minimum).

Figure — Momentum and Nesterov momentum

This is exactly the pathology that also motivates RMSProp and Adam Optimizer — but momentum fixes it the simplest way: by remembering.


Step 3 — Memory as a running average: the velocity

WHAT. Keep a running, fading memory of the arrows we have seen. Call it the velocity . We start with no memory at all, (an empty running total), and each step we forget a bit of the old velocity and add the new gradient.

WHY. "Forget a fraction, add the new" is precisely an exponentially weighted moving average. The consistent (along-valley) direction survives because its contributions all point the same way; the flipping (across-valley) direction shrinks because plus and minus cancel inside the sum. That is the "add up vs cancel" wish of Step 2, made into an equation.

Here (beta) is the momentum coefficient — physically, how heavy the ball is. means no memory (back to plain GD); near means a long memory.

PICTURE. The stacked, fading arrows show the unrolled sum. The freshest arrow is full-strength; each older one is dimmer by a factor .

Figure — Momentum and Nesterov momentum

Step 4 — Step along the memory, not the raw arrow

WHAT. Replace the raw gradient in the plain-GD rule with the velocity .

WHY. We already argued is the good direction (signal amplified, noise cancelled), and points uphill, so is downhill. Walk along .

PICTURE. Two paths on the same valley: gray = plain GD (still zig-zagging), green = momentum (smooth, hugging the valley floor). The green ball's step is longer along the valley and shorter across it — exactly the selectivity we wanted.

Figure — Momentum and Nesterov momentum

Step 5 — How big does the "consistent" speed-up get?

WHAT. Ask: if the gradient were a constant forever (a perfectly steady slope), what velocity do we settle at? Give that constant gradient a name: let So is nothing new — it is just the gradient in the special case where it never changes, written as a short symbol so the algebra is readable.

WHY. This measures the payoff of memory in the best case — a purely consistent direction.

Starting from , if every step, the recursion climbs toward a steady value satisfying , so Term-by-term: the is a geometric-series gain. With that gain is — a 10× acceleration along steady directions.

PICTURE. A curve of climbing from and levelling off at , with the dashed asymptote marked for .

Figure — Momentum and Nesterov momentum

Step 6 — The degenerate case: pure oscillation

WHAT. Take a coordinate whose gradient alternates perfectly: (crossing a symmetric valley). Watch with , again starting from .

WHY. This is the worst input for plain GD and the case momentum is built to tame — the edge case must be shown, not assumed.

PICTURE. The raw gradient (orange spikes ) versus the velocity (green, hugging zero). The green curve stays small and bounded — the wild swings largely cancel, so the parameter barely wiggles.

Figure — Momentum and Nesterov momentum

Step 7 — Nesterov: look before you leap

WHAT. Classical momentum measures the arrow where it stands, then takes its full step . Nesterov first peeks at the spot that the momentum part of that step would carry it to, and measures the arrow there.

WHY. Before committing, the ball is going to move; the momentum-only part of the classical step displaces by (that is, times , the carried-over memory). Measuring the slope at the current spot is stale; measuring it at that anticipated spot gives fresher information, so momentum can brake before the curve instead of after it.

Term-by-term: (theta-tilde) is the look-ahead point; the only change from classical is that the gradient is read at instead of at .

PICTURE. From the ball, a faded arrow shows the momentum-only peek to ; the red arrow is the gradient measured there; the green arrow is the resulting corrected step, which lands nearer the minimum than the classical step (shown gray).

Figure — Momentum and Nesterov momentum

The one-picture summary

Everything above compressed: the narrow valley, plain GD's gray zig-zag, momentum's smooth green sweep, and Nesterov's peek-then-jump correction — all on one map.

Figure — Momentum and Nesterov momentum
Recall Feynman retelling — the whole walkthrough in plain words

We stood on a hill and drew one arrow pointing downhill (Step 1). In a narrow valley that single arrow was useless — it made us bounce off the walls while barely crawling toward the bottom (Step 2). So we gave the ball a memory, starting empty (): keep a fading average of every uphill arrow we've seen (Step 3), and walk along the opposite of that memory, , instead of the newest arrow (Step 4). Because arrows that agree pile up and arrows that flip cancel, we sped up along the valley by up to ten times (Step 5) while our sideways bouncing shrank to almost nothing (Step 6). Finally, we made a smarter ball that first peeks where its momentum is about to fling it, checks the slope there, and brakes early if it's about to overshoot (Step 7). That peeking ball is Nesterov, and it reaches the bottom fastest and smoothest of all.


Quick self-check