3.2.7Training Deep Networks

Learning rate warmup

1,830 words8 min readdifficulty · medium1 backlinks

WHAT is warmup?

The two most common shapes:

  • Linear warmup: η(t)=ηpeaktTw\eta(t) = \eta_{\text{peak}} \cdot \dfrac{t}{T_w} for tTwt \le T_w.
  • Exponential/constant-then-ramp: less common; linear dominates in practice.

WHY does it help? (first-principles reasoning)

Think about what one SGD step does: θt+1=θtηgt,gt=θL(θt;batcht)\theta_{t+1} = \theta_t - \eta \, g_t, \qquad g_t = \nabla_\theta \mathcal{L}(\theta_t; \text{batch}_t)

Reason 1 — Bad early gradients. With random init the loss surface is chaotic; gtg_t has large magnitude and huge variance across batches. A large η\eta multiplies that noise → the step ηgt\eta g_t can be enormous → weights blow up (loss → NaN) or land in a bad basin.

Reason 2 — Adam's variance estimate is unreliable early. Adaptive optimizers estimate a running second moment vtv_t (an estimate of E[g2]\mathbb{E}[g^2]). Early on, with only a few samples, vtv_t is a poor estimate, so the effective step size η/vt\eta / \sqrt{v_t} swings wildly. Warmup keeps η\eta small until vtv_t has enough samples to be trustworthy. (This is the exact motivation behind RAdam.)

Reason 3 — Large-batch training. When you scale batch size BB, you often scale η\eta up too (linear scaling rule). But a big η\eta from step 0 is unstable, so warmup is what makes the large LR usable — famously in the "ImageNet in 1 hour" work.


HOW to compute it — derive the linear schedule

We want a function η(t)\eta(t) that:

  1. equals ηstart\eta_{\text{start}} at t=0t=0,
  2. equals ηpeak\eta_{\text{peak}} at t=Twt=T_w,
  3. is a straight line in between (simplest continuous choice).

A line through two points (0,ηstart)(0,\eta_{\text{start}}) and (Tw,ηpeak)(T_w,\eta_{\text{peak}}): η(t)=ηstart+(ηpeakηstart)tTw,0tTw\eta(t) = \eta_{\text{start}} + (\eta_{\text{peak}} - \eta_{\text{start}})\cdot \frac{t}{T_w}, \quad 0 \le t \le T_w

Setting ηstart=0\eta_{\text{start}} = 0 (the common default) simplifies to: η(t)=ηpeaktTw\boxed{\eta(t) = \eta_{\text{peak}} \cdot \frac{t}{T_w}}

After warmup (t>Twt > T_w) we hand off to the main schedule. A very common full recipe is warmup + cosine decay over total steps TT:

η(t)={ηpeaktTw,tTwηpeak2(1+cos ⁣(πtTwTTw)),t>Tw\eta(t) = \begin{cases} \eta_{\text{peak}} \dfrac{t}{T_w}, & t \le T_w \\[2ex] \dfrac{\eta_{\text{peak}}}{2}\left(1 + \cos\!\left(\pi \dfrac{t - T_w}{T - T_w}\right)\right), & t > T_w \end{cases}
Figure — Learning rate warmup

Worked examples


Common mistakes


Recall Feynman: explain to a 12-year-old

Imagine you just woke up and your legs are stiff. If you sprint immediately you'll pull a muscle and be out for the day. So you jog slowly first, get warm, then sprint. A neural network is the same: right after it's "born" (random weights), it's clumsy and would hurt itself with big steps. So we let it take tiny learning steps first, grow them slowly, and only then take big confident steps. That slow-start-then-speed-up is warmup.


Active recall

What is learning rate warmup?
Increasing the LR from a small value to the peak value over the first TwT_w steps before the main schedule begins.
Why are early gradients dangerous for a large LR?
With random init, gradients are large and high-variance; ηgt\eta g_t can blow up weights or land in a bad basin.
Formula for linear warmup with zero start?
η(t)=ηpeakt/Tw\eta(t)=\eta_{\text{peak}}\,t/T_w for tTwt\le T_w.
Why does warmup especially help Adam?
The second-moment estimate vtv_t is unreliable with few samples early, making the effective step η/vt\eta/\sqrt{v_t} swing wildly; small η\eta tames this until vtv_t is trustworthy.
General two-point linear warmup formula?
η(t)=ηstart+(ηpeakηstart)t/Tw\eta(t)=\eta_{\text{start}}+(\eta_{\text{peak}}-\eta_{\text{start}})\,t/T_w.
Value of cosine decay at its midpoint (progress = 0.5)?
Exactly ηpeak/2\eta_{\text{peak}}/2, since cos(π/2)=0\cos(\pi/2)=0.
What must you almost always pair warmup with?
A decay schedule (e.g., cosine or step) for the post-warmup phase.
In what units is TwT_w measured?
Optimizer steps, not epochs.
Which optimizer method builds warmup-like behavior in automatically?
RAdam (rectified Adam), by rectifying the variance early.
How does warmup enable the linear-scaling rule for large batches?
It lets you use the large scaled LR safely by ramping into it instead of applying it from step 0.

Connections

Concept Map

produces

large eta amplifies

prevents

ramps eta from 0 to peak

unreliable early

delays until v_t trusted

scales eta via

needs

hands off after Tw to

gives

Random init weights

Noisy huge early gradients

Weights blow up or bad basin

Learning rate warmup

Linear schedule eta_peak times t over Tw

Adam variance estimate v_t

RAdam motivation

Large-batch training

Linear scaling rule

Main decay schedule cosine step

Stability early speed later

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, training ke bilkul shuru mein tumhare model ke weights random hote hain, aur gradients bahut bade aur noisy hote hain. Agar tum wahin pe bada learning rate laga do, to ek hi kharab batch tumhare weights ko itna hila dega ki loss NaN ho jayega ya model kabhi recover nahi karega. Isliye warmup karte hain: pehle chhota LR se start karo, phir dheere-dheere linearly usko peak value tak badhao (say pehle 1000 steps mein), uske baad normal schedule (jaise cosine decay) le lo. Bilkul jaise gym mein pehle warm-up karte ho, phir heavy weight uthate ho.

Warmup ka sabse bada faayda stability hai jab model "kaccha" hota hai, aur speed jab surface smooth ho jaata hai. Adam jaise adaptive optimizers ke liye ye aur bhi zaroori hai, kyunki wo vtv_t (gradient ke square ka average) estimate karte hain — shuru mein kam samples hone ki wajah se ye estimate galat hota hai, aur effective step η/vt\eta/\sqrt{v_t} pagalon ki tarah jump karta hai. Warmup us waqt LR chhota rakh ke ise sambhal leta hai.

Formula simple hai: linear warmup mein η(t)=ηpeakt/Tw\eta(t)=\eta_{peak}\cdot t/T_w. Yaani agar aadhe raste ho to aadha peak LR. Ek important baat: TwT_w ko steps mein naapo, epochs mein nahi — kyunki batch size badalne se steps-per-epoch badal jaata hai aur tumhara warmup chupke se chhota-bada ho jaata hai. Aur warmup ke baad decay lagana mat bhoolna, warna peak pe hi atke rahoge.

Go deeper — visual, from zero

Test yourself — Training Deep Networks

Connections