Skip to content
Road to Intelligence

Concept · Chapter 2: The Math Toolkit

Momentum and Adam

Must knowUnderstand20 minDifficulty

Momentum smooths gradient steps by keeping a running average of past gradients, and Adam adds a per-parameter step size based on how large each parameter's gradients have been.

The problem

Plain SGD zig-zags in ravines, crawls along flat directions, and needs a single learning rate that suits every parameter at once.

The solution

Momentum accumulates velocity so consistent directions speed up and oscillations cancel; Adam also divides each parameter's step by a running estimate of its gradient magnitude.

The consequence

Training becomes faster and far less sensitive to tuning; AdamW (Adam with decoupled weight decay) is the default optimizer for Transformers.

Momentum: a ball, not a hiker

A hiker takes each step based only on the current slope. A ball carries velocity: in a ravine, the side-to-side pushes cancel out while the push along the ravine keeps adding up.

vt+1=β vt+∇L(wt),wt+1=wt−η vt+1\mathbf{v}_{t+1} = \beta\, \mathbf{v}_t + \nabla L(\mathbf{w}_t), \qquad \mathbf{w}_{t+1} = \mathbf{w}_t - \eta\, \mathbf{v}_{t+1}

With β=0.9\beta = 0.9, the velocity is roughly an average of the last ~10 gradients.

Adam: momentum plus per-parameter step sizes

Some parameters get big gradients, others tiny ones; one learning rate can't suit both. Adam keeps two running averages per parameter — of the gradient (mm) and of the squared gradient (vv) — and steps by their ratio:

wt+1=wt−η m^tv^t+ϵ\mathbf{w}_{t+1} = \mathbf{w}_t - \eta \, \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon}

Why AdamW

AdamW — Adam with weight decay applied directly to the weights rather than through the gradient — is the standard optimizer for training Transformers and LLMs Established. One practical cost: Adam stores mm and vv for every parameter — two extra numbers per weight, so the optimizer state holds twice as many values as the model itself. At LLM scale that memory is a big deal (Chapter 9).

What to remember

  • Momentum: v ← βv + g; w ← w − ηv. Like a ball rolling downhill.
  • Adam: momentum (1st moment) + per-parameter scaling by √(2nd moment).
  • AdamW decouples weight decay from the adaptive step; it's the LLM default.
  • Adam stores two extra numbers per parameter — a real memory cost at scale.

Key papers

Essential

Adam: A Method for Stochastic Optimization

Diederik P. Kingma, Jimmy Ba · 2014 · ICLR 2015

The default optimizer (with its AdamW variant) for training neural networks, including essentially all Transformers.

~40 min readarXiv:1412.6980✓ verified 2026-09-26
Important

An overview of gradient descent optimization algorithms

Sebastian Ruder · 2016

The standard readable survey of SGD, momentum, RMSprop, Adam and friends — one paper that explains the whole optimizer family tree.

How to read it: Very approachable. Read it after trying the Gradient Descent Playground.

~40 min readarXiv:1609.04747✓ verified 2026-09-26
Important

Decoupled Weight Decay Regularization

Ilya Loshchilov, Frank Hutter · 2017 · ICLR 2019

Introduced AdamW, the variant of Adam used to train most modern Transformers and LLMs.

~40 min readarXiv:1711.05101✓ verified 2026-09-26