Transformer Training Instabilities and Loss Spikes
Large transformer training runs sometimes see the loss suddenly jump upward for no apparent external reason — loss spikes — and diagnosing and preventing them is a distinct engineering discipline separate from ordinary hyperparameter tuning.
Prerequisites: Gradient Descent, Chinchilla Compute-Optimal Scaling
Training a large language model can run smoothly for weeks, loss decreasing steadily, and then — with no change in data, code, or hyperparameters — the loss suddenly jumps upward, sometimes sharply, before either recovering on its own or degrading the model permanently. These loss spikes are among the most expensive problems in large-scale training, precisely because they tend to appear only at the scale of tens or hundreds of billions of parameters, where a single run costs a great deal and a failed one cannot simply be discarded. Understanding why they happen is distinct from ordinary small-scale hyperparameter tuning, because the failure modes often don't show up at smaller scale at all.
The analogy: a truck fine on flat roads, unstable on a steep unexpected grade
A delivery truck can drive smoothly for hundreds of miles using a fixed set of gears and speeds. But hit one unusually steep, cambered hill, and the same strategy that worked everywhere else can suddenly cause the load to shift — not because the driver changed anything, but because that stretch of road exposed a weakness flat roads never triggered. Large-model training is similar: an optimiser configuration that has run stably for millions of steps can hit a particular batch, or numerical configuration, that exposes an instability the vast majority of training never encounters.
Where spikes come from
Several distinct mechanisms are implicated, and real spikes are often a combination:
Gradient and activation scale blow-ups. Deep networks can, at certain points in training, produce activations or gradients whose magnitude grows sharply across layers. With Adam, a burst of unusually large gradients can distort its running estimates of gradient mean and variance in a way that persists for many steps, compounding the damage rather than self-correcting.
In words: Adam keeps a running average of recent gradients and their squared magnitudes ; one anomalously large gradient pollutes both, and since sits in the update's denominator, that distortion can make subsequent updates unexpectedly large or erratic for many steps, not just the one bad step.
Data artefacts. A batch with an unusual sequence — heavily repeated tokens, degenerate formatting, an outlier document — produces an unusually large loss and gradient, and at large batch sizes and learning rates the resulting update can push weights into a worse region.
Precision and numerical issues. Reduced precision (bfloat16/float16) trades numerical range for speed; certain layer configurations (see Pre-Norm vs Post-Norm Transformer Blocks) are more prone to values overflowing at exactly the wrong moment.
Worked example 1: reading a loss curve
A training log shows loss declining from 3.2 to 2.4 over 40,000 steps, then abruptly jumping to 3.8 at step 40,200, before slowly declining again over the next 2,000 steps back toward the pre-spike trend. This shape — sudden jump, partial or full self-recovery over a much longer window — is the classic signature of a transient instability; a genuinely broken run instead shows loss staying elevated, or diverging (often visible as NaN) with no recovery at all.
Worked example 2: a mitigation and its effect
A team observes recurring spikes and applies gradient clipping — rescaling the gradient vector so its norm never exceeds a threshold (commonly ~1.0):
In words: if the gradient's magnitude already sits below , leave it unchanged; if it exceeds , shrink the vector so its magnitude equals , preserving direction but capping size. Before clipping, one batch produced a gradient norm of 340 against a target step size calibrated for norms around 1–2 — an update roughly 200× larger than intended, plausibly the cause of a spike. After clipping at , that same batch instead produces an update capped at the intended scale, and the spike does not occur.
Push the learning rate up in the explorer above until steps overshoot and bounce instead of settling — that visible divergence, at a small scale, is the same dynamic that produces a loss spike at full model scale.
Loss spikes arise from a combination of anomalous gradients, optimiser state pollution (especially in Adam), and numerical precision limits, and they are disproportionately a large-scale phenomenon — the same code and data can run stably for weeks before an unlucky batch triggers one, which is why gradient clipping, careful learning-rate schedules, and checkpoint-and-restart strategies are standard practice at scale.
What this means in practice
Production training runs at scale routinely save frequent checkpoints so that, when a spike is detected by automated monitoring, training can be rolled back to the last good checkpoint and resumed with a lower learning rate or a skipped batch, rather than risking permanent degradation. This operational discipline — not just the model architecture — is a large part of what makes multi-week training runs reliable in practice.
Not every upward blip is a dangerous instability — ordinary stochastic gradient noise, particularly at small batch sizes or high learning rates, produces routine small fluctuations that need no intervention. The distinction that matters is magnitude and persistence: a small bounce within the recent noise band is normal optimisation; a sharp jump well outside that band, especially one that fails to recover, is worth investigating.
Practice
- A gradient vector has norm 12, and the clipping threshold is . What is the norm of the clipped gradient, and by what factor was the original gradient scaled down?
- Why does polluting Adam's running variance estimate with one anomalously large gradient cause instability to persist for many steps afterward, rather than being corrected immediately at the next step?
Related concepts
Practice in interviews
Further reading
- Chowdhery et al., PaLM: Scaling Language Modeling with Pathways (2022)
- Molybog et al., A Theory on Adam Instability in Large-Scale Machine Learning (2023)