Up nextNext guide
How to Beat Jet Lag With an AI Schedule
Applications
Technical GUIDE
Warmup gently ramps the learning rate up from near zero before training, then cosine annealing smoothly decays it back down following a cosine curve.
Listen to this guideAI-narrated · ~2 min
Together they stabilize early training and squeeze out better final accuracy, which is why nearly every modern transformer is trained this way.
When training starts, model weights are random and gradients can be huge, so jumping straight to a large learning rate often causes loss spikes or divergence — especially with adaptive optimizers like Adam, whose variance estimates are unreliable in the first steps. Warmup fixes this by linearly increasing the rate over a few hundred to a few thousand steps. Once the model is on stable footing, cosine annealing takes over, decaying the rate as 0.5 * (1 + cos(pi * t / T)) of its peak. The cosine shape keeps the rate high early for fast progress, then eases off gradually so the optimizer can settle into a good minimum instead of bouncing around it.
GPT-style and BERT-style language models use a linear warmup over the first ~1-2% of steps followed by cosine decay to near zero.
Vision transformers (ViT) train with cosine annealing and a short warmup to avoid early divergence on ImageNet.
Hugging Face Transformers offers `get_cosine_schedule_with_warmup` as a one-line scheduler for fine-tuning jobs.
Stable Diffusion and other diffusion models fine-tune with warmup to prevent gradient explosions when adapting pretrained weights.
Warmup-plus-cosine remains the default recipe for large language models, but variants are spreading. Warmup-stable-decay (WSD) keeps a constant rate then decays sharply at the end, making it easy to extend runs without recommitting to a fixed length. Researchers are also studying why warmup works — linking it to gradient noise and loss-landscape curvature — and tools increasingly auto-tune warmup length and peak rate, reducing the manual trial-and-error that dominates today.
Free newsletter
Three verified AI stories every weekday morning, written in plain English. Free forever, no ads.
One email each weekday. Unsubscribe in one click. We never sell or share your address.
Test yourself
Instant feedback on every answer, and a shareable certificate with a verifiable ID once you pass a course.
Support free AI education. AI Understanding is a 501(c)(3) nonprofit — no ads, no paywall, ever. Make a donation
Warmup gently ramps the learning rate up from near zero before training, then cosine annealing smoothly decays it back down following a cosine curve. Together they stabilize early training and squeeze out better final accuracy, which is why nearly every modern transformer is trained this way.
Starting at a large learning rate on random weights can cause loss spikes or divergence, so warmup ramps the rate up gently to keep early steps stable.
The rate is scaled by 0.5 * (1 + cos(pi * t / T)), producing a smooth hill that stays high early and glides to near zero at the end.
Adam's running variance estimates are based on very few samples in the first steps, making the effective step size erratic — warmup mitigates this.
T is the horizon over which the rate decays from its peak to near zero; t is the current step within that horizon.
The guide describes a short linear warmup followed by cosine annealing.
Keep learning
More guides picked for this topic
Up nextNext guide
How to Beat Jet Lag With an AI Schedule
Applications