Your LLM pretraining loss just spiked. Talk me through training stability: gradient clipping, mixed precision, and your debugging playbook.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Loss spikes are endemic to large-scale transformer training - occasional bad batches, attention-logit blowups, or optimizer state getting mis-scaled produce a huge gradient, a destructive update, and a loss that jumps and either recovers slowly, plateaus higher, or diverges.
Full worked answer with diagram
Loss spikes are endemic to large-scale transformer training - occasional bad batches, attention-logit blowups, or optimizer state getting mis-scaled produce a huge gradient, a destructive update, and a loss that jumps and either recovers slowly, plateaus higher, or diverges.
Standing defences in every serious recipe:
- Gradient clipping by global norm (typically 1.0): compute the norm over all parameters; if it exceeds the threshold, rescale the whole gradient vector. Preserves direction, caps magnitude. Clipping frequency is itself a health metric - clipping every step means your LR is too high.
- Mixed precision done right. fp16 has a tiny dynamic range (max ~65k, and underflow is the bigger killer) and requires loss scaling - multiply the loss by a factor so small gradients survive fp16, unscale before the optimizer step, and skip steps whose gradients contain inf/NaN (dynamic loss scaling automates this). bf16 keeps fp32's 8 exponent bits at lower mantissa precision, eliminating loss scaling - the standard mixed-precision format on current GPUs and TPUs. Large runs increasingly push the matmuls further to FP8 with fine-grained (per-block) scaling, as DeepSeek-V3 reported, while keeping sensitive ops in higher precision. Either way, keep fp32 master weights and optimizer states; accumulate large reductions in fp32.
- Architectural/objective stabilisers: pre-norm placement, QK-norm to stop attention-logit growth, and an auxiliary z-loss (used in PaLM, ~1e-4 · log²Z) keeping the softmax normalizer from drifting.
- Warmup + sane peak LR, β₂ ≈ 0.95 (shorter second-moment memory reacts faster to gradient-scale changes than 0.999).
The playbook when a spike hits: check grad-norm and per-layer norm logs - a grad-norm spike preceding the loss spike implicates optimization; no grad spike suggests data. Inspect the offending batch (corrupt documents, pathological repetition - data issues are the most common culprit). Standard remediations, escalating: rely on clipping and let it recover; rewind to the last good checkpoint and skip the offending data batches (the PaLM paper describes exactly this, and OPT's public logbook documents repeated rollbacks); lower peak LR; add stabilisers (QK-norm, z-loss). Also rule out infrastructure: a flaky GPU producing silent NaNs looks exactly like an optimization problem - per-rank gradient-norm logging localises it.
Worth sketching. The first branch is the whole playbook: whether the grad-norm moved before the loss did tells you if this is optimization, data, or hardware.
flowchart TD
A["Loss spike"] --> B{"Grad-norm spike<br/>before the loss spike?"}
B -->|"yes"| C["Optimization: lower peak LR,<br/>check how often clipping fires"]
B -->|"no"| D["Data: inspect the batch for<br/>corrupt docs or pathological repetition"]
B -->|"one rank only"| E["Infrastructure: flaky device<br/>emitting silent NaNs"]
D --> F["Rewind to the last good<br/>checkpoint, skip that shard"]
C --> G["Add stabilisers: QK-norm,<br/>z-loss, beta2 at 0.95"]
F --> G
What a good answer covers
- Loss spikes are endemic to large-scale transformer training - occasional bad batches, attention-logit…
- Standing defences in every serious recipe
- Preserves direction, caps magnitude
- Clipping frequency is itself a health metric - clipping every step means your LR is too high
- Large runs increasingly push the matmuls further to FP8 with fine-grained (per-block) scaling, as…
Key terms: Standing defences · Gradient clipping by global norm · Mixed precision done right · loss scaling · bf16 · FP8 · Architectural/objective stabilisers · z-loss
In the glossary: Gradient clipping · Mixed precision · FP8 / INT8 · Pre-norm · Warmup
Interviewer follow-ups to expect
Why does bf16 remove the need for loss scaling - what's the actual bit-level difference?
Standing defences in every serious recipe:
- Gradient clipping by global norm (typically 1.0): compute the norm over all parameters; if it exceeds the threshold, rescale the whole gradient vector. Preserves direction, caps magnitude. Clipping frequency is itself a health metric - clipping every step means your LR is too high.
- Mixed precision done right. fp16 has a tiny dynamic range (max ~65k, and underflow is the bigger killer) and requires loss scaling - multiply the loss by a factor so small gradients survive fp16, unscale before the optimizer step, and skip steps whose gradients contain inf/NaN (dynamic loss scaling automates this). bf16 keeps fp32's 8 exponent bits at lower mantissa precision, eliminating loss scaling - the standard mixed-precision format on current GPUs and TPUs. Large runs increasingly push the matmuls further to FP8 with fine-grained (per-block) scaling, as DeepSeek-V3 reported, while keeping sensitive ops in higher precision. Either way, keep fp32 master weights and optimizer states; accumulate large reductions in fp32.
- Architectural/objective stabilisers: pre-norm placement, QK-norm to stop attention-logit growth, and an auxiliary z-loss (used in PaLM, ~1e-4 · log²Z) keeping the softmax normalizer from drifting.
- Warmup + sane peak LR, β₂ ≈ 0.95 (shorter second-moment memory reacts faster to gradient-scale changes than 0.999).
Why lower β₂ for LLMs?
Clipping fires on 40% of steps - what do you change?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep