Midway through a large pretraining run, the loss suddenly spikes and sometimes diverges. How do you diagnose the cause, and which mitigations would you consider?
Answer
Model answer, written in a candidate's voice
In short
- Inspect batches/shards around the spike for corruption, duplicates, distribution shift, and pipeline/tokeniser changes
- Track loss alongside gradient norm, update/weight ratio, logit/attention growth, and NaN/Inf or fp16 overflow
- Separate data-driven spikes from optimisation or numerics instability
- Mitigate with bad-batch skipping, lower LR/longer warmup, gradient clipping, QK-norm, z-loss, AdamW epsilon/beta2 changes, and checkpoint rewind
- Add early-warning dashboards and alerts for the next spike
In full
I’d treat the spike as a signal to localise, not just to restart: first I’d pull the exact batches and shards around the jump, check for corrupted, duplicated, or out-of-distribution data and any recent data-pipeline or tokeniser change, then compare loss with gradient norm, update/weight ratio, logit/attention growth, and fp16/bf16 overflow or NaN/Inf counts across the run. If the spike coincides with a bad shard or a few extreme batches, I’d skip or quarantine those batches and verify the pipeline; if it’s optimisation-related, I’d reduce LR or extend warmup, tighten gradient clipping, and consider QK-norm, z-loss, or AdamW epsilon/beta2 adjustments, while confirming the model is not silently overflowing in low precision. If the run is already diverging, I’d rewind to a recent healthy checkpoint, fix the cause, and resume with the safer settings rather than hoping it recovers. I’d also add early-warning dashboards for loss, gradient norm, update/weight ratio, logit/attention scale, and overflow/NaN rates so the next spike is caught before the run is lost.
What a strong answer covers
- Inspect the data around the spike (bad shards, duplicates).
- Track gradient norm, update/weight ratio, and growth in logits or attention.
- Check numerics (fp16 overflow).
- Mitigations: lower LR or longer warmup, gradient clipping, QK-norm, z-loss, AdamW ε/β2 changes, skipping bad batches, rewinding to a checkpoint.
- Set up early-warning dashboards.
Common mistakes
- Restarting with the same configuration.
- Never suspecting the data.