Visual explainer
Momentum
A decaying gradient buffer carries history into the next update. Follow computed steps through a narrow valley, overshoot and instability.
Momentum carries a decaying buffer of past gradients into each parameter update. That history can reinforce a consistent direction, but it can also keep weights moving after the current gradient reaches zero.
Our synthetic loss is , so the gradient is . The contour ellipses show equal losses 7 and 2 using equal spatial units on both axes. Start at with learning rate and no momentum. Four gradient evaluations produce , , and .
The steep y direction keeps reversing while x contracts by 0.82 per update. These are full gradients of a known quadratic; no sampling noise is needed to create the zigzag. The white dot is the start and the ring is the fourth endpoint.
Weight Older Gradients Less
Use the gradient-buffer convention, with buffer :
The buffer has gradient units; the learning rate acts after accumulation. This matches PyTorch SGD with momentum, no dampening, no weight decay and no Nesterov lookahead. Other conventions absorb the learning rate or a factor into their state, so compare definitions before copying settings.
At , gradients of ages 0, 1, 2 and 3 have coefficients 1, 0.5, 0.25 and 0.125. The bars show those coefficients, not the actual signed gradients. Older history continues decaying beyond the four displayed ages; there is no hard four-step cutoff.
Combine Memory And New Slope
For an isolated scalar example, change to and an existing buffer of 1. Retain , add the new gradient 0.4 and obtain 1.3. The first two arrows join head to tail; dashed projections align the total below. All three use the same length scale.
The buffer is not the displacement. At rate 0.1, the parameter moves by , rather than by −1.3. This warm-buffer example is separate from the zero-start valley trajectory.
Opposite Pushes Leave A Residual
Return to . Gradients +0.8 then −0.8, starting from an empty buffer, produce buffers +0.8 then . The drawing adds the retained +0.4 to the fresh −0.8. Because the older push decays first, their contributions are unequal.
Consistent gradients +0.3 then +0.3 instead produce 0.3 then 0.45. Momentum can reduce the relative effect of alternating signals while accumulating persistent ones; exact sideways cancellation and universal smoothing do not follow from this example.
Compare Equal Gradient Budgets
Return to the original two-dimensional quadratic, start , rate 0.18 and zero buffer. Plain descent is the case. With , the four endpoints are , , and . The two panels share parameter scales; circles identify plain descent and the diamond identifies momentum's fourth endpoint.
After four gradient evaluations, plain loss is about 1.24769 and momentum loss about 0.06742. This is a result of these stated settings, not a general speedup claim. Momentum's loss actually rises from about 1.01638 at update two to 1.39985 at update three. A better eventual endpoint does not imply every intermediate update improves loss.
Compare Memory Decay
Isolate one unit gradient followed by zero gradients. Its remaining contribution after age is . After four updates, retains 0.0625 while retains 0.6561. The dashed ring trace and solid diamond trace share a zero-to-one scale.
A larger factor preserves history longer. It also changes accumulated magnitude under persistent gradients: the unnormalized buffer approaches for a constant gradient . Rate and momentum therefore interact. No factor is a universal optimum.
Zero Slope Can Still Move
Switch explicitly to , rate 0.5, , and empty buffer. Updates give and . The weight reaches the minimum, but its buffer is still 2.
Now the gradient is zero, so the next buffer is 1 and the next weight is −0.5. The arrow joins the minimum to a point at loss 0.125. The curve shows loss against weight, not the parameter-space motion of a physical ball. Zero gradient alone does not stop this optimizer.
Preserve The Optimizer State
At that same weight zero, retaining buffer 2 produces the −0.5 endpoint. Resetting the buffer to zero instead leaves the weight at zero; the concentric circles show no displacement. Both lanes use the same weight ruler.
This explains why restoring only model weights need not resume the same training trajectory. Restore optimizer state when continuity is intended. The illustration is a controlled state comparison, not advice to discard momentum at every apparent minimum.
Scale The Next Displacement
For another scalar state on , hold , old buffer 2 and . Its gradient is 1 and its new buffer is 2 for either rate. Rates 0.1 and 0.2 produce endpoints 0.8 and 0.6. The longer arrow doubles the parameter displacement while keeping the newly computed buffer fixed.
Future gradients generally differ after those endpoints. The comparison concerns one update, not a claim that entire trajectories scale linearly with the learning rate.
Where It Breaks
Keep the one-dimensional loss and , but restart at , buffer zero and rate 3.5. The weights become . The vertical axis is weight, and the horizontal axis is update count. The growing alternating excursions produce losses .
This is instability, beyond the temporary overshoot shown earlier. Momentum cannot rescue an arbitrarily oversized step. Choosing rate and decay factor requires evidence for the actual objective; a smooth-looking path or a remembered direction does not guarantee convergence.
The Quick Version
- Curvature differences can cause plain descent to zigzag.
- Older gradients enter with exponentially decaying coefficients.
- Buffer magnitude differs from parameter displacement.
- Opposite gradients need not cancel under decay.
- Compare optimizers using the same gradient budget.
- Larger decay factors preserve contributions longer.
- Zero gradient can coexist with continuing motion.
- Buffer resets alter the resumed trajectory.
- Learning rate scales the next buffered displacement.
- Oversized rates can cause growing oscillations.