Adam Optimizer

⚡ Key Takeaways

Adam (Adaptive Moment Estimation) is a first-order stochastic optimization algorithm that maintains exponentially decaying running averages of both the gradient (first moment) and its element-wise square (second moment), using these to compute per-parameter adaptive learning rates. Key result: combines the benefits of momentum and RMSProp with bias-corrected moment estimates, achieving robust convergence with minimal hyperparameter tuning. Where it applies: training deep neural networks, large-scale machine learning, non-convex stochastic optimization. Who/when: Diederik P. Kingma and Jimmy Ba, 2014 (ICLR 2015).

💡 The Core Insight

Different parameters in a high-dimensional model often have gradients of vastly different scales and statistics. Adam estimates, per coordinate, both the typical direction of descent (via an exponential moving average of gradients — the first moment) and the typical magnitude of fluctuations (via an exponential moving average of squared gradients — the second moment). Dividing the smoothed gradient by the square root of the smoothed squared gradient yields a signal-to-noise normalized step: coordinates with consistent gradients move confidently, while noisy coordinates are damped automatically. Bias correction repairs the systematic underestimation that arises from initializing the moving averages at zero.

Formal Statement

DefinitionAdam Update Rule

Let f(θ)f(\theta) be a stochastic objective with parameters θ∈Rd\theta \in \mathbb{R}^d, and let gt=∇θft(θt−1)g_t = \nabla_\theta f_t(\theta_{t-1}) be the stochastic gradient at step tt. Adam maintains two exponential moving averages, mtm_t (first moment) and vtv_t (second raw moment), and updates parameters as follows. The first moment estimate:

1
mt=β1mt−1+(1−β1)gt\quad m_t = \beta_1 m_{t-1} + (1-\beta_1) g_t

Derivation hint: this is an exponential moving average; expand recursively to see mt=(1−β1)∑i=1tβ1t−igim_t = (1-\beta_1)\sum_{i=1}^{t}\beta_1^{t-i} g_i. The second raw moment estimate (element-wise square gt2=gt⊙gtg_t^2 = g_t \odot g_t):

2
vt=β2vt−1+(1−β2)gt2\quad v_t = \beta_2 v_{t-1} + (1-\beta_2) g_t^2

Derivation hint: identical EMA structure applied to squared gradients; vt=(1−β2)∑i=1tβ2t−igi2v_t = (1-\beta_2)\sum_{i=1}^{t}\beta_2^{t-i} g_i^2. Bias-corrected estimates:

3
m^t=mt1−β1t,v^t=vt1−β2t\quad \hat{m}_t = \frac{m_t}{1-\beta_1^t}, \qquad \hat{v}_t = \frac{v_t}{1-\beta_2^t}

Derivation hint: take expectation of mtm_t assuming stationary gradients; E[mt]=(1−β1t)E[gt]\mathbb{E}[m_t]=(1-\beta_1^t)\mathbb{E}[g_t], so divide by (1−β1t)(1-\beta_1^t) to remove bias. The parameter update:

4
θt=θt−1−α m^tv^t+ϵ\quad \theta_t = \theta_{t-1} - \alpha \, \frac{\hat{m}_t}{\sqrt{\hat{v}_t} + \epsilon}

Derivation hint: divide the bias-corrected mean step by the bias-corrected RMS magnitude; ϵ\epsilon prevents division by zero.

Symbols: α\alpha = step size (learning rate, default 10−310^{-3}); β1∈[0,1)\beta_1 \in [0,1) = first-moment decay (default 0.90.9); β2∈[0,1)\beta_2 \in [0,1) = second-moment decay (default 0.9990.999); ϵ\epsilon = numerical stabilizer (default 10−810^{-8}); ⊙\odot = Hadamard (element-wise) product; all divisions and square roots are element-wise. Initialization: m0=0m_0 = 0, v0=0v_0 = 0.

TheoremEffective Step Bound

Assuming ϵ=0\epsilon = 0, the magnitude of the effective step taken by Adam in each coordinate satisfies a bound:

5
∣Δθt∣=α∣m^tv^t∣≤α⋅max⁡ ⁣(1,1−β11−β2)\quad \left| \Delta\theta_t \right| = \alpha \left| \frac{\hat{m}_t}{\sqrt{\hat{v}_t}} \right| \le \alpha \cdot \max\!\left(1, \frac{1-\beta_1}{\sqrt{1-\beta_2}}\right)

In the common case 1−β1≥1−β21-\beta_1 \ge \sqrt{1-\beta_2} (e.g. defaults: 0.1≥0.03160.1 \ge 0.0316), the bound is ∣Δθt∣≤α|\Delta\theta_t| \le \alpha, establishing a trust region independent of gradient scale.

Derivation hint: bound ∣m^t∣≤(1−β1)∑β1t−i∣gi∣1−β1t|\hat m_t| \le \frac{(1-\beta_1)\sum \beta_1^{t-i}|g_i|}{1-\beta_1^t} and v^t≥\sqrt{\hat v_t} \ge a corresponding term; in the sparse-gradient limit the ratio 1−β11−β2\frac{1-\beta_1}{\sqrt{1-\beta_2}} emerges from a single nonzero gradient.

Why It Holds / Derivation

ProofBias Correction Derivation

We show that the raw moving average vtv_t underestimates the true second moment, and that the correction in equation [3] removes this bias exactly under a stationarity assumption.

Step 1. Unroll the recursion in equation [2] from v0=0v_0 = 0:

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

Derivation hint: substitute vt−1v_{t-1} repeatedly; the geometric weights β2t−i\beta_2^{t-i} and the leading (1−β2)(1-\beta_2) factor follow by induction.

Step 2. Take the expectation, and assume the second moment is approximately stationary, E[gi2]≈E[gt2]\mathbb{E}[g_i^2] \approx \mathbb{E}[g_t^2]:

7
E[vt]=(1−β2) E[gt2]∑i=1tβ2 t−i+ζ=E[gt2] (1−β2t)+ζ\quad \mathbb{E}[v_t] = (1-\beta_2)\,\mathbb{E}[g_t^2] \sum_{i=1}^{t}\beta_2^{\,t-i} + \zeta = \mathbb{E}[g_t^2]\,(1-\beta_2^t) + \zeta

where ζ\zeta is small if the stationarity assumption holds (it absorbs the drift of E[gi2]\mathbb{E}[g_i^2] across time). Derivation hint: the finite geometric series ∑i=1tβ2t−i=1−β2t1−β2\sum_{i=1}^t \beta_2^{t-i} = \frac{1-\beta_2^t}{1-\beta_2} cancels the leading (1−β2)(1-\beta_2).

Step 3. The factor (1−β2t)<1(1-\beta_2^t) < 1 is the source of bias — early in training (tt small) it can be far below 11, severely shrinking vtv_t. Dividing by it yields an unbiased estimate:

8
E[v^t]=E ⁣[vt1−β2t]≈E[gt2]\quad \mathbb{E}[\hat v_t] = \mathbb{E}\!\left[\frac{v_t}{1-\beta_2^t}\right] \approx \mathbb{E}[g_t^2]

Derivation hint: divide equation [7] by (1−β2t)(1-\beta_2^t); the leading term becomes E[gt2]\mathbb{E}[g_t^2] exactly. The identical argument applies to m^t\hat m_t. ■\blacksquare

∎
DP
Diederik P. Kingma & Jimmy Lei Ba
2014

Diederik Kingma (then a PhD student at the University of Amsterdam under Max Welling) and Jimmy Ba (then at the University of Toronto under Geoffrey Hinton) introduced Adam in a paper submitted to ICLR 2015. Kingma is also a principal architect of the variational autoencoder (VAE) and normalizing flows; Ba contributed foundational work on layer normalization and attention. The name "Adam" derives from "Adaptive Moment estimation" and is not an acronym in the conventional sense, nor a person's name. Their paper provided both the practical algorithm and an attempted regret-based convergence analysis in the online convex optimization framework of Zinkevich.

Building Intuition

🧠 Intuition

Picture rolling a ball down a noisy, anisotropic landscape. Momentum (mtm_t) gives the ball inertia: it accumulates velocity in consistent directions, smoothing over the jitter of mini-batch noise. The second moment (vtv_t) acts like a per-direction shock absorber: in directions where the gradient is large and erratic, vt\sqrt{v_t} is large, so the update is shrunk; in flat, quiet directions, vt\sqrt{v_t} is small, so the step grows. The ratio m^t/v^t\hat m_t / \sqrt{\hat v_t} is essentially a signal-to-noise ratio. When gradients agree across mini-batches, m^t≈v^t\hat m_t \approx \sqrt{\hat v_t} and the ratio is near ±1\pm 1 — full-step confidence. When gradients are pure noise with zero mean, m^t→0\hat m_t \to 0 while v^t\sqrt{\hat v_t} stays positive, so the ratio shrinks and Adam automatically slows down. This is why Adam needs so little manual tuning: it self-normalizes its step to the local geometry. Bias correction matters most in the first few dozen steps, where without it the zero-initialized averages would make the algorithm take dangerously large early steps.

Figure
Adam's adaptive step vs. SGD on an ill-conditioned valley
Trajectories on an elongated (ill-conditioned) loss basin minimum SGD (oscillates) Adam (per-axis scaled, smooth descent) start

Worked Examples

ExampleSingle-Step Update with Numbers

Given: a single parameter θ0=1.000\theta_0 = 1.000, first gradient g1=0.5g_1 = 0.5, defaults α=10−3\alpha = 10^{-3}, β1=0.9\beta_1 = 0.9, β2=0.999\beta_2 = 0.999, ϵ=10−8\epsilon = 10^{-8}, with m0=v0=0m_0 = v_0 = 0.

Step 1 — first moment: m1=0.9(0)+0.1(0.5)=0.05m_1 = 0.9(0) + 0.1(0.5) = 0.05.

Step 2 — second moment: v1=0.999(0)+0.001(0.25)=0.00025v_1 = 0.999(0) + 0.001(0.25) = 0.00025.

Step 3 — bias correction (t=1t=1): 1−β11=0.11-\beta_1^1 = 0.1, 1−β21=0.0011-\beta_2^1 = 0.001.

m^1=0.050.1=0.5,v^1=0.000250.001=0.25\hat m_1 = \frac{0.05}{0.1} = 0.5, \qquad \hat v_1 = \frac{0.00025}{0.001} = 0.25

Note that after correction, m^1=g1\hat m_1 = g_1 and v^1=g12\hat v_1 = g_1^2 exactly — the first step recovers the raw gradient and its square.

Step 4 — update:

θ1=1.000−10−3⋅0.50.25+10−8=1.000−10−3⋅0.50.5=1.000−0.001\theta_1 = 1.000 - 10^{-3}\cdot\frac{0.5}{\sqrt{0.25}+10^{-8}} = 1.000 - 10^{-3}\cdot\frac{0.5}{0.5} = 1.000 - 0.001
θ1=0.999\boxed{\theta_1 = 0.999}

The effective step is exactly α=10−3\alpha = 10^{-3} — the trust-region bound of equation [5] is saturated on the very first step regardless of the gradient's actual size.

ExampleNoise Suppression Over Many Steps

Given: suppose the gradient at a coordinate is zero-mean noise: it equals +1+1 on odd steps and −1-1 on even steps (so the true descent signal is zero, but the magnitude is constant). Compute the steady-state behavior with defaults.

Second moment (steady state): since gt2=1g_t^2 = 1 always, vt→1v_t \to 1, hence v^t→1\sqrt{\hat v_t} \to 1.

First moment (steady state): mtm_t oscillates around 00. After many steps, the EMA of an alternating ±1\pm 1 with β1=0.9\beta_1 = 0.9 has amplitude

∣m∞∣=(1−β1)1+β1=0.11.9≈0.0526|m_\infty| = \frac{(1-\beta_1)}{1+\beta_1} = \frac{0.1}{1.9} \approx 0.0526

(geometric series of alternating signs). After bias correction (factor ≈1\approx 1 at large tt), ∣m^t∣≈0.0526|\hat m_t| \approx 0.0526.

Effective step:

∣Δθ∣=α ∣m^t∣v^t≈10−3⋅0.05261.0≈5.3×10−5|\Delta\theta| = \alpha\,\frac{|\hat m_t|}{\sqrt{\hat v_t}} \approx 10^{-3}\cdot\frac{0.0526}{1.0} \approx 5.3\times10^{-5}
∣Δθ∣≈5.3×10−5≪α\boxed{|\Delta\theta| \approx 5.3\times10^{-5} \ll \alpha}

Compare: a consistent gradient of +1+1 would give ∣Δθ∣≈α=10−3|\Delta\theta| \approx \alpha = 10^{-3}, roughly 19× larger. Adam automatically suppresses the step in the noisy direction — its signal-to-noise adaptivity in action.

Common Misconceptions

⚠️ Adam Is Not Guaranteed to Converge

A widespread belief is that Adam's published convergence proof guarantees convergence on all convex problems. This is false. Reddi, Kale & Kumar (2018, "On the Convergence of Adam and Beyond") identified a flaw in the original regret analysis: the proof incorrectly assumed a positive-semidefinite quantity that can in fact be negative. The effective learning-rate matrix Γt=v^tαt−v^t−1αt−1\Gamma_t = \frac{\sqrt{\hat v_t}}{\alpha_t} - \frac{\sqrt{\hat v_{t-1}}}{\alpha_{t-1}} need not be PSD because v^t\hat v_t can decrease. They constructed simple convex problems where Adam converges to the worst possible solution.

CounterexampleA Convex Problem Where Adam Fails

Consider online linear optimization with the periodic loss sequence (period 3), x∈[−1,1]x \in [-1,1]:

ft(x)={C xif t  3=1−xotherwisef_t(x) = \begin{cases} C\,x & \text{if } t \bmod 3 = 1 \\ -x & \text{otherwise}\end{cases}

for large constant C>2C > 2. The optimal fixed decision is x=−1x = -1 (the rare large positive gradient CC should dominate the two small negative gradients −1-1). However, because Adam's vtv_t heavily damps the rare large gradient (its squared value C2C^2 is averaged with weight 1−β21-\beta_2 and then divided by v^t\sqrt{\hat v_t}, which is dominated by the frequent −1-1 contributions), the effective influence of the informative gradient is reduced, and Adam drifts toward x=+1x = +1 — the opposite of optimal. This non-vanishing regret is impossible for plain SGD with decaying steps. The fix, AMSGrad, enforces v^t=max⁡(v^t−1,vt)\hat v_t = \max(\hat v_{t-1}, v_t) so the denominator is non-decreasing, restoring the PSD property.

⚠️ Adam ≠ Best Generalization

Empirically, on some tasks (notably image classification with CNNs), well-tuned SGD-with-momentum generalizes better than Adam despite Adam achieving lower training loss faster. Wilson et al. (2017) argue adaptive methods can converge to flatter-but-worse minima or solutions with larger weight norm. This motivated decoupled weight decay (AdamW), where weight decay is applied directly to parameters rather than folded into the gradient, since standard L2 regularization interacts poorly with adaptive per-coordinate scaling.

Connections

connection

Adam sits at the confluence of several optimization lineages. Setting β2→1\beta_2 \to 1 and removing the second-moment normalization recovers classical Momentum (specifically, heavy-ball with EMA). Setting β1=0\beta_1 = 0 and using only the second moment gives essentially RMSProp, Hinton's unpublished method. The element-wise division by v^t\sqrt{\hat v_t} approximates a diagonal preconditioner, linking Adam to Newton's Method and quasi-Newton ideas, though Adam uses only first-order information and a crude diagonal curvature surrogate. Adam is a member of the broader family of Stochastic Gradient Descent methods and is analyzed within Online Convex Optimization via regret bounds. Its bias-correction step has a clean interpretation in terms of Exponential Moving Average estimators. The relationship to Natural Gradient Descent is partial: v^t\hat v_t resembles the diagonal of the empirical Fisher information, though this correspondence is only approximate and the subject of ongoing debate.

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- 1951 — Robbins & Monro introduce the stochastic approximation framework, the theoretical bedrock of all SGD methods.
- 1964 — Polyak introduces the heavy ball momentum method, the ancestor of Adam's first-moment term.
- 2011 — Duchi, Hazan & Singer publish AdaGrad, the first widely used per-coordinate adaptive method, accumulating the full sum of squared gradients.
- 2012 — Tieleman & Hinton present RMSProp (in a Coursera lecture, never formally published), replacing AdaGrad's accumulation with an exponential moving average — directly the second-moment idea Adam reuses.
- 2012 — Zeiler publishes AdaDelta, another EMA-based adaptive method addressing AdaGrad's vanishing learning rate.
- December 2014 — Kingma & Ba post the Adam paper to arXiv; it is accepted to ICLR 2015, and rapidly becomes the most-cited optimization method in deep learning.
- 2016 — Dozat introduces Nadam, incorporating Nesterov-accelerated momentum into Adam.
- 2018 — Reddi, Kale & Kumar (ICLR) expose the convergence flaw and propose AMSGrad; Loshchilov & Hutter propose AdamW with decoupled weight decay.
- 2019–2021 — A wave of variants: RAdam (rectified variance), LAMB (layer-wise scaling for huge batches), AdaBelief, Lion; debate continues over Adam's generalization properties versus SGD.

Subtleties & Limits

open-problem

Several deep questions about Adam remain only partially resolved. (1) Generalization gap: there is still no complete theory explaining when and why SGD generalizes better than Adam, nor a sharp characterization of the minima each method selects in non-convex landscapes. (2) Non-convex convergence guarantees: rigorous convergence rates for Adam (and variants) on smooth non-convex objectives require additional assumptions (e.g. bounded gradients, specific β\beta relationships) and the constants are often vacuous; the precise role of ϵ\epsilon in convergence is subtle. (3) The Fisher-information interpretation: whether v^t\sqrt{\hat v_t} should be viewed as a principled approximation to natural-gradient preconditioning, or merely an effective heuristic, is contested. (4) Hyperparameter coupling: the interaction between α\alpha, β2\beta_2, weight decay, and learning-rate warmup is poorly understood theoretically, despite enormous practical importance — RAdam's analysis of early-training variance is one partial answer. (5) Optimal β\beta scaling with batch size and sequence length for billion-parameter models remains largely empirical.

See Also

Momentum · RMSProp · AdaGrad · Stochastic Gradient Descent · Online Convex Optimization · Natural Gradient Descent · AMSGrad · AdamW · Nadam · Exponential Moving Average