Exercises — Learning rate warmup
This is the practice arena for Learning rate warmup. Every problem below uses only ideas built in the parent note: the linear warmup line, the warmup+cosine recipe, and the why behind each. Work each one on paper first, then open the solution.
Notation reminder (so nothing is used before it is named):
- (Greek letter "eta") = the learning rate, the number that scales each optimizer step.
- = LR at step ; = the highest LR you ramp up to; = the LR the decay finishes at (often , but not always — Exercise 5.3 handles the nonzero case).
- = the current optimizer step (one weight update = one step), a whole number
- = number of warmup steps; = total training steps.
- The two formulas we will lean on the whole way:

Look at the figure: the orange line climbs straight up (warmup), reaches the peak, then the teal curve rolls smoothly down to zero (cosine). The two dashed guide-lines mark and . Keep this picture in mind — every exercise lives somewhere on this shape.
Level 1 — Recognition
Exercise 1.1
Which of these does warmup provide that a constant tiny LR cannot? (a) stability at the start (b) fast progress later (c) both (d) neither
Recall Solution
Answer: (b). A constant tiny LR is already stable at the start, so warmup adds nothing there. What warmup adds on top of a tiny LR is the ability to eventually reach the large peak LR that trains fast. Compared to a constant huge LR the answer would be (a); compared to a tiny one it is the speed. Since the question is specifically vs. "constant tiny," the missing piece is speed later → (b).
Exercise 1.2
In what units is measured — epochs or optimizer steps?
Recall Solution
Optimizer steps. One step = one weight update = one call to the optimizer on one batch. Epochs are unreliable because changing the batch size changes how many steps fit in an epoch, silently changing your true warmup length.
Exercise 1.3
True or false: warmup is only useful for Transformer models.
Recall Solution
False. It became famous via the Transformer paper, but it helps any setup with shaky early gradients — deep ResNets, large-batch training, and adaptive optimizers all benefit. See Transformer training recipe for where it is most famous, but it is a general stability tool.
Level 2 — Application
Exercise 2.1
, , . Find at step .
Recall Solution
Zero-start linear warmup: . Fraction through warmup: . WHAT/WHY: a quarter of the way up the orange line → a quarter of the peak height.
Exercise 2.2
Same schedule as 2.1 but with a non-zero start . Find at step .
Recall Solution
Use the general two-point line: The gap is . Scale by : . WHY it differs from 2.1: the fraction now scales the gap between start and peak, not the peak itself — then you add back the start offset.
Exercise 2.3
, , total , . You are at step (past warmup). Find using cosine.
Recall Solution
Past warmup → cosine branch. Progress: With the cosine collapses to : WHY: at exactly half the decay, , so cosine sits at its midpoint → half of peak.
Level 3 — Analysis
Exercise 3.1
A teammate reports their LR schedule "decays to zero at the end but starts at the peak instantly — no warmup." At step of a proper warmup+cosine schedule, does the LR value from the warmup branch equal the LR value from the cosine branch? (Check continuity of the handoff.)
Recall Solution
Evaluate both branches at (take ). Warmup branch: . Cosine branch at : . They match → the schedule is continuous at the handoff, no jump. That is exactly why cosine was chosen: it starts at with (as the parent showed) zero slope, so the transition looks seamless on the figure — the orange line's top and the teal curve's start touch smoothly.
Exercise 3.2
You double the batch size and, following the linear scaling rule, you double from to . You keep fixed. At step , by what factor does the warmup LR change versus before?
Recall Solution
Zero-start linear warmup: . The fraction is unchanged. Before: . After: . Ratio . Analysis: the whole warmup line scales linearly with , so every point (including step 500) doubles. This is why warmup makes the scaled LR usable: the big LR is only reached gradually, giving the noisy large-batch gradients time to settle. See Adam optimizer on why the second-moment estimate also needs that time.
Exercise 3.3
For zero-start warmup, at what step is the LR exactly half of peak? Give the general formula and the value for .
Recall Solution
Set . Cancel (allowed, it is nonzero): . For : . WHY it's clean: the warmup line is linear, so "half the height" happens at "half the width." (Contrast with cosine, where half-height happens at of the decay window, not half of total training.)
Level 4 — Synthesis
Exercise 4.1
Design a full warmup+cosine schedule for a budget of steps. Requirements: warm up over the first of training, peak at , zero start, cosine to zero () afterward. (a) Give . (b) Give at step . (c) Give at step .
Recall Solution
(a) steps. (Check : ✓.) (b) Step , so warmup branch: . (c) Step , cosine branch (with ). Progress: . WHY these branches: step 1500 is inside the ramp (use the line); step 28000 is past it (use cosine with the shifted progress). Just past the decay midpoint, so the LR sits a touch below half of peak — consistent with the teal curve dropping through its midpoint around step ~26500.
Exercise 4.2
Your loss goes to NaN on step 3 with a constant LR of from step 0. You suspect a huge early gradient. Explain mechanistically (using ) why linear warmup would likely fix this, and estimate the LR that warmup would have used at step 3 if , zero start, same peak .
Recall Solution
Mechanism: the update size is . With random init, is huge and noisy, so a fixed produces an enormous jump weights overflow NaN. Warmup shrinks near step 0, so even a huge is multiplied by a tiny number, keeping the step bounded.
Estimate at step 3: zero-start warmup gives .
That is times smaller than the constant LR — enough to keep the first few explosive steps safe. (An alternative complementary fix is Gradient clipping, which caps directly.)
Level 5 — Mastery
Exercise 5.1
Show algebraically that warmup+cosine is continuous at for a general nonzero start , if the warmup uses the two-point line. Then state whether it is still continuous in slope (differentiable) there, and why cosine was chosen with that in mind.
Recall Solution
Value continuity. Two-point warmup at : . Cosine (with ) at : . Both equal ⇒ continuous for any (the start value never enters the handoff because at the warmup line has fully reached peak). Slope continuity. The warmup line has constant slope (rising). For the cosine we need its derivative in . WHY the chain rule enters: the cosine is written in terms of , but we want the slope in , so we must convert "rate per unit " into "rate per unit " by multiplying by how fast moves as moves — that conversion factor is . Since is a straight line in with constant, its slope is (the numerator changes by for each in , over the fixed denominator ). Chain rule then gives: which at is (since ). So the cosine arrives with zero slope while the ramp leaves with positive slope ⇒ there is a corner (value-continuous but not slope-continuous). Why cosine anyway: cosine's zero-slope end was chosen so the finish (at ) is gentle and the top is flat, giving a smooth plateau exactly where the model is most sensitive. The slope corner at handoff is harmless because both sides sit at the same peak value — the LR does not jump, it merely stops rising and starts (flatly) falling. Compare with Cosine annealing for the decay-only view and Learning rate schedules for the family.
Exercise 5.2
Prove that for zero-start linear warmup the average LR applied during warmup equals . Then compute the total "distance-scaling budget" for .
Recall Solution
Average. The average of a straight line from to over is the midpoint value: So on average during warmup you apply half the peak LR — a tidy way to see warmup as "spending half your LR budget while the model settles." Budget integral: WHY the integral matters: it is the total learning-rate "mass" injected during warmup; using it lets you compare warmup lengths fairly. RAdam (see RAdam) can be read as an automatic way of shaping this early budget.
Exercise 5.3
Now use the nonzero-floor cosine: , , , . (a) What LR does the decay end at? (b) Find at step (decay midpoint) and explain why it is not simply .
Recall Solution
(a) By construction the cosine branch reaches at (step ), so it ends at — it decays toward the floor, not to zero. (b) Progress , so : WHY not : the midpoint is halfway between the two endpoints and , i.e. their average — the floor lifts the whole curve up by . Only when does the midpoint collapse to .