Search

Search papers and lessons

On the Variance of the Adaptive Learning Rate and Beyond

Liyuan Liu, Haoming Jiang, Pengcheng He et al. · 2019

Liu et al. (2019) show that Adam's adaptive step size has huge variance early in training, explain why learning rate warmup helps, and propose RAdam, which switches that variance off by a computed factor.

On this page

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

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 ψ\psi 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 σ2\sigma^2, the adaptive term after one step is ψ=1/g12\psi = \sqrt{1/g_1^2}. The square g12/σ2g_1^2/\sigma^2 is a chi-squared variable with one degree of freedom, so 1/g121/g_1^2 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 tt. The numbers below use the paper's default β2=0.999\beta_2 = 0.999 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]
  1. A gradient gtg_t 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.
  2. The method asks how many gradients the second-moment average effectively uses. The paper calls this length ρt\rho_t (rho). Right after the first update, the average uses one gradient. Check: ρ1=1\rho_1 = 1.
  3. Later, the average covers more gradients and ρt\rho_t grows. At β2=0.999\beta_2 = 0.999 it approaches a ceiling, ρ∞=2/(1−β2)−1=1999\rho_\infty = 2/(1-\beta_2) - 1 = 1999. Check: ρt\rho_t is always below 1999.
  4. If ρt\rho_t 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 t=1t = 1 to 44 with β2=0.999\beta_2 = 0.999, ρt\rho_t is about 1, 2, 3 and 4, so this branch runs for those updates.
  5. If ρt\rho_t is above 4, the method computes a rectifier rtr_t. It is small when ρt\rho_t is near 4 and approaches 1 as ρt\rho_t approaches ρ∞\rho_\infty. Check: at t=5t = 5, ρ5≈4.996\rho_5 \approx 4.996 and r5≈0.017r_5 \approx 0.017.
  6. The parameter moves by the momentum step times the adaptive rate times rtr_t. The rectifier makes the variance of the scaled rate constant across updates. Check: the rectifier is about 0.017 at t=5t = 5 and about 0.215 at t=100t = 100, 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 min⁡(t,Tw)/Tw\min(t, T_w)/T_w, which has the same shape as rtr_t, and the paper argues this is why warmup works.

The math

Definition: Rectified Adam (RAdam)

Let β2\beta_2 be the second-moment decay, ρ∞=21−β2−1\rho_\infty = \frac{2}{1-\beta_2} - 1, and for update tt let ρt=ρ∞−2tβ2t1−β2t\rho_t = \rho_\infty - \frac{2t\beta_2^t}{1-\beta_2^t}. The rectifier is rt=(ρt−4)(ρt−2)ρ∞(ρ∞−4)(ρ∞−2)ρtr_t = \sqrt{\frac{(\rho_t - 4)(\rho_t - 2)\rho_\infty}{(\rho_\infty - 4)(\rho_\infty - 2)\rho_t}}, used only when ρt>4\rho_t \gt 4.

Step 2 in symbols: the length ρt\rho_t

The exponential moving average with weights β2t−i\beta_2^{t-i} is approximated by a simple average over a window of length f(t,β2)f(t, \beta_2), chosen so both have the same centre of mass. Solving that condition gives f(t,β2)=ρt=ρ∞−2tβ2t1−β2tf(t,\beta_2) = \rho_t = \rho_\infty - \frac{2t\beta_2^t}{1-\beta_2^t}. As tt grows, ρt\rho_t rises towards ρ∞\rho_\infty.

Step 3 in symbols: the ceiling

Setting t→∞t \to \infty in the formula for ρt\rho_t leaves ρ∞=21−β2−1\rho_\infty = \frac{2}{1-\beta_2} - 1. For β2=0.999\beta_2 = 0.999 this is 2/0.001−1=19992/0.001 - 1 = 1999. For β2≤0.6\beta_2 \le 0.6 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 Var[ψ]≈ρt2(ρt−2)(ρt−4)σ2\mathrm{Var}[\psi] \approx \frac{\rho_t}{2(\rho_t-2)(\rho_t-4)\sigma^2}. This is finite only for ρt>4\rho_t \gt 4. 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 rtr_t gives a variance of rt2 Var[ψ]r_t^2\,\mathrm{Var}[\psi], and the choice of rtr_t makes that equal to the constant CvarC_{\mathrm{var}}, the minimum variance the function reaches at ρt=ρ∞\rho_t = \rho_\infty. The paper proves this variance decreases monotonically as ρ\rho 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 β2=0.999\beta_2 = 0.999, 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

  1. Abstract and Section 1 (Introduction). Needs Learning Rate Warmup and the idea that Adam can land in bad optima.
  2. Section 2 (Preliminaries). The generic adaptive framework, momentum ϕ\phi and adaptive rate ψ\psi. Needs Adam Optimizer and Exponential Moving Average.
  3. 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.
  4. 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.
  5. 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.
  6. 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

Read the full paper

Liyuan Liu, Haoming Jiang, Pengcheng He et al., 2019. arXiv:1908.03265