Search

Search papers and lessons

On the Convergence of Adam and Beyond

Sashank J. Reddi, Satyen Kale, Sanjiv Kumar · 2019

Reddi, Kale and Kumar show that Adam can fail to converge even on simple convex problems, trace the cause to its moving average of squared gradients, and fix it with AMSGrad.

On this page

  • Colour = topic mix
  • Discrete math
  • Optimizers
  • Probability
  • Calculus
  • Linear algebra
  • Optimization
  • ReadReady to readNot yet

TL;DR

Adam is the default optimizer for training deep networks, and it is usually reliable. This paper shows that its convergence proof was wrong, and that Adam can fail to reach the best answer even on a one-dimensional convex problem. The cause is the exponential moving average of squared gradients: it forgets a rare large gradient so fast that the step size grows back. The authors propose AMSGrad, which keeps the largest value of that average seen so far, so the step size can only shrink, and they prove a regret bound for it.

Builds on: Adam Optimizer, Exponential Moving Average, No-Regret Learning · Leads to: AMSGrad, AdamW Optimizer

Why it mattered

Adam and RMSprop became the standard optimizers for training language models, image networks and recommender systems, and most of the practical tuning advice around them was built on the belief that Adam converges. This paper pointed to a gap between that belief and the mathematics, and it made the failure concrete with a counterexample that a reader can check by hand.

The fix, AMSGrad, changes one line of Adam and keeps its per-parameter step sizes. It is now available in common deep learning libraries as an option. The paper's wider lesson, that an adaptive method needs a step size that does not grow back without limit, shaped later work on adaptive optimizers.

The problem

Plain Stochastic Gradient Descent uses one step size that shrinks over time, and it converges but often slowly. Adaptive methods such as AdaGrad divide each coordinate's step by the root of a sum of its past squared gradients, so coordinates with large gradients take smaller steps. Adagrad's sum only grows, so its step sizes only shrink, which makes convergence safe but can make learning too slow for deep networks.

Adam and RMSprop replace the sum with an exponential moving average, so old gradients fade and the step size can recover. The paper asks what that fading costs. Write the step-size inverse as vt/αt\sqrt{v_t}/\alpha_t, where vtv_t is the moving average of squared gradients. Its change from one step to the next, Γt+1=vt+1/αt+1−vt/αt\Gamma_{t+1} = \sqrt{v_{t+1}}/\alpha_{t+1} - \sqrt{v_t}/\alpha_t, is never negative for SGD or Adagrad, which means their step sizes never grow. For Adam it can be negative, and the paper shows that this is exactly when convergence breaks.

How it works

The paper's counterexample is a sequence of linear losses on the interval [−1,1][-1, 1]. Let the gradient be CC on every third step and −1-1 on the other two, with C>2C > 2. The best fixed point is x=−1x = -1: the gradients sum to a positive slope over each cycle, so the loss is lowest at the left end of the interval. Adam with β1=0\beta_1 = 0 and β2=1/(1+C2)\beta_2 = 1/(1 + C^2) moves to x=+1x = +1 instead, which is the worst point.

  1. Feed a large gradient. On a step with gradient CC, the second-moment average jumps up by (1−β2)C2(1 - \beta_2) C^2, which with β2=1/(1+C2)\beta_2 = 1/(1 + C^2) is almost all of C2C^2. The step is scaled down, so the large gradient is informative but its effect is small.
  2. Forget it quickly. On the next two steps the gradient is −1-1, and each step multiplies the old average by β2\beta_2. The large gradient's contribution fades, so the step size grows back.
  3. Move the wrong way. The two small gradients of −1-1 push xx upward, and with a large step size again, Adam pushes xx toward +1+1. The rare large gradient that points toward −1-1 arrives too late and too weakly to reverse this.
  4. Repeat. Each cycle of three steps repeats the pattern, so the iterate stays near the worst point. Its average regret, the total loss minus the loss of the best fixed point in hindsight, divided by the number of steps (see No-Regret Learning), does not go to zero.

AMSGrad changes one thing. It keeps the running maximum v^t=max⁡(v^t−1,vt)\hat{v}_t = \max(\hat{v}_{t-1}, v_t) and divides by v^t\hat{v}_t instead of vtv_t. A spike in vtv_t is then remembered for as long as it stays the largest value seen, so the step size cannot grow back in step 2 above.

12345602468step tsecond-moment value
  • Adam v_t
  • AMSGrad v-hat_t
Adam's average falls back after a large gradient; AMSGrad's maximum does not, so its step size stays small.

Worked examples

Example
Example 1: Adam's average forgets a spike

Use the counterexample with C=3C = 3, so β2=1/(1+9)=0.1\beta_2 = 1/(1 + 9) = 0.1 and β1=0\beta_1 = 0. The gradients on steps 1, 2 and 3 are g1=3g_1 = 3, g2=−1g_2 = -1 and g3=−1g_3 = -1, because step 1 is the step with t mod 3=1t \bmod 3 = 1. Start from v0=0v_0 = 0. Find v1v_1, v2v_2 and v3v_3.

  1. Step 1: v1=0.1×0+0.9×32=0.9×9=8.1v_1 = 0.1 \times 0 + 0.9 \times 3^2 = 0.9 \times 9 = 8.1.
  2. Step 2: v2=0.1×8.1+0.9×(−1)2=0.81+0.9=1.71v_2 = 0.1 \times 8.1 + 0.9 \times (-1)^2 = 0.81 + 0.9 = 1.71.
  3. Step 3: v3=0.1×1.71+0.9×1=0.171+0.9=1.071v_3 = 0.1 \times 1.71 + 0.9 \times 1 = 0.171 + 0.9 = 1.071.
  4. Check: the spike's share fell from 8.1 to 1.71 to 1.071, so by step 3 the average is only a little above what the small gradients alone would give.

Interpretation: after one spike of size 3, Adam's average has dropped to about a seventh of its peak within two steps. The next step size is no longer damped by the spike.

Example
Example 2: AMSGrad keeps the spike

Continue the same sequence to step 4, where the large gradient returns, and compare Adam's vtv_t with AMSGrad's v^t\hat{v}_t.

  1. Step 4: g4=3g_4 = 3, so v4=0.1×1.071+0.9×9=0.1071+8.1=8.2071v_4 = 0.1 \times 1.071 + 0.9 \times 9 = 0.1071 + 8.1 = 8.2071.
  2. Adam's value on step 4 is 8.20718.2071, which is almost the same as the spike on step 1, because the average was reset by the new large gradient.
  3. AMSGrad's value: v^1=8.1\hat{v}_1 = 8.1, v^2=max⁡(8.1,1.71)=8.1\hat{v}_2 = \max(8.1, 1.71) = 8.1, v^3=max⁡(8.1,1.071)=8.1\hat{v}_3 = \max(8.1, 1.071) = 8.1, and v^4=max⁡(8.1,8.2071)=8.2071\hat{v}_4 = \max(8.1, 8.2071) = 8.2071.
  4. Check: v^t\hat{v}_t never falls in this run, so the AMSGrad step size on steps 2 and 3 uses 8.1, not 1.71 or 1.071.

Interpretation: AMSGrad's steps on the small gradients are about 8.1/1.71=2.2\sqrt{8.1} / \sqrt{1.71} = 2.2 times smaller than Adam's on step 2, which is the damping that prevents the drift toward +1+1.

Example
Example 3: the average gradient decides the answer

The paper's synthetic experiment uses ft(x)=1010xf_t(x) = 1010x on steps with t mod 101=1t \bmod 101 = 1 and ft(x)=−10xf_t(x) = -10x otherwise, on F=[−1,1]\mathcal{F} = [-1, 1]. Find the best point and explain why an algorithm that trusts the typical gradient can be misled.

  1. Over one period of 101 steps, the total gradient coefficient is 1010+100×(−10)=1010−1000=101010 + 100 \times (-10) = 1010 - 1000 = 10.
  2. The average is 10/101=0.09910 / 101 = 0.099, which is positive. A linear loss with positive average slope is smallest at the left end, so the best point is x=−1x = -1.
  3. Most steps push xx toward +1+1, since their gradient is −10x-10x with a negative coefficient. Only one step in 101 pushes toward −1-1, and it is the large one.
  4. Adam's step on the rare spike is damped by the average it has built up, so the many small steps win and xx drifts to +1+1. AMSGrad keeps the spike in its maximum and so keeps the big correction in effect.
  5. Try it: if the spike were 500500 instead of 10101010 and the rest unchanged, what is the best point? Answer: the total is 500−1000=−500500 - 1000 = -500, which is negative, so the average slope is negative and the best point is x=+1x = +1. The optimum is set by the size of the rare spike, which an adaptive method has to notice.

The math

Notation: gt=∇ft(xt)g_t = \nabla f_t(x_t) is the gradient at step tt. Adam keeps a first-moment average mt=β1mt−1+(1−β1)gtm_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t and a second-moment average vt=β2vt−1+(1−β2)gt2v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2, with β1,β2∈[0,1)\beta_1, \beta_2 \in [0, 1). The iterate is xt+1=ΠF,Vt(xt−αtmt/vt)x_{t+1} = \Pi_{\mathcal{F}, \sqrt{V_t}}(x_t - \alpha_t m_t / \sqrt{v_t}), where Π\Pi projects back onto the feasible set F\mathcal{F} and αt\alpha_t is the step size.

Step 1 in symbols: the large gradient enters vtv_t

With β1=0\beta_1 = 0 the first moment is just mt=gtm_t = g_t. The second moment after the large gradient is vt=β2vt−1+(1−β2)C2v_t = \beta_2 v_{t-1} + (1 - \beta_2) C^2. With β2=1/(1+C2)\beta_2 = 1/(1 + C^2) the new term is (1−β2)C2=C2/(1+C2)(1 - \beta_2) C^2 = C^2 / (1 + C^2), a little less than 11.

Step 2 in symbols: the forgetting

After the large gradient, each step multiplies the old value by β2\beta_2. Over kk steps the large gradient's share of vv is multiplied by β2k\beta_2^k. Adam's step on a later small gradient is αt⋅(−1)/vt\alpha_t \cdot (-1) / \sqrt{v_t}, which is large whenever vtv_t has forgotten the spike.

Step 3 in symbols: the indefinite Γt\Gamma_t

The paper's key quantity is Γt+1=vt+1/αt+1−vt/αt\Gamma_{t+1} = \sqrt{v_{t+1}}/\alpha_{t+1} - \sqrt{v_t}/\alpha_t. For a non-increasing learning rate this is nonnegative. Adam's moving average does not guarantee that, so Γt\Gamma_t can be negative, and the convergence proof of Adam, which assumed nonnegativity, does not apply. Theorem 1 of the paper gives a convex problem where Adam's average regret RT/TR_T / T does not go to zero.

Step 4 in symbols: AMSGrad

v^t=max⁡(v^t−1,vt),xt+1=ΠF,V^t(xt−αtmt/v^t)\hat{v}_t = \max(\hat{v}_{t-1}, v_t), \qquad x_{t+1} = \Pi_{\mathcal{F}, \sqrt{\hat{V}_t}} \left( x_t - \alpha_t m_t / \sqrt{\hat{v}_t} \right)

Because v^t\hat{v}_t never decreases, the effective step size is non-increasing, so Γt⪰0\Gamma_t \succeq 0 holds for every tt even with a constant β2\beta_2. Theorem 4 bounds the regret of AMSGrad by a sum of three terms: one proportional to T\sqrt{T} times the sum of the square roots of the final v^T,i\hat{v}_{T,i}, one from the momentum decay, and one from the gradient history. With the more modest momentum decay β1t=β1/t\beta_{1t} = \beta_1 / t, the bound is O(T)O(\sqrt{T}) (Corollary 1), which the paper compares with the O(dT)O(\sqrt{dT}) regret of SGD: the AMSGrad bound can be better when the final v^T,i\hat{v}_{T,i} are small.

Results

The paper's theorems are the main results. Theorem 1 shows a convex online problem, the one in the counterexample, where Adam's average regret does not go to zero. Theorem 2 extends this to any constant β1,β2\beta_1, \beta_2 with β1<β2\beta_1 < \sqrt{\beta_2}, and Theorem 3 gives a stochastic version in which Adam does not converge to the optimum. The paper also states that adding a small constant ϵ\epsilon to the denominator does not remove the problem for constant ϵ>0\epsilon > 0 (Theorem 6 in its appendix). Theorem 4 proves the regret bound for AMSGrad, and Corollary 1 gives the O(T)O(\sqrt{T}) form under a decaying momentum schedule.

The experiments are preliminary, and the paper says so. On the synthetic problem, Adam's average regret stays away from zero and its iterate converges to x=+1x = +1, while AMSGrad's regret goes to zero and its iterate reaches x=−1x = -1. On multiclass logistic regression on MNIST, with minibatches of 128 and β1=0.9\beta_1 = 0.9, the paper reports AMSGrad with lower training and test loss than Adam. The paper also compares the two on a one-hidden-layer network with 100 ReLU units on MNIST (Figure 2, with constant step size and a grid search over parameters). On the Cifarnet convolutional network on CIFAR-10, the paper reports AMSGrad performs considerably better than Adam on training loss and accuracy, and that the gain carries over to test loss. The paper reports that AMSGrad was less sensitive to the choice of parameters.

The limits are important. The counterexamples are constructed, and the authors say that real training is not one of them, although they argue such behaviour could slow learning. The regret bound is for convex problems. Theorem 4 allows β1t≤β1\beta_{1t} \le \beta_1, so a constant β1\beta_1 is covered, but the bound's O(T)O(\sqrt{T}) form needs the decaying schedule β1/t\beta_1 / t. The paper's own AdamNc variant changes β2\beta_2 over time to get a convergence bound without changing the algorithm's structure. Nothing here proves that AMSGrad is the best fix for deep networks. It proves that Adam as stated can fail, and that a simple change removes the failure on the problems studied.

Reading guide

  • Section 1, Introduction: the story of adaptive methods, from AdaGrad to Adam Optimizer and RMSProp. Read it with the Exponential Moving Average lesson in mind.
  • Section 2, Preliminaries: the online setting and regret. No-Regret Learning explains why average regret going to zero is the target. The generic adaptive framework in Algorithm 1 is the template that Adam and AMSGrad both fit.
  • Section 3, The Non-Convergence of Adam: the counterexample and Theorems 1 to 3. Work through the three-step cycle of Example 1 before reading the proof sketch. The condition β1<β2\beta_1 < \sqrt{\beta_2} is the one to watch.
  • Section 4, AMSGrad: Algorithm 2 and Theorem 4. The one-line change is the maximum v^t\hat{v}_t. AMSGrad has the algorithm in full.
  • Section 5, Experiments: the synthetic problem, then logistic regression, a small network and Cifarnet. The Logistic Regression and Cross-Entropy Loss lessons cover the first experiment's model.
  • Appendix: the proofs. Read them only after Section 4 is clear.

Check yourself

QuestionIn one sentence, what does Adam get wrong in the counterexample, and what does AMSGrad change to fix it?Show answer

Adam lets a rare large gradient's effect in its second-moment average fade within a few steps, so the step size grows back and small gradients push the iterate to the worst point. AMSGrad keeps the running maximum of the second-moment average and divides by that, so the step size cannot increase after a large gradient, and Γt\Gamma_t stays nonnegative.

QuestionWith beta2 = 0.1 and the second-moment average at 8.1 after a spike, what is the value after two steps of gradient -1, with the average starting from 8.1 at step 1?Show answer

Step 2 gives 0.1×8.1+0.9×1=1.710.1 \times 8.1 + 0.9 \times 1 = 1.71. Step 3 gives 0.1×1.71+0.9×1=1.0710.1 \times 1.71 + 0.9 \times 1 = 1.071. After two small steps the average is 1.071, so the spike's contribution has fallen by a factor of about eight.

QuestionWhy does the paper's Gamma quantity matter for convergence?Show answer

Gamma is the change in the inverse learning rate from one step to the next. When it is nonnegative, the learning rate never grows, and the standard regret argument works. Adam's moving average can make Gamma negative, which breaks the assumption in its published proof and allows the step size to grow back.

QuestionIn the synthetic problem with a spike of 1010 and small slope -10 on 100 of 101 steps, why is the best point -1 even though most steps push toward +1?Show answer

The average over a period is (1010−1000)/101=0.099(1010 - 1000) / 101 = 0.099, a positive slope. For a linear loss with positive average slope the minimum over [−1,1][-1, 1] is at x=−1x = -1. The rare large gradient carries enough total weight to outweigh the many small ones, so a method must keep that weight in its steps.

Sources

Read the full paper

Sashank J. Reddi, Satyen Kale, Sanjiv Kumar, 2019. arXiv:1904.09237