VerifiedarXiv:1412.698030 min
Optimization · Training

Adam: A Method for Stochastic Optimization

Two running averages give every weight its own learning rate.

Adam keeps, for each parameter, a running average of its gradient and a running average of its squared gradient. It steps along the first divided by the square root of the second, which makes each step about the same size no matter how large or small that parameter's gradients are.

Explaining the paperAdam: A Method for Stochastic OptimizationKingma, Ba · ICLR 2015 · arXiv:1412.6980 ↗

A 2014 paper with a six-line algorithm, a default learning rate of 0.001 that often works unchanged, and a convergence proof that turned out to be wrong.

Adam, or a close variant such as AdamW, is the optimizer most large neural networks are trained with, and the one PyTorch and JAX users reach for before they have a reason to pick anything else. Diederik Kingma and Jimmy Ba posted it to arXiv in December 2014 and presented it at ICLR 2015 (the author order, a footnote says, was decided by a coin flip over a Google Hangout). The main text runs nine pages and the algorithm fits in one box.

This page builds the algorithm from plain stochastic gradient descent in five steps, each fixing a specific problem:

  1. average the gradient over time, to cancel noise (the first moment);
  2. divide each parameter's step by the recent size of its gradients (the second moment);
  3. correct both averages for starting at zero (bias correction);
  4. read the resulting ratio as a step of about α\alpha per parameter;
  5. check the paper's convergence proof, which fails on a three-step counterexample.

What gradient descent has to work with

Training minimizes a loss, a single number measuring how wrong the model is, as a function of its parameters θ\theta (every weight, stacked into one long vector). The gradient gg is the vector of partial derivatives of the loss with respect to each parameter; it points in the direction the loss rises fastest. Gradient descent steps the other way:

θt=θt−1−α gt\theta_t = \theta_{t-1} - \alpha\, g_t
(1)

The minus sign makes it descend, and α\alpha is the learning rate. Picture walking downhill in fog: you can feel the slope under your feet and nothing beyond it.

SGD works under two constraints. First, the gradient is an estimate. The loss is an average over the whole dataset, far too expensive to evaluate every step, so each step computes the gradient on a random minibatch of, say, 128 examples. That estimate is unbiased (its average over all possible minibatches is the true gradient), but any single one is noisy, and the noise shrinks only as one over the square root of the batch size: quadrupling the batch halves it. Averaging gradients across steps is a cheaper way to cut noise. Second, the method uses slopes only. Curvature lives in the Hessian, a matrix with one row and one column per parameter; for a model with a billion parameters it would have 101810^{18} entries, so Adam, like SGD, is strictly first-order and never forms it.

With one global α\alpha, two failures show up constantly. In a long narrow valley (steep across, shallow along) a step big enough to make progress along the floor is too big for the walls, and the iterate bounces from side to side. And with noisy gradients, a fixed step follows each noisy sample, so a large share of its motion goes in directions the next sample reverses. The first moment addresses the noise and part of the bouncing; the second moment addresses the mismatch of scales.

The first moment: averaging the gradient

If consecutive gradient estimates disagree because of noise, average them. Adam keeps a running average of the gradient, the first moment mtm_t, and steps along it instead of along the latest sample:

mt=β1 mt−1+(1−β1) gtm_t = \beta_1\, m_{t-1} + (1-\beta_1)\, g_t
(2)

This is an exponential moving average (EMA). Each step keeps a fraction β1\beta_1 of the old average and mixes in 1−β11-\beta_1 of the new gradient, so a gradient from kk steps ago carries weight proportional to β1k\beta_1^k. With the default β1=0.9\beta_1 = 0.9, a gradient from 10 steps back carries 0.910≈0.350.9^{10} \approx 0.35 of the weight of the newest one, and the average has an effective memory of about 1/(1−β1)=101/(1-\beta_1) = 10 steps. Noise with random sign cancels inside that window; a direction that persists across it survives. In the narrow valley the side-to-side component flips sign every step and averages down, while the component along the floor has the same sign every step and accumulates.

This is the momentum idea, with one difference in scale. Classical heavy-ball momentum keeps a velocity u←μu+gu \leftarrow \mu u + g and steps by αu\alpha u. Feed it a constant gradient of 1 with μ=0.9\mu = 0.9 and the velocity settles where u=0.9u+1u = 0.9u + 1, at 10, so the step is ten times the gradient. Adam's weights β1\beta_1 and 1−β11-\beta_1 sum to one, so the same constant gradient drives mtm_t to 0.9+0.1=10.9 + 0.1 = 1, the gradient itself. The average stays on the gradient's own scale, which the division in the next section relies on. Adam also evaluates the gradient at the current parameters θt−1\theta_{t-1}; the look-ahead version (Nesterov momentum) applied to Adam is a separate method, Nadam.

In Figure 1 the amber dots are noisy gradient samples whose mean flips sign partway through, standing in for a change of direction during training. The teal curve is mtm_t. Drag β1\beta_1 to 0 and it follows every sample; drag it to 0.98 and it is smooth but takes dozens of steps to register the flip.

Figure 1 · the first moment
0.90
Raw gradient samples and their exponential moving average m. The mean of the samples changes sign midway. The memory is about 1/(1−β1\beta_1) steps: longer memory means a smoother line and a later turn.

The second moment: a step size per parameter

Parameters see gradients of very different sizes. In the paper's CNN experiment, weight sharing gives different layers "vastly different gradients", and with SGD practitioners hand-pick a smaller learning rate for the convolution layers. An embedding row for a rare word gets a nonzero gradient only in the few minibatches that contain the word. A single α\alpha that is safe for the large-gradient parameters is too small for the rest.

AdaGrad (Duchi, Hazan & Singer, 2011) gave each parameter its own divisor: the square root of the sum of all its squared gradients so far.

θt=θt−1−α gtδ+∑i=1tgi2\theta_t = \theta_{t-1} - \alpha\,\frac{g_t}{\delta + \sqrt{\sum_{i=1}^{t} g_i^2}}
(3)

A parameter with a history of large gradients gets a large divisor and a small step; a rarely active one keeps a large step, which is what sparse features need. The constant δ≥0\delta \ge 0 sits outside the square root and only guards against division by zero (the Adam paper's own statement of AdaGrad drops it).

The divisor in (3) is a cumulative sum, so it never decreases, and every parameter's effective step α/∑gi2\alpha/\sqrt{\sum g_i^2} shrinks for the whole run whether or not the gradients still carry signal. On a convex problem that shrinking is a convergent schedule. On a long non-convex training run it can stall progress.

RMSProp, which Tieleman and Hinton presented in a 2012 Coursera lecture and never published as a paper, replaces the sum with an exponential moving average of the squared gradient. That average is Adam's second moment:

vt=β2 vt−1+(1−β2) gt2v_t = \beta_2\, v_{t-1} + (1-\beta_2)\, g_t^2
(4)

It has the shape of (2), applied to the elementwise square of the gradient. An average forgets: it tracks the size of a parameter's recent gradients instead of their entire history, so the effective step can grow again when gradients get smaller. The decay rate β2\beta_2 sets the length of that memory, about 1/(1−β2)1/(1-\beta_2) steps, or 1000 at the default 0.999.

In Figure 2 the gradient magnitude drops to a third of its starting value partway through, as happens when training settles into a flatter region. Watch the two curves after the drop.

Figure 2 · the denominator's memory
0.900
Effective step α/⋅\alpha/\sqrt{\cdot} for one parameter. AdaGrad divides by a cumulative sum and its step keeps falling after the gradients shrink. Adam divides by a moving average and its step rises to match the new gradient size. Drag β2\beta_2 toward 0.999 to lengthen the memory.

AdaGrad's step, already small from the early large gradients, keeps sinking. Adam's step climbs back up, and the larger β2\beta_2 is, the more slowly it does so: as β2→1\beta_2 \to 1 the average stops forgetting and behaves like a sum again. The family section makes that limit exact.

The Adam update

Put the two averages together: the first moment gives the direction, the square root of the second moment gives each parameter's divisor, and a small ϵ\epsilon keeps the division finite.

θt=θt−1−α m^tv^t+ϵ\theta_t = \theta_{t-1} - \alpha\,\frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon}
(5)

The hats mark bias-corrected versions of mtm_t and vtv_t, defined two sections down; for the moment read them as mtm_t and vtv_t. Every operation is elementwise, so (5) is a separate one-dimensional update for each parameter, with ϵ\epsilon added outside the square root. The name comes from adaptive moment estimation: mtm_t and vtv_t estimate the first moment (the mean) and the second raw moment of each parameter's gradient. The whole algorithm, with the paper's defaults:

# Adam: one step on the parameter vector theta (all ops elementwise)
t     = t + 1                        # t starts at 0, so the first step is t = 1
g     = grad(loss, theta)            # gradient at the current theta
m     = b1 * m + (1 - b1) * g        # 1st moment: running mean of g
v     = b2 * v + (1 - b2) * g * g    # 2nd moment: running mean of g^2
m_hat = m / (1 - b1**t)              # bias correction
v_hat = v / (1 - b2**t)
theta = theta - a * m_hat / (sqrt(v_hat) + eps)
# start: m = v = 0 (same shape as theta), t = 0
# defaults: a = 1e-3, b1 = 0.9, b2 = 0.999, eps = 1e-8

Take one parameter through two steps at the defaults. At t=1t = 1 the gradient is g1=0.1g_1 = 0.1. Both averages start at zero, so

m1=0.1×0.1=0.01,v1=0.001×0.12=10−5.m_1 = 0.1 \times 0.1 = 0.01, \qquad v_1 = 0.001 \times 0.1^2 = 10^{-5}.

Bias correction divides m1m_1 by 1−0.9=0.11-0.9 = 0.1 and v1v_1 by 1−0.999=0.0011-0.999 = 0.001, giving m^1=0.1\hat m_1 = 0.1 and v^1=0.01\hat v_1 = 0.01, so v^1=0.1\sqrt{\hat v_1} = 0.1 and

Δθ1=−α 0.10.1+10−8≈−α=−0.001.\Delta\theta_1 = -\alpha\,\frac{0.1}{0.1 + 10^{-8}} \approx -\alpha = -0.001.

The parameter moves by α\alpha itself, against the gradient. Plain SGD would have moved it by αg1=0.0001\alpha g_1 = 0.0001, and by 0.10.1 if the gradient had been 100100; Adam moves it by 0.001 in both cases. Now suppose the second gradient is noise pointing the other way, g2=−0.1g_2 = -0.1:

m2=0.9(0.01)+0.1(−0.1)=−0.001,m^2=−0.0011−0.92≈−0.0053m_2 = 0.9(0.01) + 0.1(-0.1) = -0.001, \qquad \hat m_2 = \frac{-0.001}{1-0.9^2} \approx -0.0053m2=0.9(0.01)+0.1(−0.1)=−0.001,m^2=−0.0011−0.92≈−0.0053\begin{gathered} m_2 = 0.9(0.01) + 0.1(-0.1) = -0.001, \\ \hat m_2 = \frac{-0.001}{1-0.9^2} \approx -0.0053 \end{gathered}
v2=0.999×10−5+0.001×0.01=1.999×10−5,v^2=1.999×10−50.001999=0.01v_2 = 0.999 \times 10^{-5} + 0.001 \times 0.01 = 1.999 \times 10^{-5}, \qquad \hat v_2 = \frac{1.999\times 10^{-5}}{0.001999} = 0.01v2=0.999×10−5+0.001×0.01=1.999×10−5,v^2=1.999×10−50.001999=0.01\begin{gathered} v_2 = 0.999 \times 10^{-5} + 0.001 \times 0.01 = 1.999 \times 10^{-5}, \\ \hat v_2 = \frac{1.999\times 10^{-5}}{0.001999} = 0.01 \end{gathered}
Δθ2=−α −0.00530.1≈+0.053 α\Delta\theta_2 = -\alpha\,\frac{-0.0053}{0.1} \approx +0.053\,\alpha

Two gradients of equal size and opposite sign produce a step about a twentieth of the first one, because the numerator averaged them toward zero while the denominator, built from squares, did not shrink. Had g2g_2 been +0.1+0.1, m^2\hat m_2 would be 0.1 and the step a full α\alpha again.

Figure 3 puts three optimizers in the same narrow quadratic valley, starting from the same point with one shared step size each. The condition number κ\kappa is the ratio of the steep curvature to the shallow one: 1 is a round bowl, 40 a long trough. Press Play to run the race, scrub to study any step, and drag κ\kappa past 29.

Figure 3 · three optimizers, one valley
step 130
24:1
Quadratic valley, same start, fixed step sizes. SGD zig-zags across the steep axis and diverges once κ\kappa passes about 29. Momentum overshoots and rings. Adam takes a step of about α\alpha on each axis and its path barely changes with κ\kappa.

On a quadratic with curvature kk, one SGD step multiplies the distance to the minimum along that axis by 1−αk1 - \alpha k, and the iterate blows up once ∣1−αk∣>1|1-\alpha k| > 1, that is once αk>2\alpha k > 2. The figure's SGD step and shallow curvature put that threshold at κ≈29.4\kappa \approx 29.4. Adam's step on each axis is about α⋅sign(g)\alpha\cdot\mathrm{sign}(g) while the gradient keeps its sign, so the curvature of the axis drops out, and oneα\alpha works across parameters of very different scale. SGD with a learning rate and schedule tuned to a specific problem can match or beat it; Adam tends to be close without that tuning. (The figures on this page are small simulations written for this page, not experiments from the paper.)

Bias correction

Both averages start at zero, since no gradients exist yet. For the first steps each average is a mix of real gradients and that initial zero, so it reads too low. With β2=0.999\beta_2 = 0.999 the second moment takes in only a thousandth of each new squared gradient, and after 100 steps it has reached about 10% of the value it is estimating.

Unrolling (4) writes vtv_t as a weighted sum of every past squared gradient:

vt=(1−β2)∑i=1tβ2 t−i gi2v_t = (1-\beta_2)\sum_{i=1}^{t}\beta_2^{\,t-i}\, g_i^2

Take expectations. If the squared gradient's expected value is the same at every step, it factors out of the sum, and the remaining weights (1−β2)β2 t−i(1-\beta_2)\beta_2^{\,t-i} form a geometric series that sums to exactly 1−β2t1-\beta_2^t:

E[vt]=E[gt2] (1−β2 t)+ζ\mathbb{E}[v_t] = \mathbb{E}[g_t^2]\,\big(1 - \beta_2^{\,t}\big) + \zeta
(6)

The term ζ\zeta is zero when the second moment is stationary and stays small otherwise, because the exponential weights make old gradients (the ones most likely to differ) count little. The factor 1−β2t1-\beta_2^t is exact: it is the total weight the average has placed on real gradients. The missing β2t\beta_2^t still sits on the initial zero, which contributes nothing, so the average reads low by exactly that factor. Dividing it out gives estimates that are unbiased from the first step:

m^t=mt1−β1 t,v^t=vt1−β2 t\hat m_t = \frac{m_t}{1-\beta_1^{\,t}}, \qquad \hat v_t = \frac{v_t}{1-\beta_2^{\,t}}
(7)

The first moment gets the same correction with β1\beta_1; the paper notes the derivation is identical. A thermometer switched on in a warm room behaves the same way: if you know what fraction of the way it has warmed up, you can divide the reading by that fraction and get the room temperature before the reading settles. At t=1t = 1 the second-moment correction is 1/(1−β2)=10001/(1-\beta_2) = 1000, the factor that turned v1=10−5v_1 = 10^{-5} into v^1=10−2\hat v_1 = 10^{-2} in the worked example. As tt grows, β2t→0\beta_2^t \to 0 and both corrections fade to 1.

Figure 4 · bias correction
0.950
Estimating E[g2]\mathbb{E}[g^2] from noisy squared gradients. The raw average (grey) starts at zero and climbs slowly; dividing by 1−β2t1-\beta_2^t puts the corrected estimate near the true value from the first step. Drag β2\beta_2 up and the raw average takes longer to catch up.

Skipping the correction does not make early steps timid. Both averages are biased low, but the step divides by the square root of vtv_t, and vtv_t is biased far more than mtm_t because β2\beta_2 is closer to 1. For a constant gradient the two averages are exactly (1−β1t) g(1-\beta_1^t)\,g and (1−β2t) g2(1-\beta_2^t)\,g^2, so the uncorrected step is

∣Δt∣α=1−β1 t1−β2 t\frac{|\Delta_t|}{\alpha} = \frac{1-\beta_1^{\,t}}{\sqrt{1-\beta_2^{\,t}}}

which is 3.16 at t=1t=1, peaks at 6.57 at t=12t = 12, and takes thousands of steps to come back down to 1. With correction the same constant gradient gives exactly α\alpha at every step. The paper's wording is that without correction the "initial steps" are "much larger", and the effect grows as β2\beta_2 approaches 1, exactly the setting sparse gradients call for.

Figure 5 · how large a step can get
0.90
0.999
Step size in units of α\alpha, computed in closed form, on log axes. In steady gradient mode the gradient never changes; in one gradient after silence mode a parameter sees zeros and then a single nonzero gradient at step t. With and without bias correction. Hover or tap to read values; drag β1\beta_1 and β2\beta_2.

In steady-gradient mode, drag β2\beta_2 to 0.9999 and the uncorrected peak climbs past 20. Set β1=0\beta_1 = 0 and the uncorrected first step is 1/1−β21/\sqrt{1-\beta_2}, 31.6 at the default β2\beta_2. The second mode belongs to the next section.

The ratio and the step bound

With ϵ\epsilon set aside, the step is Δt=α m^t/v^t\Delta_t = \alpha\,\hat m_t/\sqrt{\hat v_t}. The numerator estimates the mean gradient E[g]\mathbb{E}[g]. The denominator estimates the square root of the second raw moment E[g2]\mathbb{E}[g^2], which is the root-mean-square (RMS) size of the gradient, signal and noise together. It is the variance only when the mean is zero: for a gradient with mean μ\mu and noise of standard deviation σ\sigma, E[g2]=μ2+σ2\mathbb{E}[g^2] = \mu^2 + \sigma^2.

Two properties follow from dividing a mean by an RMS. The first is scale invariance: multiply every gradient by a constant cc, and m^t\hat m_t scales by cc, v^t\hat v_t by c2c^2, its square root by cc, and the ratio is unchanged. Redo the worked example with g1=100g_1 = 100 in place of 0.1 and m^1=100\hat m_1 = 100, v^1=100\sqrt{\hat v_1} = 100, and the step is still α\alpha. The second is a bound. A mean can never exceed an RMS in magnitude,

∣E[g]∣≤E[g2],\big|\mathbb{E}[g]\big| \le \sqrt{\mathbb{E}[g^2]},

which is another way of writing Var[g]≥0\mathrm{Var}[g] \ge 0: averaging lets opposite signs cancel, while the RMS counts every sample at full size. So in ordinary training m^t/v^t\hat m_t/\sqrt{\hat v_t} sits between about −1-1 and +1+1, and each step moves a parameter by at most about α\alpha, however steep or shallow its slope. The paper calls this a trust region around the current parameters, the distance beyond which the current gradient estimate is not trusted. Because α\alpha bounds the distance traveled per step, you can often choose it from how far the parameters need to move: if good weights lie within about 1 of the initialization, α=10−3\alpha = 10^{-3} needs on the order of a thousand consistent steps to get there. (The term is Adam's own; TRPO uses the same words for a KL constraint on a policy, a different mechanism.)

The bound is not exactly α\alpha. Section 2.1 of the paper states two cases:

∣Δt∣≤α 1−β11−β2   if (1−β1)>1−β2,∣Δt∣≤α   otherwise.|\Delta_t| \le \alpha\,\frac{1-\beta_1}{\sqrt{1-\beta_2}} \;\text{ if } (1-\beta_1) > \sqrt{1-\beta_2}, \qquad |\Delta_t| \le \alpha \;\text{ otherwise.}∣Δt∣≤α 1−β11−β2   if (1−β1)>1−β2,∣Δt∣≤α   otherwise.\begin{aligned} |\Delta_t| &\le \alpha\,\frac{1-\beta_1}{\sqrt{1-\beta_2}} \;\text{ if } (1-\beta_1) > \sqrt{1-\beta_2}, \\ |\Delta_t| &\le \alpha \;\text{ otherwise.} \end{aligned}
(8)

At the defaults 1−β1=0.11-\beta_1 = 0.1 is larger than 0.001≈0.0316\sqrt{0.001} \approx 0.0316, so the first case applies and the worst case is 0.1/0.0316≈3.16 α0.1/0.0316 \approx 3.16\,\alpha. The paper says this case "only happens in the most severe case of sparsity: when a gradient has been zero at all timesteps except at the current timestep." Switch Figure 5 to one gradient after silence to see it: the corrected step is exactly α\alpha if the gradient arrives at step 1, dips to about 0.48 α0.48\,\alpha at step 10, and climbs toward 3.16 α3.16\,\alpha only after thousands of silent steps, when v^\hat v holds a single squared gradient weighted by 1−β21-\beta_2. The amber line in this mode is the ceiling (1−β1)/1−β2(1-\beta_1)/\sqrt{1-\beta_2} itself. Raise β1\beta_1 to 0.99 and it falls to 0.32 α0.32\,\alpha, so the maximum becomes α\alpha (at step 1), the second case of (8).

The same ratio sets how far a parameter moves when its gradient is mostly noise. The paper calls m^t/v^t\hat m_t/\sqrt{\hat v_t} the signal-to-noise ratio (SNR), "with a slight abuse of terminology". For a gradient with mean 1 and noise σ\sigma the ratio fluctuates around 1/1+σ21/\sqrt{1+\sigma^2}: 1 with no noise, 0.86 at σ=0.6\sigma = 0.6, 0.20 at σ=5\sigma = 5. Close to a minimum the true gradient shrinks while the minibatch noise does not, so the SNR falls and the steps shrink with it. The paper calls this "a form of automatic annealing": a decreasing step size nobody had to schedule.

Figure 6 · signal, noise, and the step
0.60
One parameter's gradient, mean 1 plus noise of size σ\sigma, run through Adam's averages at the default decay rates. The gauge shows m^/v^\hat m/\sqrt{\hat v} at the last step (the teal marker) and the value it fluctuates around, 1/1+σ21/\sqrt{1+\sigma^2} (the hollow amber circle). Slide σ\sigma from 0 to 5; resample to draw new noise.

At large σ\sigma the teal marker wanders far from the amber circle between resamples, and can land on the wrong side of zero. The average in the numerator covers about 10 steps, so at σ=5\sigma = 5 its own noise (standard deviation about 1.15) is as large as the signal of 1.

What the paper tested

Section 6 compares Adam with other optimizers on four problems. For every method the learning rate and momentum were searched over a dense grid and the best setting reported, and all methods started from the same initialization. The results are training-cost curves, not tables, so the claims below are the paper's qualitative readings of its figures.

The convergence proof and its counterexample

The paper also proves a convergence result, in the online convex optimization framework of Zinkevich (2003). The setup is a repeated game: at each round the optimizer picks parameters θt\theta_t, then a convex loss ftf_t is revealed, possibly chosen adversarially. Regret compares the losses incurred with those of the best single fixed parameter θ∗\theta^* in hindsight:

R(T)=∑t=1T[ft(θt)−ft(θ∗)]R(T) = \sum_{t=1}^{T}\big[f_t(\theta_t) - f_t(\theta^*)\big]
(9)

If R(T)R(T) grows more slowly than TT, the average regret R(T)/TR(T)/T goes to zero, which is the online version of converging to the best answer. The paper claims R(T)=O(T)R(T) = O(\sqrt{T}), the best rate known for this general setting. The theorem does not cover Adam as people run it: it assumes a decaying step αt=α/t\alpha_t = \alpha/\sqrt{t} and a decaying momentum β1,t=β1λt−1\beta_{1,t} = \beta_1\lambda^{t-1} with λ∈(0,1)\lambda \in (0,1), where practical Adam keeps both constant.

In 2018 Reddi, Kale and Kumar showed the proof is wrong even under those assumptions. Proofs of this kind track how the inverse of the effective step size changes from one step to the next,

Γt=Vtαt−Vt−1αt−1,\Gamma_t = \frac{\sqrt{V_t}}{\alpha_t} - \frac{\sqrt{V_{t-1}}}{\alpha_{t-1}},

where VtV_t is the diagonal matrix of second-moment estimates. The regret bound sums a series of terms weighted by these differences. When every Γt\Gamma_t is positive semi-definite (the effective step never grows on any coordinate), the sum telescopes: consecutive terms cancel and only the endpoints remain, which the assumptions bound. For SGD with a decaying rate and for AdaGrad that holds, because their divisors only grow. Adam's moving average is designed so that vtv_t can fall when gradients shrink, which makes the effective step rise and Γt\Gamma_t negative on that coordinate. The original proof assumed positive semi-definiteness anyway, and without it the bound does not follow.

Reddi et al. then built a problem where Adam fails. One parameter lives on [−1,1][-1, 1]. The loss is ft(x)=Cxf_t(x) = Cx on every third step and −x-x on the other two, with C>2C > 2. Over one three-step cycle the gradients sum to C−2>0C - 2 > 0, so the total loss falls as xx falls and the best fixed point is x∗=−1x^* = -1. They set β1=0\beta_1 = 0 and a deliberately small β2=1/(1+C2)\beta_2 = 1/(1+C^2) (not the default 0.999), so vtv_t forgets within a step or two. The rare gradient CC inflates the denominator, so its step toward −1-1 is about α\alpharather than CC times larger; the denominator then decays, and each of the two frequent gradients of −1-1 gets a near-full step toward +1+1. Net drift per cycle is toward +1+1, the worst point in the interval.

Figure 7 · the counterexample
C = 5.0
Online convex problem on [−1, 1]: gradient CC every third step, −1-1 otherwise, so the best point is x∗=−1x^*=-1. Adam with β2=1/(1+C2)\beta_2 = 1/(1+C^2) ends at +1+1. AMSGrad, which divides by the running maximum of vv, heads toward −1-1. As CC approaches 2 the average gradient per step, (C−2)/3(C-2)/3, goes to zero, so AMSGrad crawls (−0.13 at C=2.1C = 2.1 after 150 steps) while Adam still reaches +1+1. Drag CC.

The same paper proposed AMSGrad, which divides by the largest second-moment estimate seen so far:

v^t=max⁡(v^t−1, vt),θt=θt−1−α mtv^t\hat v_t = \max\big(\hat v_{t-1},\, v_t\big), \qquad \theta_t = \theta_{t-1} - \alpha\,\frac{m_t}{\sqrt{\hat v_t}}

(In Reddi's algorithm the first moment is not bias-corrected.) The running maximum never decreases, so the effective step never grows, Γt≥0\Gamma_t \ge 0, and the telescoping argument goes through. In the counterexample the first large gradient sets a high mark that keeps damping the parameter, and AMSGrad converges to −1-1. AMSGrad's own proof was later found to have a gap and was patched by Tran and Phong (2019). None of this changed what practitioners run: the counterexample depends on a small β2\beta_2 and an adversarial loss sequence, and Adam with default settings kept working on real problems.

AdaMax, AdaGrad and other relatives

Section 7.1 of the paper generalizes the denominator. Adam divides by a scaled L2 norm of a parameter's current and past gradients; replace it with an Lp norm and let p→∞p \to \infty, and the norm becomes a maximum. This gives AdaMax, whose denominator is an exponentially decayed running maximum of the gradient's absolute value:

ut=max⁡(β2 ut−1,  ∣gt∣),θt=θt−1−α1−β1 t mtutu_t = \max\big(\beta_2\, u_{t-1},\; |g_t|\big), \qquad \theta_t = \theta_{t-1} - \frac{\alpha}{1-\beta_1^{\,t}}\,\frac{m_t}{u_t}

with u0=0u_0 = 0. The maximum needs no bias correction, because the newest ∣gt∣|g_t| enters at full weight instead of at weight 1−β21-\beta_2, and there is no ϵ\epsilon in the update. Its step obeys the simpler bound ∣Δt∣≤α|\Delta_t| \le \alpha. The suggested defaults are α=0.002\alpha = 0.002 (twice Adam's), β1=0.9\beta_1 = 0.9 and β2=0.999\beta_2 = 0.999.

AdaGrad is a limit of Adam. Set β1=0\beta_1 = 0 (no momentum), let β2→1\beta_2 \to 1, and replace α\alpha with the annealed αt=α t−1/2\alpha_t = \alpha\, t^{-1/2}. As β2→1\beta_2 \to 1 the bias-corrected second moment becomes the plain average of all squared gradients, and the annealed step supplies the missing t\sqrt{t}:

lim⁡β2→1v^t=1t∑i=1tgi2,α t−1/2 gtt−1∑i=1tgi2=α gt∑i=1tgi2\lim_{\beta_2\to 1}\hat v_t = \frac{1}{t}\sum_{i=1}^t g_i^2, \qquad \frac{\alpha\, t^{-1/2}\, g_t}{\sqrt{t^{-1}\sum_{i=1}^t g_i^2}} = \frac{\alpha\, g_t}{\sqrt{\sum_{i=1}^t g_i^2}}

The right-hand side is the step in AdaGrad's update (3) with δ=0\delta = 0. The correspondence needs all four ingredients. Without bias correction, β2\beta_2 near 1 leaves vtv_t near zero and the updates grow without bound, the same effect as the uncorrected curve in Figure 5.

The paper also relates Adam to natural gradient descent, which preconditions the gradient with the inverse of the Fisher information matrix, a measure of how much the model's predicted distribution changes when the parameters move. It says v^t\hat v_t approximates the diagonal of that matrix, and that Adam, dividing by v^t\sqrt{\hat v_t}, applies the inverse square root of the diagonal (exponent −1/2-1/2), a milder correction than natural gradient's full inverse (exponent −1-1). The link is an analogy. What Adam accumulates is the squared gradient at the observed labels, an empirical Fisher, which equals the true Fisher only for a log-likelihood loss with labels drawn from the model itself, roughly the situation near a well-fit optimum.

Two further variants are common. L2 regularization added to the loss puts λθ\lambda\theta inside the gradient, where Adam divides it by v^t\sqrt{\hat v_t}, so parameters with large gradients get less regularization. AdamW subtracts the weight decay outside the ratio instead. And Section 7.2 of the paper suggests averaging the parameters themselves for evaluation, since the last iterate is noisy:

θˉt=β2 θˉt−1+(1−β2) θt,θˉ0=0,\bar\theta_t = \beta_2\,\bar\theta_{t-1} + (1-\beta_2)\,\theta_t, \qquad \bar\theta_0 = 0,

corrected the same way, by dividing by 1−β2t1-\beta_2^t.

Implementation notes

Adam stores two extra vectors the size of the model, mm and vv. In fp32 that is 8 bytes per parameter: 56 GB of optimizer state for a 7-billion-parameter model, more than the fp16 weights themselves. Mixed-precision training usually keeps an fp32 master copy of the weights too, which is why ZeRO counts Adam's training state at 16 bytes per parameter and shards it across GPUs.

The paper gives a reordering that saves two divisions over the whole parameter vector per step, by folding both corrections into a scalar learning rate:

# Same step, reordered as in Sec. 2 of the paper: fold both corrections into a
# per-step learning rate and skip the two divisions over the whole vector.
a_t   = a * sqrt(1 - b2**t) / (1 - b1**t)
theta = theta - a_t * m / (sqrt(v) + eps_hat)
# identical to Algorithm 1 only if eps_hat = eps * sqrt(1 - b2**t)

At t=1t = 1 with the defaults, the folded learning rate is 0.001×0.0316/0.10.001 \times 0.0316/0.1, or 3.16×10−43.16\times 10^{-4}. The two forms differ in where ϵ\epsilon lands. Multiply (5) through by 1−β2t\sqrt{1-\beta_2^t} and the constant in the denominator becomes ϵ1−β2t\epsilon\sqrt{1-\beta_2^t}, which changes with tt. A library that implements the reordered form with a fixed ϵ^\hat\epsilon therefore applies an effectively larger ϵ\epsilon early in training (by a factor of 31.6 at t=1t = 1 with the default β2\beta_2). This matters only when v\sqrt{v} is comparable to ϵ\epsilon, as in the paper's CNN run.

Provenance Verified against primary literatureHow we verify
Robbins & Monro (1951)Stochastic approximation: descending on noisy gradient estimates, the setting Adam works in. Background; the Adam paper does not cite it.
Duchi, Hazan & Singer (2011)AdaGrad. Divides by the square root of a cumulative sum of squared gradients; its constant delta sits outside the root. Adam reduces to it only with beta1 = 0, beta2 -> 1, alpha/sqrt(t) and bias correction all together.
Tieleman & Hinton (2012)RMSProp, from Coursera lecture 6e: MeanSquare = 0.9 MeanSquare + 0.1 grad^2, gradient divided by its square root. The slide has no epsilon, no momentum and no bias correction.
Kingma & Ba (2015), Sec. 2.1The step bound has two cases: alpha(1 - beta1)/sqrt(1 - beta2) when 1 - beta1 > sqrt(1 - beta2), alpha otherwise. At the defaults the worst case is 3.16 alpha, reached only by a gradient that was zero at every earlier step.
Reddi, Kale & Kumar (2018)The O(sqrt T) regret proof assumes Gamma_t is positive semi-definite, which fails for exponential moving averages. Counterexample on [-1, 1] and the AMSGrad fix; AMSGrad's own proof was patched by Tran & Phong (2019).
Kunstner, Balles & Hennig (2019)v-hat approximates a diagonal empirical Fisher (observed labels). It matches the true Fisher only for a log-likelihood loss with labels drawn from the model, near a well-fit optimum.
correctionTwo slips in Section 3 of the paper, present from v1 (2014) through v9 (2017). The bias derivation is about the second moment, yet the text says "the exponential decay rate β₁ can (and should) be chosen" to down-weight old gradients; the symbol must be β₂. A paragraph later it says sparse gradients call for "a small value of β2" to average over many gradients, but averaging over many gradients takes β₂ close to 1, which is how Section 5 states it ("a value of β2 close to 1 (required in case of sparse gradients)"). This page teaches β₂ in the derivation and a β₂ close to 1 for sparse gradients.

Questions you might still have

?

If v is the variance of the gradient, why divide by it?
v estimates the second raw moment E[g^2], the uncentered variance, so its square root is the RMS size of the gradient, signal and noise together. It equals the variance only when the gradient has mean zero. Dividing by the RMS puts every coordinate on the same scale, so each step comes out near alpha.

?

Is Adam without bias correction the same as RMSProp?
It is closest to RMSProp with momentum, and even that differs in the algebra: RMSProp with momentum applies momentum to the already-rescaled gradient g/sqrt(v), while Adam averages g and g^2 separately and divides afterwards. The paper's Section 6.4 compares the two on a variational autoencoder and finds bias correction matters most when beta2 is close to 1.

?

Does the broken proof mean Adam does not work?
No. It means the paper's convergence guarantee was never established. Reddi, Kale and Kumar built a convex problem where Adam, with a deliberately small beta2, converges to the worst point, and proposed AMSGrad. In ordinary training Adam kept working, which is why it stayed the default.

?

Why is the default beta2 (0.999) so much closer to 1 than beta1 (0.9)?
beta2 sets how many squared gradients the denominator averages over, roughly 1/(1 - beta2) = 1000 at the default. A long window gives a stable estimate of each coordinate's gradient size, which sparse gradients need. The cost is a slow warm-up from zero, which is why bias correction matters most for v.

?

What does epsilon do, and does its value matter?
It keeps the division finite when v-hat is near zero. At 1e-8 it is negligible while gradients are larger than about 1e-8, but the paper reports that in its CNN experiment v-hat shrank toward zero after a few epochs and was dominated by epsilon, at which point the step is roughly alpha times m-hat over epsilon and the per-parameter scaling is gone.

?

How much memory does Adam add?
Two extra vectors the size of the parameters, m and v. In fp32 that is 8 bytes per parameter, 56 GB of optimizer state for a 7-billion-parameter model, before counting the weights and gradients themselves. The ZeRO explainer covers how that state is sharded across GPUs.

Footnotes & further reading

  1. The paper: Kingma & Ba, Adam: A Method for Stochastic Optimization (ICLR 2015; arXiv v9, January 2017). The name is from "adaptive moment estimation", and a footnote records that the author order was decided by a coin flip.
  2. The convergence proof is corrected in Reddi, Kale & Kumar, On the Convergence of Adam and Beyond (ICLR 2018), which introduces AMSGrad and the counterexample of Figure 7. AMSGrad's own proof is patched in Tran & Phong (2019).
  3. AdaGrad: Duchi, Hazan & Singer, Adaptive Subgradient Methods for Online Learning and Stochastic Optimization (JMLR 2011). RMSProp: Tieleman & Hinton, Lecture 6e, Neural Networks for Machine Learning (Coursera, 2012; the Adam paper cites it as Lecture 6.5).
  4. Momentum: Polyak's heavy ball (1964) and Sutskever, Martens, Dahl & Hinton, On the importance of initialization and momentum in deep learning (ICML 2013).
  5. The online-learning framing is Zinkevich, Online Convex Programming and Generalized Infinitesimal Gradient Ascent (ICML 2003); the stochastic-approximation roots are Robbins & Monro (1951).
  6. On the Fisher connection and its limits: Kunstner, Balles & Hennig, Limitations of the Empirical Fisher Approximation (NeurIPS 2019). For the optimization background generally, Goodfellow, Bengio & Courville, Deep Learning, chapter 8. Decoupled weight decay is covered in the AdamW explainer.