3.7 — LR schedules and gradient clipping
Goal: Sketch the warmup-then-cosine schedule used by GPT-3 / Chinchilla, the more recent WSD schedule, and the global-norm gradient clipping that keeps LLM training stable.
1. Why this session exists
A modern LLM training run does not use a constant learning rate. It uses a schedule: a function that varies over the course of training. The canonical recipe — used by GPT-3, Chinchilla, LLaMA, Mistral, and basically everything since 2020 — has three phases:
- Linear warmup from to peak over the first steps.
- Cosine decay from down to a small floor over the next steps.
- (Optional) Hold at for any remaining steps.
Each phase exists for a reason. We write each one down, derive the formula, and explain the empirical motivation.[2, 5]
2. Warmup: why start small
The first few steps of training are special. At :
- The Adam EMAs have just been initialised at zero. Bias correction partially fixes that (3.2), but — the variance estimate has effectively one sample and is very noisy.
- The model weights are still at the random init. The classifier head in particular often produces large gradients before settling.
- Layer norm and residual streams have not yet calibrated.
Stepping at full at can blow up the optimisation: one bad batch produces a giant step, which produces a bad next gradient, which feeds back through before bias correction stabilises. Empirically this is the dominant failure mode of LLM training without warmup.
The fix is to ramp up gradually:
A linear ramp from to over steps. Typical : 1–5% of total training steps, or a fixed 2000–10000 steps regardless of total length.
3. Cosine decay: why fade out
After warmup, the natural next question is: should stay at forever?
No. Several reasons:
- Convergence theory. For convex stochastic optimisation, the optimal rate requires (e.g., ). Constant LR converges only to a noise ball of radius around the optimum; you must shrink to refine within that ball.
- Loss-landscape flattening. Late in training the loss surface is near-flat near the solution; large steps wash out the small remaining gradient signal as noise. Smaller extracts the last bits of useful gradient.
- Empirics. Across many training runs, accuracy improves measurably in the last of training if you decay the LR aggressively in that window.
The cosine schedule (Loshchilov & Hutter, 2017[1], SGDR) is the empirically dominant choice:
Read off the endpoints: at the cosine argument is , , so . At the argument is , , so . In between it traces out a smooth half-period of cosine — fast initially, slow near the end. The shape is the inverse of an S-curve: it spends a long time near the peak (where gradients are still informative) and a long time near the floor (where fine-tuning helps).
GPT-3 uses . Chinchilla uses . The floor is rarely zero — full decay to zero turns out to slightly underfit the last epoch.[7]
4. Linear decay: a simpler alternative
Some papers use linear decay after warmup instead of cosine:
Same endpoints, straight line in between. Empirically very close to cosine; some recent work (e.g., Hoffmann et al.'s Chinchilla) finds linear marginally better than cosine when total steps are matched. The difference is small enough that hyperparameter tuning matters more than the choice.
A useful comparison: cosine spends more total time near the peak than linear and more total time near the floor — the middle transition is faster. Linear is uniform. Which is preferable is empirical.
5. Why the schedule matters more than you think
A scaling experiment: train a model with constant LR for steps. Then re-train for steps with the warmup + cosine schedule peaking at . The second run typically reaches a loss lower. Same compute, same model, same data. The schedule alone is worth a non-trivial slice of training quality.
Two effects compound:
- Without warmup, the first few hundred steps would damage initialisation; the schedule sidesteps that.
- Without decay, the last fraction of training is wasted hopping around the basin.
Modern training scripts therefore always schedule. The Hugging Face transformers and accelerate libraries ship get_cosine_schedule_with_warmup as the default; PyTorch ships LambdaLR and CosineAnnealingLR to roll your own.
6. The Chinchilla schedule, written out
The Chinchilla paper (Hoffmann et al., 2022)[6] trains models from 70M to 70B parameters on 1.4T tokens. Their schedule is the now-standard recipe:
- Warmup: linear, over the first of tokens.
- Decay: cosine over the remaining tokens, ending at .
- Peak LR : scaled with model size. Smaller models get larger peak LR. Their fit: for 1B params, for 10B, for 70B.
- AdamW with , weight decay (excluding biases and LN).
This combination, more than any architectural choice, is what made Chinchilla a calibration result for the entire field.
7. WSD: warmup–stable–decay (the 2024 alternative)
The cosine schedule has one practical drawback: once you commit to a target , you cannot easily extend the run. The decayed checkpoints near the end of the schedule are at a much smaller than the middle of the run, so resuming training on them gives a low-momentum start that needs a fresh warmup.
WSD (warmup–stable–decay) — popularised by MiniCPM (Hu et al., 2024)[3] and used in several recent LLMs (DeepSeek-V2/V3, parts of Llama 3, MAP-Neo) — addresses this by spending most of the run at a constant peak LR, with the decay compressed into the last – of steps:
The key trick: mid-stable-phase checkpoints are usable as warm starts for follow-up training. You can take a T-token stable checkpoint, decay it for B tokens to get a deployable model, and take the same stable checkpoint and continue training for another T tokens — both branches start cleanly. Cosine doesn't permit this without re-warming.
Empirically WSD matches cosine on final loss for a fixed compute budget, while gaining the "extendability" property. As of 2025–2026 it's the recipe of choice for production LLM teams that plan to continue-pretrain or release a family of models from a single base.
8. Other schedules you'll see
- Inverse-square-root decay. . Used in the original Transformer paper (AIAYN, 2017). Smooth, no , never goes to zero. Largely replaced by cosine for autoregressive LMs.
- Step decay. Drop by a factor (typically ) at hand-picked epoch boundaries. Common in vision (ResNet on ImageNet). Brittle, requires tuning. Replaced by cosine in most pipelines.
- One-cycle (Smith). Warmup up to a very high , then decay below the starting point. Aggressive; sometimes used for fast fine-tuning.
For LLM pre-training, you can essentially ignore these and use warmup + cosine (canonical) or WSD (modern, extendable).
9. Gradient clipping by global norm
Session 2.9 introduced gradient clipping as a fix for the exploding side of the chain. In LLM training it is not optional — every reference training script for GPT-2, GPT-3, LLaMA, Mistral, Chinchilla applies global-norm clipping to every parameter update, every step.
Definition. Concatenate every parameter's gradient into a single vector and compute its norm . If it exceeds a fixed threshold , rescale the entire gradient vector down to norm :
If , do nothing. The direction is preserved; only the magnitude is capped.
Typical threshold. for LLM pre-training. This is small enough to catch genuine spikes (which are typically in norm) and large enough to almost never bind during normal steps — most steps have – after the first warmup epoch. PyTorch's torch.nn.utils.clip_grad_norm_ is the canonical implementation.
Why global norm (not per-parameter clipping). Per-parameter clipping caps each weight tensor independently, which can dramatically distort the overall update direction (one tensor clips, another doesn't, the relative balance changes). Global-norm clipping is a uniform scaling: it preserves the direction in the full parameter vector and only scales the magnitude. Empirically far more stable.
When clipping fires. Three common situations during a healthy LLM training run:
- The first 50–200 steps, before warmup has stabilised activations.
- A bad batch — a particularly long or pathological sequence.
- A hardware-glitch step (a corrupted gradient from a flaky GPU).
In a well-behaved training run, the rate of clipping events drops to near zero after the warmup phase. Continued high clip rates (say, of steps clipping) is a signal that something is wrong — usually peak LR too high or warmup too short.
10. Takeaways
- A modern training run schedules LR; constant LR is almost never optimal.
- Phase 1: linear warmup to stabilise Adam's before taking full steps.
- Phase 2: cosine decay (or linear) from to over the rest of training.
- WSD (warmup–stable–decay) is the modern alternative when extendability matters: long stable phase at , short final decay.
- The total decay horizon must match the actual number of training steps you plan to run.
- Global-norm gradient clipping at is mandatory in LLM training — preserves direction, caps magnitude.
- Chinchilla's recipe: 1.5% linear warmup, cosine decay to , AdamW , , grad-clip .
(a) A 7B model is to be trained for Adam steps with peak LR and floor . Warmup is of total steps. Write the explicit formulas for in each phase under the cosine recipe and plot the rough shape.
(b) A practitioner reports: "I trained with peak , no warmup, and the loss diverged after 50 steps." Explain in terms of the EMA why warmup would have prevented this.
(c) Show that the cosine schedule (with ) spends roughly of above and roughly of below . (Hint: symmetry.)
(d) Argue why "extending the schedule" — keeping the same but doubling — is not the same as training for steps with the original schedule. Which gives lower final loss, and why? How does WSD sidestep this problem?
(e) During a training run you see on step 73 and the configured clip threshold is . By what factor is the gradient rescaled before the optimiser step? Argue why preserving direction matters here.
References
- [1]
Loshchilov, I., & Hutter, F. (2017). "SGDR: Stochastic gradient descent with warm restarts". ICLR. arXiv:1608.03983 — Cosine schedule (3.7).
↩ - [2]
Pascanu, R., Mikolov, T., & Bengio, Y. (2013). "On the difficulty of training recurrent neural networks". ICML. arXiv:1211.5063 — Gradient clipping by global norm (3.7).
↩ - [3]
Hu, S., Tu, Y., Han, X., et al. (2024). "MiniCPM: Unveiling the potential of small language models with scalable training strategies". arXiv:2404.06395 — WSD schedule (3.7).
↩ - [4]
Liu, L., Jiang, H., He, P., et al. (2020). "On the variance of the adaptive learning rate and beyond". ICLR. arXiv:1908.03265 — Variance analysis of warmup (3.7).
↩ - [5]
Brown, T., Mann, B., Ryder, N., et al. (2020). "Language models are few-shot learners". NeurIPS. arXiv:2005.14165 — GPT-3 training schedule; referenced in 3.7.
↩ - [6]
Hoffmann, J., Borgeaud, S., Mensch, A., et al. (2022). "Training compute-optimal large language models". arXiv:2203.15556 — Chinchilla schedule recipe (3.7).
↩ - [7]
Welbl, J., Glaese, A., Uesato, J., et al. (2021). "Challenges in detoxifying language models". arXiv:2109.07445 — Toxicity filtering trade-offs (7.1 §3.7).
↩