Search

Search papers and lessons

Momentum

Level 2 · 7 min read

Momentum keeps a running velocity of past gradients, so gradient descent builds speed along consistent directions and damps zigzagging across narrow valleys.

On this page

  • Colour = topic mix
  • Calculus
  • Optimizers
  • Probability
  • Linear algebra
  • Losses & regularization
  • Discrete math
  • Sign in to see your progress

TL;DR

Plain gradient descent steps directly downhill from where it stands, so it forgets everything it learned one step earlier. Momentum keeps a velocity: each step adds the new gradient to a decaying sum of past gradients and moves along that sum. Directions that keep agreeing gain speed, and directions that flip back and forth cancel out.

Where you'll see it: inside almost every neural network optimizer, usually as the first moment term of Adam or as the momentum setting of SGD in deep learning frameworks.

Intuition

A ball rolling downhill

Picture a ball rolling over a hilly landscape. Gradient descent is a ball with no mass: wherever the slope pushes it, it moves exactly that far and stops. A real ball has inertia. It keeps rolling in the direction it was going, and a small bump does not stop it. That inertia is momentum.

The gain is largest in badly shaped landscapes. Imagine a long, narrow valley that slopes gently towards its end but steeply across its width. Plain gradient descent points mostly across the valley, so it zigzags from wall to wall and crawls along the floor. The across-valley gradients point in alternating directions and cancel in the velocity sum, while the along-valley gradients all agree and add up. The ball therefore speeds up down the valley and stops bouncing off the walls.

This is why momentum was adopted so widely. Neural network loss surfaces have many such ravines, and an optimizer that zigzags wastes steps.

flowchart LR
  A[Current gradient] --> C[Velocity: decayed old velocity plus new gradient]
  B[Previous velocity] --> C
  C --> D[Move parameters by learning rate times velocity]

The math

Update rule

Let θt\theta_t be the parameters at step tt, η>0\eta \gt 0 the learning rate, β∈[0,1)\beta \in [0, 1) the momentum coefficient (commonly 0.9), and ∇L(θ)\nabla L(\theta) the gradient of the loss. The classical momentum update is

vt=βvt−1+∇L(θt−1),θt=θt−1−η vt,\begin{aligned} \mathbf{v}_t &= \beta \mathbf{v}_{t-1} + \nabla L(\theta_{t-1}), \\ \theta_t &= \theta_{t-1} - \eta \, \mathbf{v}_t, \end{aligned}

with v0=0\mathbf{v}_0 = \mathbf{0}. The velocity vt\mathbf{v}_t is a sum of past gradients, each multiplied by a power of β\beta:

vt=∑k=0t−1βk∇L(θt−1−k).\mathbf{v}_t = \sum_{k=0}^{t-1} \beta^{k} \nabla L(\theta_{t-1-k}).

So β\beta controls memory. A gradient kk steps old still counts, weighted by βk\beta^k. Setting β=0\beta = 0 recovers plain gradient descent.

Relation to an exponential moving average

If you rescale the velocity as mt=(1−β)vt\mathbf{m}_t = (1 - \beta)\mathbf{v}_t, the update becomes mt=βmt−1+(1−β)∇L(θt−1)\mathbf{m}_t = \beta \mathbf{m}_{t-1} + (1 - \beta)\nabla L(\theta_{t-1}). Each mt\mathbf{m}_t is then an exponential moving average of the gradients. Many textbooks write momentum in this form, and Adam uses the same averaging for its first moment. The two forms differ only by a rescaling of the learning rate.

Effective step size

If the gradient stays at a constant value gg, the velocity grows towards

lim⁡t→∞vt=g1−β.\lim_{t \to \infty} \mathbf{v}_t = \frac{g}{1 - \beta}.

With β=0.9\beta = 0.9 the step is ten times as large as plain gradient descent in a consistent direction. That is the speed-up, and it is also the reason the learning rate often has to be reduced when momentum is turned on.

Worked examples

Example
One dimension, two methods

Minimise f(θ)=θ2f(\theta) = \theta^2, so ∇f(θ)=2θ\nabla f(\theta) = 2\theta. Start at θ0=1\theta_0 = 1 with learning rate η=0.1\eta = 0.1.

Plain gradient descent, θt=θt−1−0.1⋅2θt−1\theta_t = \theta_{t-1} - 0.1 \cdot 2\theta_{t-1}:

  1. θ1=1−0.2=0.800\theta_1 = 1 - 0.2 = 0.800
  2. θ2=0.800−0.160=0.640\theta_2 = 0.800 - 0.160 = 0.640
  3. θ3=0.640−0.128=0.512\theta_3 = 0.640 - 0.128 = 0.512

Momentum with β=0.9\beta = 0.9, v0=0\mathbf{v}_0 = 0:

  1. Gradient 22. v1=0.9⋅0+2=2v_1 = 0.9 \cdot 0 + 2 = 2. θ1=1−0.1⋅2=0.800\theta_1 = 1 - 0.1 \cdot 2 = 0.800.
  2. Gradient 1.61.6. v2=0.9⋅2+1.6=3.400v_2 = 0.9 \cdot 2 + 1.6 = 3.400. θ2=0.800−0.340=0.460\theta_2 = 0.800 - 0.340 = 0.460.
  3. Gradient 0.920.92. v3=0.9⋅3.4+0.92=3.980v_3 = 0.9 \cdot 3.4 + 0.92 = 3.980. θ3=0.460−0.398=0.062\theta_3 = 0.460 - 0.398 = 0.062.

Interpretation: after three steps plain descent is at 0.512, while momentum is at 0.062, closer to the minimum at 0. Both start with the same first step, and momentum pulls ahead because every gradient so far points the same way, so the velocity keeps growing.

Example
Velocity under a constant gradient

Suppose the gradient is a constant g=1g = 1 at every step, with β=0.9\beta = 0.9 and v0=0\mathbf{v}_0 = 0.

  1. v1=0.9⋅0+1=1.000v_1 = 0.9 \cdot 0 + 1 = 1.000
  2. v2=0.9⋅1.000+1=1.900v_2 = 0.9 \cdot 1.000 + 1 = 1.900
  3. v3=0.9⋅1.900+1=2.710v_3 = 0.9 \cdot 1.900 + 1 = 2.710
  4. v4=0.9⋅2.710+1=3.439v_4 = 0.9 \cdot 2.710 + 1 = 3.439

The sequence climbs towards g/(1−β)=1/0.1=10g / (1 - \beta) = 1 / 0.1 = 10, and it takes roughly 20 to 30 steps to get most of the way there. Interpretation: the optimizer's step grows smoothly to ten times the plain step as long as the direction stays the same.

Tradeoffs and failure modes

Momentum is cheap, since it stores one extra vector per parameter, and it usually converges faster on ravines. It has failure modes too.

SituationProblemBetter choice
High β\beta with a large learning rateThe ball overshoots the minimum and oscillates, sometimes divergingLower η\eta, or use a smaller β\beta
Noisy stochastic gradientsMomentum smooths noise but can also carry a bad estimate for many stepsA larger batch size, or Adam's adaptive scaling
Narrow minima near the end of trainingLeftover velocity keeps the iterate moving past the minimum, so the loss oscillates before settlingLearning rate decay, or a smaller β\beta late in training
Parameters with very different scalesOne global velocity treats all coordinates alikePer-parameter scaling, as in [[adam-optimizer

Nesterov momentum is a common variant. It computes the gradient at the point the velocity is about to carry the parameters to, rather than at the current point, which corrects overshoot earlier. In practice the two perform similarly in deep learning.

History

Boris Polyak introduced the heavy ball method in 1964 as a way to speed up iterative methods for solving equations, using a term proportional to the previous step. Yurii Nesterov's 1983 accelerated gradient method gave a provably faster rate for convex problems, and its lookahead form became known as Nesterov momentum.

For neural networks the decisive study was Sutskever, Martens, Dahl and Hinton's 2013 paper on initialization and momentum in deep learning. They showed that carefully tuned momentum let deep networks train from scratch with first-order methods, which were then the standard option. Momentum has been part of nearly every training recipe since, and it is the ancestor of the adaptive optimizers that dominate today.

Check yourself

QuestionPlain gradient descent and momentum both start at the same point with the same learning rate. Why can momentum make progress when the gradient is almost zero in the current step?Show answer

The velocity is a decaying sum of past gradients, so the previous large gradients still move the parameters even when the current gradient is tiny. This is how momentum crosses flat regions and saddle points.

QuestionWith β=0.5\beta = 0.5, what fraction of a gradient from three steps ago still contributes to the current velocity, relative to the newest gradient?Show answer

The contribution of a gradient kk steps old is weighted by βk\beta^k. Three steps old gives 0.53=0.1250.5^3 = 0.125, or one eighth of the newest gradient's weight.

QuestionFor β=0.99\beta = 0.99 and a constant gradient g=2g = 2, what is the limiting velocity, and why might a learning rate that worked with β=0.9\beta = 0.9 now be too large?Show answer

The limit is g/(1−β)=2/0.01=200g / (1 - \beta) = 2 / 0.01 = 200, which is 100 times the plain gradient, and ten times the β=0.9\beta = 0.9 case. The step size scales with 1/(1−β)1/(1 - \beta), so the learning rate usually has to shrink as β\beta approaches 1.

QuestionIn a long ravine, gradients alternate between pointing across the valley and along it. Explain in words why momentum helps along the valley and not across it.Show answer

The across-valley components flip sign each step, so they partly cancel in the sum of past gradients. The along-valley components keep the same sign and accumulate. The velocity therefore grows in the useful direction and shrinks in the oscillating one.

QuestionYou turn momentum on and the loss starts oscillating wildly and then increases. Name the most likely cause and the first change you would make.Show answer

The effective step has grown, because the velocity amplifies the learning rate, so the optimizer overshoots. The first change is to lower the learning rate, or to reduce β\beta if the learning rate is already sensible.

Sources