Search

Search papers and lessons

Learning Rate Warmup

Level 3 · 12 min read

Learning rate warmup starts training with a small step size and raises it over the first few hundred or thousand steps, which protects adaptive optimizers like Adam while their running statistics are still unreliable.

On this page

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

TL;DR

Learning rate warmup means starting training with a small learning rate and raising it step by step over the first part of training, before the normal schedule takes over. It solves a specific problem: Adam and similar optimizers scale each step using averages of past gradients, and in the first few steps those averages rest on almost no data. Large early steps built on that thin evidence can push the model into a poor region that training then struggles to leave.

Builds on: Adam, Learning Rate · Leads to: RAdam, learning-rate schedules

Where it's used

Training Transformers for translation and language modelling. The original Transformer paper by Vaswani and colleagues used a linear warmup over the first 4,000 updates, followed by a decay in proportion to the inverse square root of the step number. The RAdam paper reports a concrete case: training a Transformer on the IWSLT'14 German-to-English translation task without warmup raised the training loss from about 3 to around 10.

Training image classifiers with very large batches. A very large batch gives a less noisy gradient, so a large step can look safe, but the first steps can still move the weights a long way from their random starting point in a convolutional network. The RAdam paper says warmup was originally proposed for very large batches, citing the large-minibatch work of Goyal and colleagues in 2017.

Fine-tuning a pretrained model. Pretrained weights already encode useful structure. A short warmup keeps the first updates small, so the new data is less likely to overwrite that structure in a few bad steps. This is one reason fine-tuning often uses a smaller rate than training from scratch. The argument is practical; the RAdam paper does not test this case.

How it works

Use one weight θ\theta and a loss whose gradient we can compute by hand. We will track only the first four steps, with a target learning rate of η=0.1\eta = 0.1 and warmup length 4.

  1. Set the schedule. Warmup length is Tw=4T_w = 4 steps. For step tt, the rate is ηt=η⋅min⁡(1,t/Tw)\eta_t = \eta \cdot \min(1, t / T_w). Check: step 1 uses 0.1×1/4=0.0250.1 \times 1/4 = 0.025, and step 4 uses 0.1×4/4=0.10.1 \times 4/4 = 0.1.
  2. Run step 1 with gradient g1=0.5g_1 = 0.5. Adam keeps two averages: mm, the average of gradients, and vv, the average of squared gradients. After one gradient both averages are built from that single number, so the bias-corrected estimates are m^1=0.5\hat m_1 = 0.5 and v^1=0.5\sqrt{\hat v_1} = 0.5. The normalized direction is 0.5/0.5=10.5 / 0.5 = 1. Check: the step is η1×1=0.025\eta_1 \times 1 = 0.025.
  3. Run step 2 with gradient g2=0.5g_2 = 0.5 again. The averages now rest on two equal numbers, so the normalized direction is still 1. The step is η2=0.05\eta_2 = 0.05. Check: the weight moved by 0.05, which is twice the first move because the rate doubled.
  4. Run step 3 with gradient g3=0.5g_3 = 0.5. The normalized direction is still 1, and the step is η3=0.075\eta_3 = 0.075.
  5. Run step 4 with gradient g4=0.5g_4 = 0.5. The step is η4=0.1\eta_4 = 0.1, the full target rate. Check: total movement after four steps is 0.025+0.05+0.075+0.1=0.250.025 + 0.05 + 0.075 + 0.1 = 0.25.
  6. Now see what the warmup protects against. Suppose instead the first gradient were g1=0.01g_1 = 0.01 and the second were g2=5.0g_2 = 5.0, a sudden spike. Adam's averages now hold very little evidence about the scale of gradients, so the step on that spike is hard to predict from the past. Without warmup, the rate on step 2 would be the full 0.10.1. With warmup, it is only 0.050.05, so the same spike moves the weight half as far.
flowchart LR
  A[Few gradients seen] --> B[Averages m and v are noisy]
  B --> C[Adaptive step can be erratic]
  C --> D[Warmup keeps the rate small]
  D --> E[Averages settle, rate rises]
01234567800.020.040.060.080.10.12step tlearning rate
  • linear warmup, 4 steps
  • constant rate
The warmup line climbs from 0 to the full rate 0.1 over the first four steps, then stays flat. The dashed line is the rate with no warmup.

The math

Definition

Definition: Linear learning rate warmup

Let η\eta be the target learning rate and Tw>0T_w \gt 0 the warmup length in steps. The scheduled rate at step t≥1t \ge 1 is

ηt=η⋅min⁡ ⁣(1,tTw).\eta_t = \eta \cdot \min\!\left(1, \frac{t}{T_w}\right).

The rate rises linearly from near zero to η\eta over the first TwT_w steps, then stays at η\eta (or follows whatever schedule comes next).

Step 2 in symbols: what Adam computes

Adam keeps two exponential moving averages, with decay rates β1=0.9\beta_1 = 0.9 and β2=0.999\beta_2 = 0.999, the defaults given in the Adam paper. The first average is of the gradient gtg_t, and the second is of its square:

mt=β1mt−1+(1−β1)gt,vt=β2vt−1+(1−β2)gt2.m_t = \beta_1 m_{t-1} + (1 - \beta_1) g_t, \qquad v_t = \beta_2 v_{t-1} + (1 - \beta_2) g_t^2.

Both start at zero, so they are biased toward zero early. Correct the bias by dividing by 1−βt1 - \beta^t:

m^t=mt1−β1t,v^t=vt1−β2t.\hat m_t = \frac{m_t}{1 - \beta_1^t}, \qquad \hat v_t = \frac{v_t}{1 - \beta_2^t}.

The update then uses the warmed-up rate:

θt+1=θt−ηtm^tv^t+ϵ.\theta_{t+1} = \theta_t - \eta_t \frac{\hat m_t}{\sqrt{\hat v_t} + \epsilon}.

Here ϵ\epsilon is a tiny constant that prevents division by zero.

Step 2 in symbols: the first step is always the rate

After one gradient, m1=(1−β1)g1m_1 = (1 - \beta_1) g_1, so m^1=g1\hat m_1 = g_1. Similarly v1=(1−β2)g12v_1 = (1 - \beta_2) g_1^2, so v^1=g12\hat v_1 = g_1^2. Ignoring ϵ\epsilon, the normalized direction is g1/∣g1∣=±1g_1 / |g_1| = \pm 1. The first step therefore has size exactly η1\eta_1, whatever the gradient's magnitude. This is why the walkthrough used g1=0.5g_1 = 0.5 and got a normalized direction of 1, and it is why the first steps depend so heavily on the rate.

Step 3 in symbols: few samples, unreliable scale

Adam's normalized direction is roughly m^t/v^t\hat m_t / \sqrt{\hat v_t}. When v^t\hat v_t is built from only a few gradients, it is a noisy estimate of the true gradient scale. The RAdam paper argues that this estimate has large variance early in training, and that warmup works by reducing that variance: it keeps the rate small until the averages contain enough samples to be trusted. The argument concerns the adaptive term, so it applies to Adam and related methods such as RMSProp, and not to plain SGD, which has no such term.

Step 4 in symbols: the total movement

With the linear schedule and a constant normalized direction of 1 for the first TwT_w steps, the weight moves

∑t=1TwηtTw=ηTw+12.\sum_{t=1}^{T_w} \eta \frac{t}{T_w} = \eta \frac{T_w + 1}{2}.

For η=0.1\eta = 0.1 and Tw=4T_w = 4 this gives 0.1×5/2=0.250.1 \times 5/2 = 0.25, which matches the total in step 5 of the walkthrough. Holding the full rate for the same four steps (with the same unit direction) would move the weight 0.40.4. In general, with the direction held at 1, the ratio is (Tw+1)/(2Tw)(T_w + 1)/(2T_w), which falls toward one half as warmup gets longer.

Worked examples

Example
Tiny: the first Adam step with and without warmup

Take one weight, a gradient g1=0.5g_1 = 0.5, and the target rate η=0.1\eta = 0.1.

  1. Without warmup, the rate at step 1 is η1=0.1\eta_1 = 0.1.
  2. The first step size is η1×∣g1∣/∣g1∣=0.1\eta_1 \times |g_1| / |g_1| = 0.1, because Adam's normalized direction is 1.
  3. With linear warmup over Tw=4T_w = 4, the rate at step 1 is 0.1×1/4=0.0250.1 \times 1/4 = 0.025.
  4. The first step size is now 0.0250.025.

Answer: warmup cut the first move from 0.10.1 to 0.0250.025, a factor of four.

Example
Standard: four warmup steps with a steady gradient

Keep η=0.1\eta = 0.1 and Tw=4T_w = 4. Every gradient is gt=0.5g_t = 0.5, so the normalized direction is 1 at every step.

  1. Step 1 uses η1=0.1×1/4=0.025\eta_1 = 0.1 \times 1/4 = 0.025.
  2. Step 2 uses η2=0.1×2/4=0.05\eta_2 = 0.1 \times 2/4 = 0.05.
  3. Step 3 uses η3=0.1×3/4=0.075\eta_3 = 0.1 \times 3/4 = 0.075.
  4. Step 4 uses η4=0.1×4/4=0.1\eta_4 = 0.1 \times 4/4 = 0.1.
  5. The weight moves a total of 0.025+0.05+0.075+0.1=0.250.025 + 0.05 + 0.075 + 0.1 = 0.25.
  6. Check with the formula η(Tw+1)/2=0.1×5/2=0.25\eta (T_w + 1)/2 = 0.1 \times 5 / 2 = 0.25. The two agree.
  7. From step 5 on, the rate stays at 0.1 and the weight moves 0.1 per step.

Answer: after four steps the weight has moved 0.25 and the rate has reached its target. A run that held 0.1 from the start would have moved 0.4 in the same four steps.

Example
Realistic: a Transformer that diverges without warmup

Suppose a team trains a small Transformer for translation with Adam and a target rate of η=0.001\eta = 0.001. In the first run they skip warmup.

  1. Suppose that within the first few dozen steps, the loss falls for a while, then jumps and does not recover. The model settles in a poor state.
  2. In the second run they add a linear warmup over the first 1,000 steps, so the rate on step tt is 0.001×t/10000.001 \times t / 1000.
  3. On step 10 the rate is 0.001×10/1000=0.000010.001 \times 10/1000 = 0.00001, which is a hundredth of the target. Early steps are now tiny, while Adam's averages collect data.
  4. By step 1,000 the rate reaches 0.0010.001, and the loss keeps falling without the jump.

Try it: with the linear schedule above, what is the rate on step 250, and what fraction of the target is it? Answer: 0.001×250/1000=0.000250.001 \times 250/1000 = 0.00025, which is one quarter of the target.

Common mistakes and tradeoffs

Mistake: "Warmup is only needed for huge models." It is tempting to think warmup matters only at extreme scale. In fact the cause is the adaptive averages, which are unreliable at the start of any run. The RAdam paper's clearest demonstration is a translation Transformer, and it notes similar phenomena in BERT pre-training, so the problem is not specific to one kind of model.

Mistake: "Warmup can be any length, so pick a short one." It is tempting to use a few steps and move on. In fact warmup length matters. In a CIFAR10 test in the RAdam paper, using a ResNet-20 classifier, Adam with 100 steps of warmup at a rate of 0.1 reached only 90.13 percent test accuracy, while RAdam reached 91.06 at the same rate. The authors also note that for some warmup lengths Adam with warmup is more sensitive to the choice of learning rate.

Mistake: "Warmup replaces the learning rate decay." It is tempting to think a warmup handles the whole schedule. In fact warmup handles only the start. Many recipes pair it with a later decay, such as cosine annealing, which lowers the rate as training converges.

Tradeoffs. Warmup adds a hyperparameter, the warmup length, and that length has to be chosen for each setup. Too short and the early instability returns; too long and training wastes steps at a rate that is too low. Methods such as RAdam remove the need for a hand-set length by rectifying the adaptive term directly, at the cost of a more involved optimizer. RAdam itself falls back to SGD with momentum for its first few updates, while its variance is still divergent. Plain SGD has no adaptive averages, so the variance argument does not apply to it; warmup is still used there, mainly for very large batches, the setting it was first proposed for.

History

Warmup was first proposed for training with very large batches. The RAdam paper says it was originally proposed for SGD in that setting, citing Goyal and colleagues in 2017.

The Transformer paper by Vaswani and colleagues in 2017 used a linear warm-up followed by decay. The RAdam paper notes that the state of the art in neural machine translation at the time used Adam with linear warmup.

Only in 2019 did the RAdam paper give a theoretical account. Its authors argued that the adaptive term has large variance early in training, and that warmup works by reducing that variance. The paper also proposed RAdam, an Adam variant that rectifies the variance directly.

Recap

  • Adam scales each step by averages of past gradients. The averages are unreliable in the first few steps.
  • The first Adam step has size equal to the learning rate, whatever the gradient, so the rate at the start matters most.
  • Linear warmup raises the rate from near zero to the target over TwT_w steps: ηt=η⋅min⁡(1,t/Tw)\eta_t = \eta \cdot \min(1, t/T_w).
  • The RAdam paper argues that warmup works by reducing the variance of the adaptive term early on, which is why it stabilizes training.
  • Read next: RAdam, which removes the need for a hand-set warmup, and cosine annealing, which handles the decay after warmup.

Check yourself

QuestionAdam has ηt=0.2\eta_t = 0.2 on step 1 and the first gradient is g1=−3g_1 = -3. What is the size of the first step, ignoring ϵ\epsilon?Show answer

Answer: 0.2. After one gradient, m^1=g1\hat m_1 = g_1 and v^1=g12\hat v_1 = g_1^2, so the normalized direction is −3/3=−1-3/3 = -1, with magnitude 1. The step size is η1×1=0.2\eta_1 \times 1 = 0.2, whatever the gradient's magnitude.

QuestionA linear warmup has η=0.1\eta = 0.1 and Tw=5T_w = 5. What is the rate on step 3?Show answer

Answer: 0.06. The formula is ηt=η⋅min⁡(1,t/Tw)=0.1×3/5=0.06\eta_t = \eta \cdot \min(1, t/T_w) = 0.1 \times 3/5 = 0.06.

QuestionWhy does warmup help Adam more than it helps plain SGD, in terms of what the optimizer knows at the start?Show answer

Answer: Adam keeps running averages of the gradient and its square, and those averages are built from very few gradients in the first steps. Their scale is an unreliable estimate, so the normalized step can be erratic. Warmup keeps the rate small until the averages contain enough data. Plain SGD does not normalize by a running estimate of gradient size, so it does not have this early-stage unreliability in the same way.

QuestionYou train a model with a rate that warms up over 2,000 steps, then decays. A colleague says the warmup length does not matter as long as there is some warmup. Is that right?Show answer

Answer: No. The length affects the outcome. Too short a warmup leaves the early instability in place, and too long a warmup spends many steps at a low rate. The RAdam paper reports that Adam with a 100-step warmup at a rate of 0.1 reached only 90.13 percent on CIFAR10, and that for some warmup lengths Adam with warmup is more sensitive to the learning rate, so the choice is a real tuning decision.

QuestionIn one sentence, what does the warmup schedule ηt=η⋅min⁡(1,t/Tw)\eta_t = \eta \cdot \min(1, t/T_w) do after step TwT_w?Show answer

Answer: It holds the rate at the target η\eta, because t/Twt/T_w is at least 1 and the minimum is 1. Any later decay is a separate schedule applied on top.

Sources