Simple Algorithm
Machine Learning · Convergence · 28 min

Adaptive Methods in Depth

AdaGrad’s regret bound, Adam’s failure cases and AdamW.

Adam is the default optimizer of deep learning, yet on a one-dimensional convex problem it can converge to the worst possible point. This lesson proves the regret bound that made AdaGrad famous, builds the counterexample that broke Adam's original analysis, reads Adam's step as a sign step scaled by a signal-to-noise ratio, and sorts out what is known, and what is still argued, about warmup, decoupled weight decay and generalization.

What you’ll learn

  • Define regret in online convex optimization and prove AdaGrad's data-dependent bound 2 D∞∑i∥g1:T,i∥2\sqrt2\,D_\infty\sum_i\norm{\mathbf g_{1:T,i}}_2.
  • Analyze Reddi, Kale & Kumar's counterexample, explain why a short-memory second moment breaks convergence, and how AMSGrad or a large β2\beta_2 repairs it.
  • Interpret Adam's step as a sign step scaled by the gradient's signal-to-noise ratio, and explain warmup and RAdam's variance rectification.
  • Show why an L2 penalty and decoupled weight decay differ under adaptive preconditioning, and weigh the evidence on how adaptive methods generalize.

Online convex optimization and AdaGrad

The cleanest theory of adaptive methods lives in online convex optimization, the convex corner of online learning. At each round t=1,…,Tt=1,\dots,T a learner picks xt\mathbf x_t in a convex set X\mathcal X; then a convex loss ftf_t is revealed and the learner pays ft(xt)f_t(\mathbf x_t). Performance is measured by regret against the best fixed point in hindsight,

RT=∑t=1Tft(xt)−min⁡x∈X∑t=1Tft(x),R_T=\sum_{t=1}^Tf_t(\mathbf x_t)-\min_{\mathbf x\in\mathcal X}\sum_{t=1}^Tf_t(\mathbf x),

with no assumption on how the losses are generated (Online Learning & Regret). Projected online gradient descent, xt+1=ΠX(xt−ηtgt)\mathbf x_{t+1}=\Pi_{\mathcal X}(\mathbf x_t-\eta_t\mathbf g_t) with gt∈∂ft(xt)\mathbf g_t\in\partial f_t(\mathbf x_t) and ηt∝1/t\eta_t\propto1/\sqrt t, achieves RT=O(DGT)R_T=\order{DG\sqrt T}, where DD is the diameter of X\mathcal X and GG bounds ∥gt∥\norm{\mathbf g_t} (Zinkevich, 2003). Regret bounds are optimization bounds too: if the ftf_t are i.i.d. draws of a random convex loss with mean FF, the averaged iterate satisfies EF(xˉT)−F⋆≤ERT/T\E F(\bar{\mathbf x}_T)-F^\star\le\E R_T/T (online-to-batch conversion).

Proof of the bound, and what it buys

DerivationProof
  1. ∥xt+1−x⋆∥Ht2 ≤ ∥xt−x⋆∥Ht2−2η gt⊤(xt−x⋆)+η2∥gt∥Ht−12\norm{\mathbf x_{t+1}-\mathbf x^\star}_{H_t}^2\ \le\ \norm{\mathbf x_t-\mathbf x^\star}_{H_t}^2-2\eta\,\mathbf g_t^\top(\mathbf x_t-\mathbf x^\star)+\eta^2\norm{\mathbf g_t}_{H_t^{-1}}^2

    One step. Projection onto a convex set in the HtH_t-norm does not increase HtH_t-distances to points of the set, so for the comparator x⋆∈X\mathbf x^\star\in\mathcal X:

  2. ft(xt)−ft(x⋆) ≤ ∥xt−x⋆∥Ht2−∥xt+1−x⋆∥Ht22η+η2∥gt∥Ht−12f_t(\mathbf x_t)-f_t(\mathbf x^\star)\ \le\ \frac{\norm{\mathbf x_t-\mathbf x^\star}_{H_t}^2-\norm{\mathbf x_{t+1}-\mathbf x^\star}_{H_t}^2}{2\eta}+\frac\eta2\norm{\mathbf g_t}_{H_t^{-1}}^2

    Rearrange, and use convexity, ft(xt)−ft(x⋆)≤gt⊤(xt−x⋆)f_t(\mathbf x_t)-f_t(\mathbf x^\star)\le\mathbf g_t^\top(\mathbf x_t-\mathbf x^\star):

  3. ∑t=1T(∥xt−x⋆∥Ht2−∥xt+1−x⋆∥Ht2) ≤ ∑t=1T∥xt−x⋆∥Ht−Ht−12 ≤ D∞2Tr⁡(HT)=D∞2∑i∥g1:T,i∥2\sum_{t=1}^T\Big(\norm{\mathbf x_t-\mathbf x^\star}_{H_t}^2-\norm{\mathbf x_{t+1}-\mathbf x^\star}_{H_t}^2\Big)\ \le\ \sum_{t=1}^T\norm{\mathbf x_t-\mathbf x^\star}_{H_t-H_{t-1}}^2\ \le\ D_\infty^2\Tr(H_T)=D_\infty^2\sum_i\norm{\mathbf g_{1:T,i}}_2

    Distance terms. Summed over tt, these do not telescope exactly because the norm changes each round. What is left is controlled by the growth of HtH_t, which is diagonal and nondecreasing (set H0=0H_0=0):

  4. ∑t=1TatAt ≤ 2AT⟹∑t=1T∥gt∥Ht−12 ≤ 2∑i∥g1:T,i∥2\sum_{t=1}^T\frac{a_t}{\sqrt{A_t}}\ \le\ 2\sqrt{A_T}\qquad\Longrightarrow\qquad\sum_{t=1}^T\norm{\mathbf g_t}_{H_t^{-1}}^2\ \le\ 2\sum_i\norm{\mathbf g_{1:T,i}}_2

    Gradient terms. Coordinate by coordinate these are ∑tgt,i2/At,i\sum_tg_{t,i}^2/\sqrt{A_{t,i}}. For nonnegative ata_t with partial sums AtA_t, At−At−1=at/(At+At−1)≥at/(2At)\sqrt{A_t}-\sqrt{A_{t-1}}=a_t/(\sqrt{A_t}+\sqrt{A_{t-1}})\ge a_t/(2\sqrt{A_t}), so the sum telescopes:

  5. RT ≤ (D∞22η+η)∑i=1d∥g1:T,i∥2=2 D∞∑i=1d∥g1:T,i∥2R_T\ \le\ \Big(\frac{D_\infty^2}{2\eta}+\eta\Big)\sum_{i=1}^d\norm{\mathbf g_{1:T,i}}_2=\sqrt2\,D_\infty\sum_{i=1}^d\norm{\mathbf g_{1:T,i}}_2

    Combine the two sums and choose η=D∞/2\eta=D_\infty/\sqrt2, which balances them:

What the bound buys. Online gradient descent with the best fixed step chosen in hindsight guarantees RT≤D2(∑i∥g1:T,i∥22)1/2R_T\le D_2\big(\sum_i\norm{\mathbf g_{1:T,i}}_2^2\big)^{1/2}, with D2D_2 the Euclidean diameter. On the box X=[−1,1]d\mathcal X=[-1,1]^d, D∞=2D_\infty=2 while D2=2dD_2=2\sqrt d, and by Cauchy–Schwarz ∑i∥g1:T,i∥2≤d (∑i∥g1:T,i∥22)1/2\sum_i\norm{\mathbf g_{1:T,i}}_2\le\sqrt d\,\big(\sum_i\norm{\mathbf g_{1:T,i}}_2^2\big)^{1/2}. So AdaGrad's bound is never more than 2\sqrt2 times that tuned bound, needs no knowledge of the gradient sequence, and is far smaller when a few coordinates carry most of the gradient mass while many others are rarely active: sparse, heavy-tailed features, as in text and click data.

Think first On the box [−1,1]d[-1,1]^d with d=10,000d=10{,}000, coordinate ii of the gradient is ±1\pm1 in a fraction 1/i21/i^2 of the rounds and 00 otherwise. Compare the two bounds.

Now ∥g1:T,i∥2≈T/i\norm{\mathbf g_{1:T,i}}_2\approx\sqrt T/i. AdaGrad: 22 T∑i1/i≈22⋅9.79T≈27.7T2\sqrt2\,\sqrt T\sum_i1/i\approx2\sqrt2\cdot9.79\sqrt T\approx27.7\sqrt T. Tuned online gradient descent: 2d T (∑i1/i2)1/2≈200⋅1.28T≈257T2\sqrt d\,\sqrt T\,\big(\sum_i1/i^2\big)^{1/2}\approx200\cdot1.28\sqrt T\approx257\sqrt T. AdaGrad's guarantee is about 99 times smaller, and the ratio grows like d/log⁡d\sqrt d/\log d. If instead every coordinate were active in every round, AdaGrad's bound would be 2\sqrt2 times larger: adaptivity pays off for uneven gradients.

When Adam fails: the counterexample

Adam replaces AdaGrad's sum by an exponential average, vt=β2vt−1+(1−β2)gt2v_t=\beta_2v_{t-1}+(1-\beta_2)g_t^2. In AdaGrad the effective learning rate ηt/v^t\eta_t/\sqrt{\hat v_t} can only shrink; with a short memory it can grow again whenever recent gradients are small. Kingma & Ba's (2015) original convergence analysis implicitly relied on it shrinking, and Reddi, Kale & Kumar (2018) showed that the gap is real, with a problem small enough to work out by hand.

DerivationAdam converges to the worst point
  1. ft(x)={Cx,t≡1 (mod 3)−x,otherwise∑one cycleft(x)=(C−2) xf_t(x)=\begin{cases}Cx, & t\equiv1\ (\mathrm{mod}\ 3)\\ -x, & \text{otherwise}\end{cases}\qquad\sum_{\text{one cycle}}f_t(x)=(C-2)\,x

    Let X=[−1,1]\mathcal X=[-1,1], fix C>2C>2 and present the losses cyclically. Each cycle of three rounds sums to (C−2)x(C-2)x, so the best fixed point is x⋆=−1x^\star=-1:

  2. va=β2vc+(1−β2)C2,vb=β2va+(1−β2),vc=β2vb+(1−β2)v_a=\beta_2v_c+(1-\beta_2)C^2,\qquad v_b=\beta_2v_a+(1-\beta_2),\qquad v_c=\beta_2v_b+(1-\beta_2)

    Run Adam with β1=0\beta_1=0, β2=1/(1+C2)\beta_2=1/(1+C^2) and steps ηt=η/t\eta_t=\eta/\sqrt t (bias correction is negligible after a few rounds). The second moment forgets quickly and settles into a three-round cycle; with C=3C=3, so β2=0.1\beta_2=0.1, it reads v≈8.21v\approx8.21 after the large gradient and 1.721.72, then 1.071.07, after the two small ones:

  3. −Cva+1vb+1vc ≈ −1.05+0.76+0.97=+0.68-\frac C{\sqrt{v_a}}+\frac1{\sqrt{v_b}}+\frac1{\sqrt{v_c}}\ \approx\ -1.05+0.76+0.97=+0.68

    The informative large gradient is normalized away. In units of ηt\eta_t, the round with gradient CC moves xx by about 1.051.05 toward the optimum, and the two rounds with gradient −1-1 move it by about 0.76+0.970.76+0.97 away from it: a net drift of about +0.68 ηt+0.68\,\eta_t per cycle toward x=+1x=+1.

  4. v^t AMS=max⁡(v^t−1 AMS, vt)\hat v_t^{\,\mathrm{AMS}}=\max\big(\hat v_{t-1}^{\,\mathrm{AMS}},\,v_t\big)

    Since ∑tη/t\sum_t\eta/\sqrt t diverges, the drift pushes the iterates to x=+1x=+1, the worst point of X\mathcal X, where each cycle costs 2(C−2)2(C-2) more than x⋆x^\star; hence RT/T→2(C−2)/3>0R_T/T\to2(C-2)/3>0. AMSGrad keeps a running maximum of the second moment, so the effective step can only shrink, and on this problem it converges to −1-1.

Predict before you look

In the counterexample with C=3C=3, once Adam sits at x=+1x=+1, what is its average regret per round against x⋆=−1x^\star=-1?

Show the answer

0.67

Per cycle the losses sum to (C−2)x=x(C-2)x=x, so Adam pays +1+1 while x⋆x^\star pays −1-1: a difference of 22 every three rounds, about 0.670.67 per round, forever. A no-regret method drives this average to 00.

How much does this matter in practice? The construction ties β2\beta_2 to the problem: it needs a short memory, β2=1/(1+C2)\beta_2=1/(1+C^2). With the usual β2=0.99\beta_2=0.99 or 0.9990.999, Adam reaches x⋆=−1x^\star=-1 on this very example. Zhang, Chen, Shi, Sun & Luo (2022) proved that, without changing the update rule, Adam converges to a neighborhood of critical points when β2\beta_2 is large enough and β1<β2\beta_1<\sqrt{\beta_2}, and that a small β2\beta_2 can indeed make it diverge. Défossez, Bottou, Bach & Usunier (2022) proved that, with suitably chosen parameters, Adam drives the average squared gradient norm of a smooth nonconvex objective with bounded gradients down at the rate O(dln⁡N/N)\order{d\ln N/\sqrt N} after NN steps, the same rate they prove for AdaGrad. The counterexample exposes a real mechanism, the forgetting of rare large gradients, rather than a typical failure.

What Adam's step does: sign, noise and warmup

Per coordinate, Adam steps by η m^/v^\eta\,\hat m/\sqrt{\hat v}, with m^≈Eg\hat m\approx\E g and v^≈Eg2=(Eg)2+Var⁡g\hat v\approx\E g^2=(\E g)^2+\Var g. Writing μ\mu and σ\sigma for the mean and standard deviation of a coordinate's gradient, the average step is

m^v^ ≈ μμ2+σ2=sign⁡(μ)1+σ2/μ2.\frac{\hat m}{\sqrt{\hat v}}\ \approx\ \frac{\mu}{\sqrt{\mu^2+\sigma^2}}=\frac{\sign(\mu)}{\sqrt{1+\sigma^2/\mu^2}}.

When the signal dominates (∣μ∣≫σ\abs\mu\gg\sigma) the step is about η sign⁡(μ)\eta\,\sign(\mu); when noise dominates it shrinks to about η∣μ∣/σ\eta\abs\mu/\sigma. Balles & Hennig (2018) made this decomposition precise: Adam is a sign method whose step length adapts to the gradient's signal-to-noise ratio. With β1=β2=0\beta_1=\beta_2=0 and ε→0\varepsilon\to0 it is exactly sign descent, x←x−η sign⁡(g)\mathbf x\leftarrow\mathbf x-\eta\,\sign(\mathbf g), the steepest-descent direction for the ℓ∞\ell_\infty norm, since arg min⁡∥d∥∞≤1g⊤d=−sign⁡(g)\argmin_{\norm{\mathbf d}_\infty\le1}\mathbf g^\top\mathbf d=-\sign(\mathbf g). Mirror Descent & Natural Gradient develops this geometric view.

Warmup and RAdam. In the first steps v^\hat v averages very few squared gradients, so the adaptive learning rate η/v^\eta/\sqrt{\hat v} is itself highly variable, and the early updates are erratic. Liu et al. (2020) quantified this variance and proposed RAdam, which switches the adaptive scaling on gradually through a rectification factor derived from it; a linear warmup of η\eta over the first steps (a learning-rate schedule) has a similar effect and is standard practice for transformers. Large early gradients and sharp regions of the loss early in training are other proposed reasons why warmup helps, and their relative importance is still debated.

Weight decay and generalization

DerivationAn L2 penalty versus decoupled weight decay
  1. x−η(∇f+λx)=(1−ηλ) x−η∇f\mathbf x-\eta\big(\nabla f+\lambda\mathbf x\big)=(1-\eta\lambda)\,\mathbf x-\eta\nabla f

    For SGD, the gradient of f+λ2∥x∥2f+\frac\lambda2\norm{\mathbf x}^2 produces a multiplicative shrink followed by a gradient step, so the penalty and weight decay coincide:

  2. x←x−ηP−1(∇f+λx)⟹xi←(1−ηλPii)xi−ηPii ∂if\mathbf x\leftarrow\mathbf x-\eta P^{-1}\big(\nabla f+\lambda\mathbf x\big)\quad\Longrightarrow\quad x_i\leftarrow\Big(1-\frac{\eta\lambda}{P_{ii}}\Big)x_i-\frac\eta{P_{ii}}\,\partial_if

    With a diagonal preconditioner P=diag⁡(v^)+εIP=\diag(\sqrt{\hat{\mathbf v}})+\varepsilon I (momentum set aside for simplicity), the penalty's gradient is preconditioned as well, and coordinate ii shrinks by ηλ/Pii\eta\lambda/P_{ii}: least where gradients have been largest.

  3. x←(1−ηλ) x−ηP−1m^(AdamW)\mathbf x\leftarrow(1-\eta\lambda)\,\mathbf x-\eta P^{-1}\hat{\mathbf m}\qquad\text{(AdamW)}

    AdamW applies the decay outside the preconditioner, so every coordinate shrinks by the same factor. Heuristically, at a fixed point m^≈∇f\hat{\mathbf m}\approx\nabla f and P−1∇f+λx=0P^{-1}\nabla f+\lambda\mathbf x=\mathbf 0, a stationary point of f+λ2x⊤Pxf+\frac\lambda2\mathbf x^\top P\mathbf x with PP frozen: a weighted L2 penalty that is strongest where gradients are largest. The L2-in-the-loss version keeps the fixed points of the plain penalty, ∇f+λx=0\nabla f+\lambda\mathbf x=\mathbf 0; what differs across its coordinates is how fast each weight decays on the way there.

Do adaptive methods generalize worse? Wilson, Roelofs, Stern, Srebro & Recht (2017) designed a separable classification problem with more features than examples on which the outcome depends on the optimizer: gradient descent started at zero finds a solution that predicts new points correctly, while AdaGrad, RMSProp and Adam settle on a different solution that generalizes poorly. They also reported adaptive methods generalizing worse than tuned SGD on several image and language benchmarks. The mechanism is implicit bias: among the many solutions that fit the data, each optimizer's geometry selects a different one (The Implicit Bias of Gradient Descent).

Later work complicated the picture. Choi et al. (2019) argued that a more general optimizer should never lose to the special cases it contains once every hyperparameter, Adam's ε\varepsilon included, is tuned, and found exactly that, so many reported gaps reflected tuning protocols. On transformers the gap runs the other way: Adam trains them markedly better than SGD. Heavy-tailed gradient noise was proposed as the reason (Zhang et al., 2020); Kunstner et al. (2023) found that noise is not the main factor, since the gap persists as the batch grows, and that at large batch sizes Adam behaves like sign descent with momentum. As of the mid-2020s the question is open.

Check your understanding

Which statement about weight decay is correct?

  1. With plain SGD, an L2 penalty and decoupled weight decay coincide once λ\lambda is matched to the learning rate; with Adam they do not
  2. Adam with an L2 penalty in the loss decays every weight at the same relative rate
  3. AdamW's decay acts most strongly on weights with small gradients
  4. Decoupled weight decay changes the gradients that Adam's moment estimates see
Show the answer

A. With plain SGD, an L2 penalty and decoupled weight decay coincide once λ\lambda is matched to the learning rate; with Adam they do not

Plain SGD folds the penalty's gradient into the shrink factor 1−ηλ1-\eta\lambda, so the two are the same update. Adam divides the penalty's gradient by v^\sqrt{\hat v} together with the loss's, which is why Loshchilov & Hutter (2019) moved the decay outside the adaptive scaling.

Key takeaways

  • Online convex optimization measures regret against the best fixed point; online gradient descent has O(DGT)\order{DG\sqrt T} regret, and online-to-batch conversion turns regret bounds into optimization bounds.
  • AdaGrad's regret is at most 2 D∞∑i∥g1:T,i∥2\sqrt2\,D_\infty\sum_i\norm{\mathbf g_{1:T,i}}_2 without any tuning to the data: never much worse than tuned online gradient descent, and far better with sparse, unevenly active features.
  • A short-memory second moment can normalize away rare informative gradients, and Adam then converges to the worst point of a convex problem. AMSGrad's running maximum, or β2\beta_2 close to 11, restores convergence.
  • Adam is a sign method whose step shrinks with the gradient's signal-to-noise ratio; warmup or RAdam tames the noisy early second moments, and AdamW's decoupled decay shrinks every weight at the same rate.
  • Adaptive methods can select worse-generalizing solutions on constructed problems, but tuning explains many reported gaps, and on transformers Adam clearly beats SGD, for reasons still debated.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

AdaGrad's bound 2 D∞∑i∥g1:T,i∥2\sqrt2\,D_\infty\sum_i\norm{\mathbf g_{1:T,i}}_2 is most favorable, compared with online gradient descent, when…

  1. every coordinate's gradient is large in every round
  2. the domain is a Euclidean ball
  3. a few coordinates are active often and most are active rarely, on a domain such as a box where D2≫D∞D_2\gg D_\infty
  4. the losses are strongly convex
Show the answer

C. a few coordinates are active often and most are active rarely, on a domain such as a box where D2≫D∞D_2\gg D_\infty

Sparse, unevenly active coordinates make ∑i∥g1:T,i∥2\sum_i\norm{\mathbf g_{1:T,i}}_2 far smaller than its worst case d(∑i∥g1:T,i∥22)1/2\sqrt d\big(\sum_i\norm{\mathbf g_{1:T,i}}_2^2\big)^{1/2}, and a box has D∞=2D_\infty=2 against D2=2dD_2=2\sqrt d. Both effects favor the per-coordinate bound.

Question 2

In Reddi, Kale & Kumar's counterexample, what goes wrong?

  1. The losses are nonconvex, so Adam finds a poor local minimum
  2. The momentum term overshoots the optimum
  3. The bias correction is missing
  4. A short-memory second moment normalizes away the rare large gradient, so the frequent small gradients win and push the iterate to the worst point
Show the answer

D. A short-memory second moment normalizes away the rare large gradient, so the frequent small gradients win and push the iterate to the worst point

With β2=1/(1+C2)\beta_2=1/(1+C^2), vtv_t is large only right after the gradient CC, so that step is normalized to about ηt\eta_t, while each of the two gradients −1-1 also earns a step of about ηt\eta_t, in the opposite direction. A running maximum (AMSGrad) or a long memory (β2\beta_2 near 11) keeps the effective step from growing back, and the method converges.

Question 3

On one coordinate, mini-batch gradients have mean μ=0.01\mu=0.01 and standard deviation σ=1\sigma=1. Roughly how far does Adam move that coordinate per step on average, in units of η\eta?

  1. About 11
  2. About 0.010.01
  3. About 100100
  4. Exactly 00, because the mean is so small
Show the answer

B. About 0.010.01

m^/v^≈μ/μ2+σ2≈0.01\hat m/\sqrt{\hat v}\approx\mu/\sqrt{\mu^2+\sigma^2}\approx0.01: a noise-dominated coordinate drifts at a rate shrunk by its signal-to-noise ratio. Individual steps fluctuate more, since m^\hat m averages noise over only about 1/(1−β1)1/(1-\beta_1) recent steps, but the fluctuations largely cancel.

Question 4

According to Liu et al. (2020), why can Adam's first steps be erratic without warmup?

  1. v^\hat v averages only a few squared gradients, so the adaptive learning rate η/v^\eta/\sqrt{\hat v} has very high variance early on
  2. Bias correction overshoots in the first steps
  3. Momentum has not yet built up
  4. The weights are initialized too large
Show the answer

A. v^\hat v averages only a few squared gradients, so the adaptive learning rate η/v^\eta/\sqrt{\hat v} has very high variance early on

With one or two samples, v^\sqrt{\hat v} can be far from its typical value, so the per-coordinate learning rate η/v^\eta/\sqrt{\hat v} is very noisy and the early updates are erratic. RAdam rectifies the variance of the adaptive rate; a linear warmup of η\eta has a similar effect.

Further reading

  • J. Duchi, E. Hazan & Y. Singer, "Adaptive subgradient methods for online learning and stochastic optimization," Journal of Machine Learning Research 12, 2121–2159 (2011).
  • D. P. Kingma & J. Ba, "Adam: a method for stochastic optimization," ICLR (2015).
  • S. J. Reddi, S. Kale & S. Kumar, "On the convergence of Adam and beyond," ICLR (2018).
  • I. Loshchilov & F. Hutter, "Decoupled weight decay regularization," ICLR (2019).
  • A. C. Wilson, R. Roelofs, M. Stern, N. Srebro & B. Recht, "The marginal value of adaptive gradient methods in machine learning," Advances in Neural Information Processing Systems 30 (2017).