Skip to content
mlmentorship

SGD with momentum: keep the update history

Trace the saved gradient sum from startup to steady behavior, then change history length and learning-rate placement.

Published · 8 min read ·Core ·Intermediate

Visual quick review

Compare raw SGD with momentum on an alternating gradient sequence and explain how momentum amplifies the consistent component while reducing the relative cross-valley oscillation.

Learning objective

In this recurrence, momentum reinforces persistent motion and damps alternating motion

Persistent directions accumulate while alternating directions cancelEach step keeps part of the previous velocity and adds the current gradient. Repeated gradients reinforce that retained motion. Alternating gradients push against it, so much of their movement cancels. Momentum favors persistence, not every large individual gradient.Retain velocity, then add the newdirectionPersistent gradients reinforceretained direction11.51.751.875Alternating gradients cancel retaineddirection1-0.50.75-0.625
Read it this way: Each step keeps part of the previous velocity and adds the current gradient. Repeated gradients reinforce that retained motion. Alternating gradients push against it, so much of their movement cancels. Momentum favors persistence, not every large individual gradient. Which sequence reinforces the same direction when half the previous velocity is retained?
Full explanation 8 min read
Reading depth

Summary

Momentum saves a decaying sum of gradients and uses it to choose the next parameter step. It is useful when successive gradients contain persistent direction, but history can also delay a necessary reversal.

Task: filter four prescribed descent directions with retention and learning rate . Start the parameter and buffer at zero. What changes relative to ordinary SGD?

Write gradient , descent direction , gradient buffer , and descent buffer . The figure shows the warmed-up response, not the first four updates from zero. These are prescribed inputs, not gradients reevaluated along two measured optimization trajectories.

Learning objective

Trajectory comparison: persistent versus alternating gradient components

Raw SGD follows alternating descent directions On a common coordinate scale, four raw SGD updates alternate between the vectors one comma two and one comma negative two. The path zigzags from zero comma zero through one comma two, two comma zero, three comma two, and four comma zero. RAW SGD · SAME SCALE +2 0 −1 0 2 4 6 8 Δθ = (1, +2), (1, −2), … ends at x = 4
Momentum amplifies consistent progress relative to oscillation For beta one half after the momentum buffer reaches its steady alternating regime, the update vectors alternate between two comma four thirds and two comma negative four thirds. On the same scale as raw SGD, four updates trace zero comma zero, two comma four thirds, four comma zero, six comma four thirds, and eight comma zero. MOMENTUM · β=0.5 · WARMED UP +2 0 −1 0 2 4 6 8 Δθ = (2, +4/3), (2, −4/3), … ends at x = 8
use the same axes in both panels. Raw SGD follows descent directions dt = −gt = (1, ±2). Each step moves forward by 1 and across the valley by 2. With ut = 0.5ut−1 + dt after warm-up, the alternating steady-state updates are (2, ±4/3). The consistent component doubles; the cross-valley-to-forward ratio falls from 2 to 2/3. This is a filter response, not evidence of measured convergence. Compare learning rates as well as paths. This original trace was checked against Polyak (1964), Sutskever et al. (2013), and the PyTorch SGD definition.
Check: Why is the persistent component amplified while the alternating component is damped in this specific warmed-up recurrence?
Reference drawing

Learning objective

In this recurrence, momentum reinforces persistent motion and damps alternating motion

Persistent directions accumulate while alternating directions cancelEach step keeps part of the previous velocity and adds the current gradient. Repeated gradients reinforce that retained motion. Alternating gradients push against it, so much of their movement cancels. Momentum favors persistence, not every large individual gradient.Retain velocity, then add the newdirectionPersistent gradients reinforceretained direction11.51.751.875Alternating gradients cancel retaineddirection1-0.50.75-0.625
Derivation
Raw SGD follows alternating descent directions On a common coordinate scale, four raw SGD updates alternate between the vectors one comma two and one comma negative two. The path zigzags from zero comma zero through one comma two, two comma zero, three comma two, and four comma zero. RAW SGD · SAME SCALE +2 0 −1 0 2 4 6 8 Δθ = (1, +2), (1, −2), … ends at x = 4
Momentum amplifies consistent progress relative to oscillation For beta one half after the momentum buffer reaches its steady alternating regime, the update vectors alternate between two comma four thirds and two comma negative four thirds. On the same scale as raw SGD, four updates trace zero comma zero, two comma four thirds, four comma zero, six comma four thirds, and eight comma zero. MOMENTUM · β=0.5 · WARMED UP +2 0 −1 0 2 4 6 8 Δθ = (2, +4/3), (2, −4/3), … ends at x = 8
use the same axes in both panels. Raw SGD follows descent directions dt = −gt = (1, ±2). Each step moves forward by 1 and across the valley by 2. With ut = 0.5ut−1 + dt after warm-up, the alternating steady-state updates are (2, ±4/3). The consistent component doubles; the cross-valley-to-forward ratio falls from 2 to 2/3. This is a filter response, not evidence of measured convergence. Compare learning rates as well as paths. This original trace was checked against Polyak (1964), Sutskever et al. (2013), and the PyTorch SGD definition.
Check: Why is the persistent component amplified while the alternating component is damped in this specific warmed-up recurrence?
Read it this way: Each step keeps part of the previous velocity and adds the current gradient. Repeated gradients reinforce that retained motion. Alternating gradients push against it, so much of their movement cancels. Momentum favors persistence, not every large individual gradient. Which sequence reinforces the same direction when half the previous velocity is retained?

Start from zero

Compute , then :

Step
1
2
3
4

Ordinary SGD ends at ; the startup momentum path ends at . The warmed-up figure instead ends at .

For constant input , the limiting buffer solves , giving . For alternating input , let the positive-phase limit be . Then , so . Here the steady components are and .

Two formulations

Classical momentum (Polyak, 1964)

Assume , zero initial buffer, and no dampening. Expanding the recurrence gives . This is a decaying sum, not a normalized exponential moving average.

For the average , matching initialization gives . An update using needs learning rate to match the sum-based update at constant .

Nesterov momentum (Nesterov, 1983)

New task: evaluate the gradient at a lookahead point. Replace above with ; keep the parameter update based at .

Check: for , current , previous , , and , lookahead is . The new buffer is and parameter , versus classical and . Use when: the specified algorithm calls for lookahead; this is not merely a changed label on the same gradient.

Picking

New task: respond faster when older directions become stale. Reduce and reconsider the learning rate together.

Check: constant gradient one gives limiting buffers at and at . At learning rate , limiting step magnitudes are and . Using with matches the latter scale, but not its response speed. Use when: history length changes; equal learning rates do not isolate smoothing.

Change the learning-rate placement

New task: resume across a learning-rate reduction from to . With , , and , the gradient buffer stays ; the new step magnitude is . The stored gradients do not contain the old learning rate.

For a displacement buffer , old instead gives . Use when: resuming or translating implementations; preserve state according to the actual recurrence, not a universal reset rule.

Failure and transfer

Reconstruct: why is not the zero-buffer startup trace?

Answer

Those values solve steady-state equations after transients decay. The four-row ledger retains the missing initial history explicitly; its final parameter differs from the warmed-up figure.

When SGD+momentum vs. Adam

Momentum changes the history filter; Adam also tracks coordinatewise squared gradients. Neither mechanism establishes a universal speed or generalization ordering. Compare tuned learning rates, schedules, regularization, stopping criteria, compute budgets, and repeated seeds on the target workload.

The scale is a useful history horizon, not an exact count of equally weighted observations. For independent scalar gradient noise of variance , the stationary sum has variance . The normalized average instead has variance . These noise assumptions do not describe every minibatch process.

Common pitfalls

  • A zero buffer creates startup transients, not an error that every momentum implementation must bias-correct.
  • A zero current gradient does not imply a zero update while history remains.
  • Larger retention can amplify overshoot as well as persistent progress.
  • Frameworks differ in dampening, first-buffer initialization, Nesterov parameterization, and learning-rate placement.
  • Algebraically related Nesterov forms require matching state definitions and schedule assumptions before comparing saved buffers.
  • Resume checkpoints must preserve parameters, optimizer buffers, step count, schedule state, and any random or sampling state needed for replay.