TL;DR
AMSGrad is a training rule for neural networks. It is Adam with one change: when it divides the averaged gradient by the square root of the averaged squared gradient, it uses the largest such average seen so far, not the current one. That keeps each parameter's step size from growing again after a large gradient has passed. Reddi, Kale and Kumar introduced it to fix a convergence gap in Adam.
Builds on: Adam Optimizer, Exponential Moving Average, Gradient Descent · Leads to: On the Convergence of Adam and Beyond
Where it's used
Training deep networks in practice. Adam is the default optimizer for many deep-learning projects, and AMSGrad is offered as a switch on the same optimizer in common libraries (PyTorch exposes it as a flag on its Adam class). Teams turn it on when Adam's training loss stops improving or oscillates late in training.
Rare, large gradients. The paper's counterexample is built around one parameter that receives a huge gradient only occasionally, with small, opposite gradients the rest of the time. That is the pattern in which Adam's steps can drift the wrong way, as the third worked example shows.
Convex benchmarks and theory. Researchers use AMSGrad where a guarantee matters. The paper proves a regret bound of order for it, where is the largest gradient size allowed by its assumptions. That is the same rate that plain gradient methods achieve on convex problems, so the online-learning guarantee holds.
How it works
We will trace one parameter through a few steps, with a learning rate , the first average (the Momentum term) using so that is just the latest gradient, and the second average using . The second average is set to decay fast on purpose, so the difference is easy to see in a few steps. Real training uses . We also drop Adam's bias correction, which only matters at the first few steps.
-
Start. Set , and , where is the running maximum of . The gradient at step 1 is . Check: nothing has been seen yet, so every average is zero.
-
Step 1: a big gradient. Update the averages: and . Then . The step is . Check: Adam takes the same step here, since its current is also .
-
Step 2: a small gradient. The gradient is . Update: , and . Now the two methods split. AMSGrad keeps the memory of the big step: , so its step is . Adam uses the current , and its step is . Check: the denominator of AMSGrad is larger, so its step is smaller, and it is the only one that remembers the spike.
-
Step 3: the gradient returns to 0.1. Update Adam's average: . Adam's step is . AMSGrad keeps , so its step stays at . Check: Adam's step is growing again even though the gradient has not changed. That is the behaviour AMSGrad removes.
- step = 0.1 times 0.1 over sqrt(v)
The math
The update rule
Let be the gradient at step . Let be the learning rate, and the decay rates of the two averages, and a small constant that prevents division by zero. Adam keeps two averages, of the gradient and of its square:
Adam then steps by . AMSGrad changes one line. It keeps a running maximum of :
Implementations keep the small , as Adam does, so that the denominator is never zero.
Step 2 and Step 3 in symbols: the memory
Because is a maximum, it never decreases: . So the effective learning rate
is non-increasing in . In the trace above, , so stays at . Adam's effective rate is , which rises when falls. That rise is the source of Adam's trouble.
Why the rise is harmful
Suppose a coordinate has . The paper observes that Adam then increases its effective rate, because the denominator shrinks. AdaGrad, which sums all past squared gradients, shrinks its rate slightly. AMSGrad keeps the rate unchanged in this case, because the maximum already exceeds , so its denominator cannot shrink. The paper's convergence argument needs a certain matrix , built from these averages, to be positive semi-definite. For Adam that is not guaranteed. For AMSGrad it holds at every step.
The bound
Under its assumptions (bounded feasible set, gradients bounded by , and a decreasing schedule for ), the paper proves a regret bound of order for AMSGrad. Regret is the total extra loss compared with the best fixed choice in hindsight. A bound of this order means the average regret per step goes to zero.
Worked examples
Use , , , and gradients , .
- Step 1: , so . The step is .
- Step 2 for Adam: . The step is .
- Step 2 for AMSGrad: . The step is .
- Interpretation: the gradient did not change between the two methods, but Adam's step is bigger because it forgot the spike.
Continue the same run with .
- Adam: . Step: .
- AMSGrad: . Step: .
- Compare the sequence of Adam steps: , then , then . The step is rising while the gradient is flat.
- Compare the AMSGrad steps: , then , then . The step never rises.
- Interpretation: after a large gradient, Adam's effective learning rate climbs back up as its average forgets the spike. AMSGrad keeps the cautious rate.
The paper gives a simple online problem on the interval . On one step in every 100 the loss is , and on the other 99 steps it is . The gradient is therefore on about one step in 100 and otherwise. Averaged over time, the loss is about , so the best point is .
- The expected gradient is .
- A positive expected gradient means the average step pushes downward, towards , which is correct.
- Adam's forgets slowly, with . The rare gradient adds to , while each gradient of adds only . So the rare spike dominates Adam's denominator for a long time, and the paper shows that Adam's steps can drift the wrong way and end near .
- AMSGrad keeps the large in , so the common small gradients do not produce ever-larger steps.
Try it: suppose the rare gradient occurs with probability instead, and the other gradient is still . Find the expected gradient and say which end of the average step pushes towards.
Answer: the expected gradient is . It is negative, so the average step pushes upward, towards , which is now the best point.
Common mistakes and tradeoffs
"AMSGrad always trains faster than Adam." It is tempting to think a convergence fix means better results. In fact, the paper's guarantee is about worst cases and regret. On its experiments, AMSGrad often matches or improves on Adam, but the gap depends on the problem, so check it on yours.
"Adam is broken, so never use it." The paper's counterexamples are specially built. Adam works well on most deep-learning problems, and the paper's fix is a one-line change. Choose between them on validation performance, not on the proof.
"AMSGrad uses a constant learning rate." It is tempting to read "the step never grows" as "the step is fixed". In fact the effective rate is only non-increasing. It can still fall a lot, which is useful but can also slow training down.
The cost of a spike. Because is a maximum, one very large early gradient keeps the step small for the rest of training. Adam forgets it over roughly steps, which is about a thousand steps when . AMSGrad does not forget it at all, unless a later gradient is larger. Gradient clipping, which caps the size of each gradient at a fixed value, is one common remedy.
When to use it: when Adam's loss oscillates late in training, or when you need the convergence guarantee. When not to use it: when early training speed matters most, or when rare large gradients are expected and you do not want their effect to last. Alternatives: Adam with a smaller learning rate, a schedule that decays the learning rate, gradient clipping, or the paper's own alternative of letting change with .
History
Adaptive methods of this kind grew out of AdaGrad, which scales each coordinate by the square root of all its past squared gradients. That scaling shrinks the rate too much over long runs. RMSprop and then Adam replaced the sum with exponential averages, so the rate can recover. Kingma and Ba introduced Adam in 2014, and it became the default in much of deep learning.
Reddi, Kale and Kumar then analysed Adam's convergence proof and found an error: the proof needs a quantity to be positive semi-definite, and it is not in general. They gave a small convex counterexample where Adam fails to converge, and they proposed AMSGrad as the fix. The arXiv version of their paper is from 2019. It caught on because the change is a single line, and because it leaves the rest of Adam, including its averages and its Momentum term, unchanged.
Recap
- Adam divides its averaged gradient by the square root of an averaged squared gradient. When the squared average falls, its effective step rises.
- AMSGrad keeps the running maximum of the squared average, so the effective step never rises again.
- The effect is a non-increasing learning rate, which gives the convergence guarantee and avoids the failure mode in the paper's counterexample.
- The cost is that one large early gradient can keep the step small for the rest of training.
- Next, read On the Convergence of Adam and Beyond for the paper's own argument. For the averaged-square idea without the maximum, see RMSProp.
Check yourself
QuestionRecall: what single change turns Adam into AMSGrad?Show answer
QuestionComputation: with , , , gradients and , what is the AMSGrad step at step 2, to three decimal places?Show answer
QuestionWhy: why can Adam's effective learning rate rise even when the gradient is steady, and why does AMSGrad avoid this?Show answer
QuestionApplied: a team trains a language model with a rare, very large gradient on a few output words, and Adam's loss keeps oscillating late in training. Would switching to AMSGrad help, and what would you check afterwards?Show answer
Sources
- Reddi, Kale and Kumar, On the Convergence of Adam and Beyond, arXiv 2019: https://arxiv.org/abs/1904.09237
- Kingma and Ba, Adam: A Method for Stochastic Optimization, 2014: https://arxiv.org/abs/1412.6980