Concept · Chapter 2: The Math Toolkit
Momentum and Adam
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.
You should understand first
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.
With , 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 () and of the squared gradient () — and steps by their ratio:
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 and 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
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.
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.
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.