Debug a Transformer Pretraining Run That Diverges Into NaN Losses

Last updated: November 29, 2026

Quick Overview

A large transformer pretraining job on Azure GPUs trains fine for 40,000 steps, then the loss spikes and becomes NaN. Walk through how you would find the cause and what changes would make training stable.

Microsoft
Machine Learning
Machine Learning Engineer
Microsoft
November 29, 2026
Machine Learning Engineer
Onsite
Machine Learning
Hard

0

0

0 solved


A large transformer pretraining job on Azure GPUs trains fine for 40,000 steps, then the loss spikes and becomes NaN. Walk through how you would find the cause and what changes would make training stable.

Teams training foundation models on Azure supercomputers routinely fight loss spikes that cost days of GPU time. An onsite interviewer looks for a systematic debugging process, knowledge of mixed precision and optimizer failure modes, and pragmatic recovery strategies.

What the Interviewer Expects
  • Recover quickly from a checkpoint and make the failure reproducible
  • Separate data, numerics and optimization causes
  • Check gradient norms, per-layer activation and attention logit statistics before the spike
  • Know mixed-precision overflow causes and loss scaling or bf16
  • Know Adam epsilon, learning rate and warmup effects
  • Propose stabilizers like QK-norm, z-loss, clipping and skipping bad batches
Key Topics to Cover
training instability
mixed precision
gradient clipping
loss spikes
Adam optimizer
attention logits
How to Approach This
  1. Understand the bias-variance trade-off. High training accuracy but low test accuracy signals overfitting.
  2. Choose evaluation metrics carefully based on the problem. Accuracy alone is often insufficient.
  3. Feature engineering is often more impactful than model selection.
  4. Know when to use tree-based models (tabular data) vs neural networks (unstructured data).
  5. Handle class imbalance with SMOTE, class weights, or appropriate loss functions.
Possible Follow-up Questions
  • How would you tell whether a specific data batch caused the spike?
  • Why do attention logits grow over training and how does QK layer norm help?
  • What would you log from day one on the next run?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Explore ML Interview Prep
Sample Answer
Clarify

Questions: precision (fp16 with loss scaling or bf16), optimizer and learning rate schedule, whether the spike repeats when resuming, and what is logged (gradient norm, loss scale, per-layer stats)....

Approach

Resume from the last good checkpoint a few hundred steps before the spike, with the same data order, and add detailed logging. Then bisect causes: data, numerics, optimization dynamics....


Submit Your Answer
Markdown supported