TL;DR
Adam and similar adaptive optimizers scale each parameter's step by a running estimate of its gradient size. The paper shows that this scale estimate is very noisy in the first few updates, because it is built from only a handful of gradients. That noise, not the model, is why training often needs a warmup. The authors add a computed correction factor to Adam, called RAdam (rectified Adam), that shrinks the adaptive step until enough gradients have been seen.
Builds on: Learning Rate Warmup, Adam Optimizer, Exponential Moving Average · Leads to: AdamW Optimizer
Why it mattered
Adam-style optimizers are the default for training large neural networks, including Transformer language models and the BERT family. Those models were usually trained with a hand-set warmup, a schedule that starts with a tiny learning rate and raises it over the first few epochs. Practitioners tuned the warmup length by trial and error, and nobody could say in advance whether a given setting would work. This paper gives an account of why warmup helps, and it turns the fix into a formula with no warmup length to choose. Its experiments follow the decoupled weight decay of AdamW Optimizer.
The problem
Recall the two parts of an adaptive method. A momentum term averages recent gradients. An adaptive term, called here, divides the step by a running average of squared gradients, so parameters with large gradients take smaller steps. Both are built from data seen so far, so both are noisy at the start.
The paper's observation: in neural machine translation on the IWSLT'14 German-English task with a Transformer, removing the warmup makes the training loss converge around 10 instead of falling below 3. The authors look at the histogram of gradient magnitudes and find it is distorted during the first 10 updates. Vanilla Adam, they argue, lands in a bad local optimum because of those first few steps.
The question is why the first steps are so damaging. The answer is a variance argument. If the gradients are independent draws from a zero-mean Gaussian with variance , the adaptive term after one step is . The square is a chi-squared variable with one degree of freedom, so is a scaled inverse chi-squared variable with one degree of freedom. That distribution has infinite variance. The adaptive step can therefore be arbitrarily large in the first updates.
How it works
The paper's pipeline runs once per parameter, at every update . The numbers below use the paper's default for the second-moment average.
flowchart LR
A[gradient g_t] --> B[update moving averages]
B --> C[compute rho_t from t and beta_2]
C --> D{rho_t greater than 4?}
D -- no --> E[momentum step, no adaptive scaling]
D -- yes --> F[compute rectifier r_t]
F --> G[momentum step times r_t times adaptive rate]
- A gradient arrives for one parameter. Adam-style methods keep two running averages, one of the gradient and one of its square. Nothing is different yet from Adam Optimizer.
- The method asks how many gradients the second-moment average effectively uses. The paper calls this length (rho). Right after the first update, the average uses one gradient. Check: .
- Later, the average covers more gradients and grows. At it approaches a ceiling, . Check: is always below 1999.
- If is 4 or less, the variance of the adaptive term is still too large to use. RAdam then switches the adaptive scaling off and takes a plain momentum step, like Stochastic Gradient Descent with Momentum. Check: for to with , is about 1, 2, 3 and 4, so this branch runs for those updates.
- If is above 4, the method computes a rectifier . It is small when is near 4 and approaches 1 as approaches . Check: at , and .
- The parameter moves by the momentum step times the adaptive rate times . The rectifier makes the variance of the scaled rate constant across updates. Check: the rectifier is about 0.017 at and about 0.215 at , so early steps are far smaller than late ones. The paper reads this as the reason early updates stop being harmful.
Step 5 is the part that replaces warmup. A linear warmup multiplies the learning rate by , which has the same shape as , and the paper argues this is why warmup works.
The math
Let be the second-moment decay, , and for update let . The rectifier is , used only when .
Step 2 in symbols: the length
The exponential moving average with weights is approximated by a simple average over a window of length , chosen so both have the same centre of mass. Solving that condition gives . As grows, rises towards .
Step 3 in symbols: the ceiling
Setting in the formula for leaves . For this is . For it is at most 4, so RAdam never leaves the momentum-only branch and reduces to SGD with momentum.
Step 4 in symbols: the branch
The paper writes the variance of the adaptive term as . This is finite only for . Below that, the variance is treated as intractable and the adaptive term is turned off.
Step 6 in symbols: the rectified step
Multiplying the adaptive term by gives a variance of , and the choice of makes that equal to the constant , the minimum variance the function reaches at . The paper proves this variance decreases monotonically as grows (Theorem 1), so a fixed target is reachable.
Results
The paper evaluates on language modelling (One Billion Word, with 2-layer LSTMs of 2048 hidden units), image classification (CIFAR-10 with ResNet-20, ImageNet with ResNet-18), and neural machine translation (IWSLT'14 De-En and En-De, and WMT'16 En-De, with Transformers).
- Versus vanilla Adam. RAdam beats Adam on all three benchmarks in the paper. On ImageNet, training accuracy is 69.57 for SGD, 69.12 for Adam and 70.30 for RAdam. The authors state that RAdam does not beat SGD on test accuracy.
- Versus warmup. On translation, Table 2 reports BLEU of 34.66 ± 0.014 for Adam with warmup and 34.76 ± 0.003 for RAdam on IWSLT'14 De-En; 28.56 ± 0.067 and 28.48 ± 0.054 on IWSLT'14 En-De; and 27.03 and 27.27 on WMT'16 En-De. The authors describe these as similar. On CIFAR-10, Adam with warmup reaches 91.29 and RAdam 91.38.
- Sensitivity. With learning rate 0.1 and a 100-step warmup, Adam reaches 90.13 on CIFAR-10 and RAdam reaches 91.06. Across learning rates from 0.1 to 0.003, the authors report that RAdam's curves overlap while Adam and SGD vary more.
- Simulation. Over six settings of the gradient mean, with 5000 sampled trajectories and 6000 iterations at , the original adaptive term has large variance early on and the rectified one stays roughly constant.
Limits. The derivation assumes gradients are zero-mean Gaussian, which the paper justifies only at initialisation and then checks by simulation. The exponential average is replaced by a simple average. The fix addresses the variance of the adaptive term only; the paper notes it is orthogonal to gradient clipping, smoothing and normalisation, which can be combined with it. In the first four updates the method is plain momentum, and the appendix shows that switching those updates to Adam hurts test accuracy (89.98 versus 91.08 for RAdam in Table 3). The paper's main claim is mechanistic, and its benchmarks are a handful of tasks, not a full sweep.
Reading guide
- Abstract and Section 1 (Introduction). Needs Learning Rate Warmup and the idea that Adam can land in bad optima.
- Section 2 (Preliminaries). The generic adaptive framework, momentum and adaptive rate . Needs Adam Optimizer and Exponential Moving Average.
- Section 3 (Variance). The one-gradient case uses Gaussian (Normal) Distribution and Chi-Squared Distribution. Theorem 1 relies on the scaled inverse chi-squared form.
- Section 4 (RAdam). Equations 3 to 6 and Algorithm 2. Read the box in "The math" alongside it. Needs Stochastic Gradient Descent and Momentum for the fallback branch.
- Section 5 (Experiments) and Appendix B. Benchmarks and hyperparameters. Background: Transformer and BLEU Score for the translation results, and Deep Residual Learning for Image Recognition (ResNet) for the image models.
- Appendix A (Proof of Theorem 1). Uses the beta function, which is defined through the Gamma Function.
Check yourself
QuestionAt update t = 1 with beta_2 = 0.999, what is rho_1, and why does this make the first adaptive step unreliable?Show answer
rho_1 = 1 by the formula, because the second-moment average uses only one gradient. With one Gaussian gradient the adaptive term is the reciprocal of a chi-squared-type variable with one degree of freedom, which has infinite variance. So the first adaptive step can be arbitrarily large.
QuestionWith beta_2 = 0.999, compute rho_infinity. Show the arithmetic.Show answer
rho_infinity = 2 / (1 - 0.999) - 1 = 2 / 0.001 - 1 = 2000 - 1 = 1999.
QuestionWhy does RAdam reduce to SGD with momentum when beta_2 is at most 0.6?Show answer
For beta_2 at most 0.6, rho_infinity = 2 / (1 - beta_2) - 1 is at most 4. Then rho_t never exceeds 4, so the rectified adaptive branch is never active, and the update is the momentum step alone.
QuestionGive a reason why a linear warmup and the rectifier r_t behave similarly, and say what the paper claims that means.Show answer
Linear warmup multiplies the step by min(t, T_w) / T_w, which starts small and grows, just as r_t starts small and approaches 1. The paper reads this similarity as evidence that warmup works by reducing the variance of the adaptive learning rate, not by some other effect.
QuestionTable 2 reports RAdam at 34.76 and Adam with warmup at 34.66 on IWSLT'14 De-En. Is RAdam clearly better here? Explain using the reported standard deviations.Show answer
The difference is 0.10 BLEU. It is larger than the reported deviations (±0.014 for warmup, ±0.003 for RAdam), but it is small, and the paper itself describes the two methods as performing similarly on translation. Read it as parity, not a clear win, and note that it comes from five random seeds.
Sources
- Liu, Jiang, He, Chen, Liu, Gao, Han (2019). On the Variance of the Adaptive Learning Rate and Beyond. arXiv:1908.03265. https://arxiv.org/abs/1908.03265
- Kingma and Ba (2014). Adam: A Method for Stochastic Optimization. arXiv:1412.6980. https://arxiv.org/abs/1412.6980