LEARNING RATE

Too big blows up, too small never arrives, and the start is the steepest part

L216 MINAI SYSTEMS
PREDICT

A two-parameter loss has curvature 1 along one direction and 20 along the other, near its minimum. You run plain gradient descent with a constant learning rate. Roughly what is the largest rate that still converges?

Gradient descent takes a step against the gradient, scaled by the learning rate. Near a minimum the loss looks like a bowl with different steepness in different directions: the eigenvalues of the Hessian. Along a direction with curvature λ, one step multiplies your distance from the minimum by (1 − lr·λ). Above 2/λ that factor is bigger than 1 in size, and every step overshoots further. So the steepest direction caps the rate, and the shallow ones then move slowly. Deep Learning (Goodfellow, Bengio and Courville, sections 4.3 and 8.2.1) gives the same picture: the Hessian’s eigenvalues set the scale of the learning rate.

Two more things make one constant rate wrong. Real losses are steeper in some places than others, and the start of training is often the steep part. And minibatch gradients are noisy, so a constant rate never settles at the minimum.

▶ SIMULATION
SCHEDULE
—
step 0 / 120
lr now —
PARAMETERS
w1 (shallow, curvature 1) = 10
w2 (steep, curvature 20 + 3·w2²) = 5
loss = 456.25 (start 456.25)
STABILITY
largest curvature here 95.0
lr × curvature — (must stay < 2)
worst so far —
loss every 10 steps456.25 (start)
the boundnear the minimum each step multiplies w2 by (1 − 20·lr): stable only if lr < 2/20 = 0.1. At the start the curvature is 95, so lr < 2/95 ≈ 0.021
✓ every step: lr × largest curvature where you stand < 2✓ the loss never blows up past its starting value✓ after 120 steps: mean loss over the last 10 ≤ 0.15
SCHEDULE
01[TRAIN]steps 1–10: gradient step, w ← w − lr·(∇L + noise)
02[TRAIN]steps 11–20: gradient step, w ← w − lr·(∇L + noise)
03[TRAIN]steps 21–30: gradient step, w ← w − lr·(∇L + noise)
04[TRAIN]steps 31–40: gradient step, w ← w − lr·(∇L + noise)
05[TRAIN]steps 41–50: gradient step, w ← w − lr·(∇L + noise)
06[TRAIN]steps 51–60: gradient step, w ← w − lr·(∇L + noise)
07[TRAIN]steps 61–70: gradient step, w ← w − lr·(∇L + noise)
08[TRAIN]steps 71–80: gradient step, w ← w − lr·(∇L + noise)
09[TRAIN]steps 81–90: gradient step, w ← w − lr·(∇L + noise)
10[TRAIN]steps 91–100: gradient step, w ← w − lr·(∇L + noise)
11[TRAIN]steps 101–110: gradient step, w ← w − lr·(∇L + noise)
12[TRAIN]steps 111–120: gradient step, w ← w − lr·(∇L + noise)
Start of too high scenario. 12 steps.
GRADIENT DESCENT ON L(w1, w2) = ½·w1² + 10·w2² + ¼·w2⁴

step:  w ← w − lr · (∇L(w) + noise)

Near the minimum L ≈ ½·(1·w1² + 20·w2²), and one step multiplies
each coordinate by (1 − lr·λ):
  |1 − lr·λ| < 1   ⇔   0 < lr < 2/λ
  stable in every direction  ⇔  lr < 2/λmax = 2/20 = 0.1
  progress along the shallow one  ∝ lr·λmin = lr·1   (slow)

At the start the steep curvature is 20 + 3·5² = 95: lr < 0.021.

Schedule that gets both:
  warmup:  lr_t = peak · (t+1)/W           for t < W
  decay:   lr_t = peak · (0.1 + 0.9·½(1 + cos(π(t−W)/(T−W))))
Warmup keeps lr small while the curvature is high. Decay
shrinks the noise floor: with gradient noise σ, each direction
settles at an expected excess loss of lr·σ² / (2·(2 − lr·λ)).

The toy loss is ½·w1² + 10·w2² + ¼·w2⁴, starting from (10, 5), 120 steps, with seeded noise of σ = 2 added to each gradient as a stand-in for minibatches. Its curvature is 1 and 20 at the minimum, but 95 along w2 at the start. Watch lr × curvature in the STABILITY box: at 2 or above, the step overshoots. NO WARMUP hits 7.6 on step 1. TOO HIGH warms up properly and still crosses 2 at step 10, because 0.11 is above 2/20; w2 then flips sign across the valley with growing swings. SAFE BUT SLOW uses 0.02, under 2/95, and never overshoots, but w1 is still at 0.79 after 120 steps. WARMUP, NO DECAY reaches the minimum and then hovers on the noise floor. Only warmup plus decay ends under 0.15.

TUNE IT NOT YET

The YOUR SCHEDULE scenario trains with your sliders. With no warmup and the peak held, 0.08 blows up on the first step. Find a schedule that reaches a mean loss of 0.15 or less over the last 10 of 120 steps, and never lets lr × curvature reach 2 on any step. Try a peak above 0.1 too, with any warmup.

GOAL: lr × curvature < 2 on every step, and final mean loss ≤ 0.15

The noise floor has a formula. With gradient noise σ and a constant rate, each direction settles at an expected excess loss of lr·σ²/(2·(2 − lr·λ)). At 0.08 that is about 0.48 here, most of it from the steep direction, which sits close to its limit (lr·λ = 1.6). At the decayed rate of 0.008 it is about 0.017. Deep Learning section 8.3.1 gives this as the reason SGD needs a decaying rate: the gradient estimate stays noisy even at a minimum.

FIX IT NOT YET

Write lrAt(step, total, peak), which returns the learning rate (a number) for step step (0 to total − 1). The grader trains the toy loss from (10, 5) with peak = 0.08 and total = 120, then with peak = 0.07 and total = 200, each on three noise seeds. It checks: every rate is a finite number from 0 to peak; some step uses at least 90% of peak; lr × curvature stays under 2 on every step; the loss never blows up; and the mean loss over the last 10 steps is 0.15 or less.

Warmup came into common use with large-batch training. Goyal and colleagues (“Accurate, Large Minibatch SGD”, 2017) scaled the rate with the batch size and found it broke early in training, “when the network is changing rapidly”. A low constant rate for five epochs and then a jump made the training error spike. A gradual ramp to the target rate over five epochs fixed it. The sim’s steep start is a toy stand-in for that early phase, not a model of it: a real network’s curvature changes with its weights, and the optimiser is usually AdamW, not plain gradient descent. The stability bound itself is exact only for a quadratic.

You meet these numbers when you fine-tune. The fine-tuning chapter sets a LoRA learning rate about ten times the full fine-tuning one, because the adapter’s updates are scaled differently. The same rule applies: the rate is relative to how steep the loss is in the parameters you train. The pretraining to RLHF chapter describes the runs where a divergence costs days. Not every NaN is the rate: in mixed precision a value past 65,504 does the same, and fp16 overflow shows how to tell the two apart. And a validation loss is only evidence if the validation set is walled off from training (data leakage).

Mental model:

The learning rate is a step size measured against curvature. It must stay under 2 divided by the steepest curvature you will meet, and that is steepest early, so warm up. Then the noise sets a floor that scales with the rate, so decay. A constant rate is either too big at the start or too big at the end.

IN PRODUCTION

Pretraining and fine-tuning runs: a loss curve that spikes and goes to NaN or infinity a few hundred steps in, a fine-tune whose loss is flat because the rate is 10× too small for LoRA, a validation loss that stops improving while the training loss jitters at a constant rate. Every training config has a peak rate, a warmup length and a decay shape; the usual first fix for a divergence is a lower peak, a longer warmup, or a restart from a checkpoint at a lower rate.

IN INTERVIEWS

“Your loss goes to NaN after 300 steps. What do you check?” Start with the learning rate and warmup before blaming the data, and say why: a step overshoots when lr × curvature passes 2, and curvature is highest early. Then “Why not a constant rate?” Name both ends: warmup for the start, decay to shrink the noise floor at the end. Mention that a rate tuned at one batch size or one LoRA rank does not carry over unchanged.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: FP16 OVERFLOW →