Part IX — Deep Learning Regularization, Normalization & Training Dynamics · Chapter 8

Learning rate schedules: Warmup & Cosine decay

Hook

A learning rate that's perfect once training has settled down is often wildly too large at the very first step, while everything is still far from where it needs to be. One fixed number can't be right for both moments.

Intuition
Constant — log₁₀(loss) after 12 steps ≈ 5.51 (loss ≈ 3.21e+5)

This toy problem just wants to minimize f(x)=x2f(x)=x^2 starting from x=10x=10. The base rate here is deliberately too large to use constantly. Watch log10(loss)\log_{10}(\text{loss}) over 12 steps — it doesn't wobble, it climbs, forever.

Formalize

Two schedules address this from different angles. Step decay reduces the rate at fixed checkpoints:

ηstep(t)=η0γt/k\eta_{\text{step}}(t) = \eta_0 \cdot \gamma^{\lfloor t / k \rfloor}

Warmup + cosine instead starts the rate at (near) zero and ramps it up before easing it back down:

ηwarmup(t)={η0tTwt<Twη02(1+cos ⁣(πtTwTTw))tTw\eta_{\text{warmup}}(t) = \begin{cases} \eta_0 \cdot \dfrac{t}{T_w} & t < T_w \\[4pt] \dfrac{\eta_0}{2}\left(1+\cos\!\left(\pi \cdot \dfrac{t - T_w}{T - T_w}\right)\right) & t \geq T_w \end{cases}
  • η0\eta_0 — the base (peak) learning rate.
  • γ\gamma — the step-decay shrink factor applied every kk steps.
  • TwT_w — the number of warmup steps, ramping linearly from 00 up to η0\eta_0.
  • TT — the total number of training steps, by which the cosine term reaches its floor.
  1. Step decay still starts at the full (too-large) rate

    Until the first checkpoint at t=kt=k, ηstep(t)=η0\eta_{\text{step}}(t)=\eta_0 — exactly the same too-large rate as never decaying at all. Whatever damage a too-large rate does in those first kk steps still happens.

  2. Warmup never applies the full rate until x has already moved toward the optimum

    ηwarmup(0)=0\eta_{\text{warmup}}(0)=0, and it only reaches η0\eta_0 at t=Twt=T_w — by which point gradient descent has already taken several small, safe steps. The large rate arrives once it's less likely to cause an overshoot.

Play
final loss ≈ 6.13e-4 — peak loss along the way ≈ 1.00e+2

Switch between all three. Step decay eventually gets the loss down too — but only after a huge overshoot in the middle, while it's still using the full base rate. Warmup + cosine reaches a comparably tiny final loss without ever letting the loss climb above where it started.

Worked example
  1. Constant: diverges immediately and never recovers

    At the base rate, xt+1=xt(12η0)=xt(1.4)x_{t+1}=x_t(1-2\eta_0)=x_t\cdot(-1.4) — each step grows in magnitude by 40%. Since every step multiplies by the same 1.4-1.4, this is a plain geometric sequence: xt=10(1.4)tx_t = 10\cdot(-1.4)^t. At t=12t=12: x12=10(1.4)12566.9x_{12}=10\cdot(-1.4)^{12}\approx566.9, and the loss x122321,000x_{12}^2\approx321{,}000 — up from 100100 at the start.

  2. Step decay: the same explosion, temporarily

    For the first 4 steps (before the first decay), step decay is identical to constant, so the same closed form applies: x4=10(1.4)438.4x_4 = 10\cdot(-1.4)^4 \approx 38.4, and loss x421476x_4^2\approx1476 — nearly 15×15\times its starting value, before the rate ever drops. Once it does, the trajectory recovers quickly and the final loss ends up tiny — but only after that mid-run spike.

  3. Warmup + cosine: no spike at all

    During warmup, η(t)=1.2t/4\eta(t)=1.2\cdot t/4 is a different rate every step, so each step needs its own multiplication:

    • t=0t=0: η=0\eta=0, so x1=10(10)=10x_1=10\cdot(1-0)=10 — completely unchanged
    • t=1t=1: η=0.3\eta=0.3, so x2=10(10.6)=4x_2=10\cdot(1-0.6)=4
    • t=2t=2: η=0.6\eta=0.6, so x3=4(11.2)=0.8x_3=4\cdot(1-1.2)=-0.8
    • t=3t=3: η=0.9\eta=0.9, so x4=0.8(11.8)=0.64x_4=-0.8\cdot(1-1.8)=0.64

    By the time the rate ramps up to its peak at t=4t=4, xx has already shrunk to 0.640.64 on its own from those small early steps. The loss never exceeds its starting value of 100100 anywhere along the run, and still ends near 6×1046\times10^{-4}.

Checkpoint

Pick the schedule that gets the loss under 0.01 by step 12 and never lets the loss climb above its own starting value along the way.

no schedule selected yet
Pick a schedule to try it
Summary
ηwarmup(t)={η0t/Twt<Twη02(1+cos(πtTwTTw))tTw\eta_{\text{warmup}}(t) = \begin{cases} \eta_0 \cdot t/T_w & t < T_w \\ \frac{\eta_0}{2}\left(1+\cos\left(\pi\frac{t-T_w}{T-T_w}\right)\right) & t \geq T_w \end{cases}

A constant learning rate has to compromise between "large enough to make progress" and "small enough not to overshoot" for every step of training at once — usually failing at both once the ideal rate changes over time. Step decay fixes the long run but not the start. Warmup fixes the start; cosine decay fixes the end. Together they let the rate be small when the network can't yet handle anything larger, large once it can, and small again for fine convergence — which is exactly why a flat rate is the exception in modern training, not the rule. The next chapter turns to a different training-time constraint: numeric precision itself.