CD0005 Pretraining NaN Loss Spike Triage

Mode C · Incident Triage 30 Min 256x H100 · FSDP · BF16 5 Telemetry Clues

Google DeepMind’s training infrastructure team owns the reliability of hundred-GPU pretraining runs, where a single NaN spike can cost a day of cluster time. In an ML infrastructure debugging interview styled on that postmortem work, you are on call for a 7B-parameter Transformer pretraining run on 256 H100 GPUs. The run uses BF16 mixed precision, FSDP, and FlashAttention-2. Training is smooth for 14,200 steps and the loss reaches 2.18. At step 14,203 the training loss spikes to 19.4, and at step 14,204 it turns into NaN.

Two experiments are already done. Rolling back to the step-14,000 checkpoint and resuming with the exact same configuration reproduces the spike at exactly step 14,203. Skipping data steps 14,200–14,205 delays the crash by only 60 steps before another spike occurs. Every hour spent debating leaves the full cluster idle.

Walk through your 30-minute incident triage. Formulate the candidate root-cause buckets: a corrupted data shard, BF16 attention logit or activation overflow, optimizer second-moment underflow, or a hardware bit-flip. Then inspect the five diagnostic telemetry clues in order, isolate the combined root cause, and specify the exact code and configuration fixes plus automated regression guards.

Three-panel loss telemetry: the original run spikes to 19.4 at step 14,203 and goes NaN, a replay from checkpoint 14,000 spikes at the same step, and a run that skips batches 14,200 to 14,205 spikes again at step 14,263

Figure 1: the spike lands on the same step after a rollback, and it returns 60 steps after the suspect batches are skipped. Something in the run is primed to fail, and something in the data pulls the trigger.

Available Telemetry Clues (Inspect & Rank Before Opening the Answer):

Clue #1: Deterministic Replay & Hardware ECC CheckFalsifies: Hardware bit-flip

Triage question before viewing the log: Given that rolling back to step 14,000 reproduces the spike at the exact same step 14,203, what would a replay on a disjoint node pool plus ECC/Xid counters confirm or rule out in under five minutes?

Clue #2: Data Shard Inspection at Step 14,203Falsifies: Sole data corruption

Triage question: Skipping batches 14,200-14,205 still crashed 60 steps later. When you decode token statistics at step 14,203 and step 14,263, what pattern distinguishes a trigger batch from a corrupted shard?

Clue #3: Per-Layer Activation & QK Logit Max-Norm TelemetryTests: Forward BF16 numerics

Triage question: BF16 has FP32’s exponent range (3.4 \times 10^{38}) yet only 8 significant bits. Which forward quantity can grow silently over 4,000 steps and destroy softmax resolution without overflowing?

Clue #4: Optimizer State Inspection (Dtype, \beta_2, Clipping)Tests: Update amplification

Triage question: Why would a single spiky batch turn the very next step into NaN instead of a recoverable bump? Check what happens to AdamW’s second moment v_t when stored in BF16 with \beta_2 = 0.999.

Clue #5: Stabilization Patch Replay & AblationsVerifies: Combined root cause

Triage question: From which checkpoint step must you replay an architectural norm change so existing attention heads do not suffer a sudden distribution shock?

Incident Triage War-Room: Open the split-screen triage console to inspect raw cluster telemetry, verify your 5-clue causal chain, and test your QK-Norm stabilization patch.

Progressive Hints (Free · Zero Spoilers)
1Inspection Checklist (Where to Look)

(1) Hardware & Determinism: Random bit-flips do not fire on the identical step across replays; verify node independence and ECC counters first.
(2) Trigger vs Vulnerability: A crash that returns 60 steps after skipping suspect batches proves the batch is only a trigger acting on a primed model state.
(3) BF16 Resolution vs Range: Track per-layer QK logit maxima; BF16 loses unit precision long before it overflows.
(4) Optimizer Amplification: Check moment buffer dtypes, \beta_2 spike ceiling, gradient clipping, and update-to-weight ratios.

2Visual Review Map (Figure 2)
Triage map: four observed symptoms converge on the question of which bucket explains all of them, which fans out to four candidate buckets (corrupted data shard, BF16 attention logit or activation overflow, optimizer second-moment precision, hardware bit-flip), each linked to the telemetry clue that tests it

Figure 2: The triage map. The final diagnosis must explain every symptom, and each candidate bucket has one telemetry clue that can falsify it.

3Interviewer Nudge (Quantitative Triage Prompts)

Use these four quantitative back-of-the-envelope checks while classifying Clues #1-#5 in the Incident Console:

1. Cheap Falsification First (Clues #1 & #2): Random SRAM/network bit-flips do not repeat at the exact step 14,203 on disjoint GPUs, and a sole bad-shard bug would not crash again 60 steps after skipping steps 14,200-14,205. Distinguish a trigger from an underlying primed state.
2. BF16 ULP Spacing at 68,400 (Clue #3): BF16 has 7 explicit mantissa bits, so near 65,536 its unit-in-last-place step is 2^16 * 2^-7 = 512. Even though 68,400 is nowhere near 3.4e38 overflow, rounding Q/K jitters logits by hundreds and collapses softmax to one-hot.
3. Frozen Second Moments & the 3.16x Ceiling (Clue #4): Multiplying a BF16 v_t by beta2 = 0.999 decays it by 0.1%, which is smaller than half a BF16 ULP (~0.39%) and rounds away to zero! When one huge gradient hits a frozen v_t, compute the single-step Adam bound (1 - beta1) / sqrt(1 - beta2) at 0.999 vs 0.95.
4. Checkpoint Scale Matching (Clue #5): Per-head QK-Norm with gain 1.6 and d = 128 caps logits near sqrt(128) * 1.6^2 ~ 29. Compare that target scale against ckpt_10000 (28.1) versus ckpt_14000 (61,200) to avoid distribution shock on resume.
+Patch Lab Nudges (Optional Coding Step) for the Stabilization Patch Sandbox

These map onto the patch_starter skeleton in the workbench: each chip jumps to the blank's region in the Patch Sandbox editor:

Blank 1 (QK-Norm Modules): Every query and key head needs its own nn.RMSNorm(self.d, eps=1e-6) with weight initialized to qk_gain_init. Why per-head rather than one shared norm, and what does the gain scale vs the eps stabilize?
Blank 2 (Normalize + Causal SDPA): F.normalize(t, p=2, dim=-1) acts on the LAST axis before transposing to (B, H, T, D). Which argument to F.scaled_dot_product_attention replaces the manual causal mask, and does SDPA want is_causal=True during decode?
Blank 3 (FP32 Optimizer): Assert p.dtype == torch.float32, then split weight decay by tensor rank (0.1 for dim >= 2, 0.0 below). From Clue #4's ULP math, why does betas=(0.9, 0.95) keep second moments alive in BF16?
Blank 4 (Guarded Step): clip_grad_norm_ returns the pre-clip total norm; gate opt.step() on torch.isfinite(norm) so an Inf/NaN batch is skipped, then zero_grad(set_to_none=True). What breaks if you clip-then-step unconditionally?
Blank 5 (Stable Z-Loss): Never exp() the logits directly: torch.logsumexp(logits, dim=-1) computes log Z in the log domain. Return ce + z_coef * log_z.pow(2).mean(): what does the quadratic penalty do to a +1000-logit tail?
Answer
Login to view more content

Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *