Paper Breakdowns  /  Adam
Paper 44~12 min readICLR 2015worked math + runnable code
Paper Breakdown

Adam,
explained.

If you have ever trained a neural network, you almost certainly used Adam. It is the closest thing deep learning has to a default — the optimizer you reach for before thinking. Its secret is combining two older ideas, momentum and per-parameter scaling, and adding one small correction most explanations skip. Here is the whole thing, built up from scratch and made runnable.

01

Why one learning rate isn't enough

Plain gradient descent has one knob — the learning rate — applied identically to every parameter. That is a problem, because parameters are not alike. Some receive large, frequent gradients; others receive tiny, rare ones. A step size big enough to move the sluggish parameters will make the sensitive ones explode; a step size safe for the sensitive ones leaves the sluggish ones barely moving. And the loss landscape makes it worse: real objectives have ravines — steep in one direction, nearly flat in another — where a single learning rate either bounces across the walls or crawls along the floor.

Two fixes had been invented separately. Momentum smooths and accelerates by averaging gradients over time. RMSProp gives each parameter its own effective learning rate, scaled by how big its gradients have recently been. Adam's contribution was to combine them cleanly — and to fix a subtle bias that both introduce at the start.

The one-sentence version

Adam keeps a running memory of each parameter's recent gradients (direction) and their recent sizes (scale), and uses both to take a well-sized step for every parameter independently.

02

Momentum: the first moment

Instead of stepping along the raw gradient g, which is noisy and can zig-zag, momentum steps along an exponentially weighted average of recent gradients. Call it m — the first moment, an estimate of the gradient's mean. Each step nudges the old average a little toward the new gradient:

m ← β₁·m + (1 − β₁)·g

With β₁ = 0.9, roughly the last ten gradients dominate the average. The effect is a heavy ball rolling downhill: consistent directions accumulate and speed up, while noisy back-and-forth components cancel out. Ravines that make raw descent oscillate get smoothed into a steady roll along the valley floor.

03

RMSProp: the second moment

Momentum fixes direction; it does nothing about scale. RMSProp adds a second running average — this time of the squared gradients. Call it v, the second moment, an estimate of each parameter's gradient variance:

v ← β₂·v + (1 − β₂)·g²

Then it divides the step by √v. A parameter with consistently large gradients gets a large v and so a smaller effective step; a parameter with tiny gradients gets a small v and a larger effective step. Every parameter ends up with its own adaptive learning rate, automatically. With β₂ = 0.999, this variance is averaged over a much longer window than the momentum — it changes slowly and stably.

Put the two together — step in the direction of m, scaled by 1/√v — and you almost have Adam. Almost, because both averages start life at zero, and that creates a bias worth fixing.

04

Adam, and the correction everyone forgets

Both moments are initialized at m = 0, v = 0. So on step 1, with a gradient g, the first moment is m = (1 − β₁)·g = 0.1·g — ten times too small. The estimate is biased toward zero, badly, for the first several steps. Adam cancels this exactly by dividing each moment by 1 − βt, where t is the step number:

mt = β₁·mt−1 + (1−β₁)·gt    vt = β₂·vt−1 + (1−β₂)·gt²
t = mt / (1 − β₁t)    t = vt / (1 − β₂t)    θt = θt−1 − α · m̂t / (√v̂t + ε)

At t=1 the divisor 1−β₁ turns m = 0.1·g back into m̂ = g, undoing the bias precisely; as t grows, βt → 0 and the correction fades to 1. The final line is the whole optimizer: move each parameter by the (corrected) average gradient, divided by the square root of its (corrected) average squared gradient.

One elegant property falls out of that division: Adam is roughly scale-invariant. Multiply every gradient by a constant and scales by that constant while √v̂ scales by the same amount — they cancel, and the step size barely changes. The update is governed by the direction and consistency of the gradients, not their raw magnitude, which is a big reason the default learning rate works across so many different problems.

RUN IT YOURSELF

Adam, in twelve lines

Here is the entire optimizer, plus a loop that runs it. Three things the math promised, made concrete: at step 1 the raw first moment is 0.1×g (ten times too small) and bias correction restores it to exactly g; the step for a gradient of 2 and a gradient of 20 come out identical (scale invariance); and Adam drives an ill-conditioned bowl — 100× steeper in x than y — to the origin, handling both directions at once where a single learning rate would struggle. Change the bowl or the betas and watch it adapt.

CPython · WebAssembly
05

The full rule and its famous defaults

The whole algorithm, per step t, per parameter: update m and v, bias-correct both, then step. Four hyperparameters govern it, and the paper's defaults are so robust they are rarely touched:

SymbolDefaultWhat it controls
α (learning rate)0.001Overall step size. The one people actually tune.
β₁0.9Decay of the first moment — how much momentum is retained (~last 10 gradients).
β₂0.999Decay of the second moment — the window for gradient-variance (~last 1000).
ε1e-8Guards the denominator against divide-by-zero when v̂ is tiny.

The reason those numbers travel so well is the scale invariance from section 04: because the update normalizes by the gradient's own size, the same α = 0.001 is a reasonable step whether gradients are large or small, whether the network is a tiny MLP or a giant transformer. That "just works out of the box" quality is exactly why Adam displaced hand-tuned SGD schedules for most practitioners.

06

Why it became the default — and where it goes next

Adam won because it removed a chore. Before it, getting a network to train meant babysitting a learning-rate schedule and often a per-layer tuning ritual. Adam's per-parameter adaptation absorbed most of that, converging fast and reliably on a huge range of architectures with the stock settings. For research velocity — try an idea, see if it trains, today — that mattered enormously.

It is not the end of the story. Plain Adam mishandles weight decay: folding L2 regularization into the gradient lets the adaptive 1/√v̂ scaling rescale the decay unevenly across parameters. AdamW fixes this by decoupling weight decay — applying it straight to the weights, outside the adaptive step — and is now the standard for training large models. Newer optimizers (LAMB for huge batches, Lion, Adafactor for memory) refine the idea further, but every one of them is a descendant of the same two-moments-plus-correction recipe this paper introduced.

Worth knowing

Adam keeps two extra numbers (m and v) per parameter — so its optimizer state is twice the model's size in memory. For a 7-billion-parameter model that is tens of gigabytes of optimizer state alone, which is why memory-efficient variants and sharding (ZeRO) exist.

Frequently asked

Quick answers

What does Adam stand for?

Adaptive Moment Estimation. It estimates the first moment (mean) and second moment (uncentered variance) of the gradients, and adapts each parameter's step from them.

Why does Adam need bias correction?

The moment averages start at zero, so early estimates are biased low — the first-moment estimate at step 1 is only 0.1× the gradient. Dividing by 1 − βᵗ cancels that bias exactly, so training doesn't crawl at the start.

Is Adam always better than SGD?

Not always. Adam converges faster and needs less tuning, but well-tuned SGD with momentum can generalize slightly better on some vision tasks. For most modern work — especially transformers — AdamW is the default.

What is AdamW?

Adam with decoupled weight decay: the regularization is applied directly to the weights instead of through the gradient, restoring uniform, correct weight decay. It's the standard optimizer for large language models.

Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns