You now own every ingredient separately:
Two pieces are still missing, and both guard against the same enemy: a single bad mini-batch throwing a giant gradient and blowing up the run. Weight decay keeps the parameters from drifting large, and gradient clipping rescales any oversized gradient down to a fixed maximum norm before it can land a destabilizing step.
One step processes one mini-batch
Step 1 — forward pass. Run the network on the batch and average the
per-example loss over its
Step 2 — backward pass. Backpropagate to get the gradient of that loss with
respect to every parameter (this is what
Step 3 — clip the gradient. Measure the gradient's global norm
The direction is untouched — only the length is capped. A normal step passes through
unchanged; a freak spike of norm
Step 4 — schedule the learning rate. Look up this step's rate from the
warmup-then-cosine schedule — a short linear ramp to a peak
with decay progress
Step 5 — the AdamW update. Feed the clipped gradient
That is the entire recipe. Repeat steps 1–5 over mini-batches for
It's tempting to think of the recipe as a shopping list you can pick from independently — use AdamW or a different optimizer, this schedule or that one, whatever batch size you like. In reality these choices are tuned together: the peak learning rate that works well for AdamW at one batch size and precision is often wrong for a different optimizer, a different batch size, or a different numeric precision, because they interact.
Swap out just one ingredient — say, replace AdamW with plain SGD — while keeping everyone else's learning rate, warmup length, and weight decay the same, and training can get worse, not better, even though SGD is a perfectly good optimizer in general. It was never tuned for this combination. A real recipe change means re-tuning the whole combination, not swapping one part in isolation.
Watch a large training run and the loss curve is not perfectly smooth — every so often it jumps upward in a spike. The usual culprit is one pathological mini-batch whose gradient is enormous. Without protection, AdamW takes a huge step along it, the parameters lurch into a bad region, and the loss leaps — sometimes never to recover (a divergence).
Clipping is the seatbelt. A spike of norm
The bold curve is a typical training loss falling over steps; the faint
curve is the learning rate
This loop, run at scale over a vast text corpus, is what produces a pretrained