Training Pitfalls & Failure Modes
Symptom → cause → fix for the failures that actually happen
Networks fail in recognizable patterns: NaN losses, plateaued plateaus, silent overfitting, degenerate predictions. This concept is your symptom → cause → fix playbook.
What you will learn
- Diagnose the five most common training failures by signature
- Map each to its root cause and the cheapest fix
- Add observability that finds these before humans do
What is this?
Training fails in a handful of reproducible signatures: loss → NaN (exploding gradients / unstable ops), loss stuck (dead ReLUs, saturating activations, or a silent LR=0), deep stack underperforming shallow baseline (vanishing gradients), loss falling on train while val is flat (overfitting), and constant/degenerate outputs (post-softmax degeneracy or label collapse). Recognizing the signature tells you which fix applies — before you rewrite the architecture.
Why do you need it?
- Most 'my model is broken' sessions are one of a half-dozen known traps.
- Each signature has a cheapest, most likely fix — order matters (LR before architecture).
- Observability (grad norms, activation stats, weight norms) surfaces the failure before a bad model ships.
- Knowing the shape of each failure lets you verify the fix fast instead of guessing.
Mental model
A doctor reading vital signs
Diagnosing training failures with signals
Fever, low BP, and a racing pulse point to different causes even when the patient 'felt sick' in one way. Train loss is just one vital; weight-norm, grad-norm and activation stats are the others that separate the diagnoses.
How it works
- NaN: any unstable math multiplies up (exp, log on extreme values) or LR spikes a weight norm into overflow.
- Dead ReLU: high LR/init permanently zeroes many units; gradients through them vanish.
- Vanishing: saturating activations + depth keep early-layer gradients near zero.
- Overfitting: capacity ≫ data with no regularization; val flattens while train falls.
- Degenerate output: label imbalance + naive loss, or a collapsed embedding cluster, produces one class to rule them all.
Observed signals and the failure they point to.
In production
- CI gates run a short overfit test so plumbing failures fail before expensive fine-tuning.
- Run-time dashboards plot grad-norm and weight-norm along with loss
- Failsafe policy: NaN loss triggers automatic restart from last-good checkpoint with LR halved.
Best practices
- Instrument grad-norm, weight-norm, and activation mean/std every K steps.
- Run the LR range test once per architecture; log the chosen peak LR.
- Gate training on a finite-loss assertion at step 1.
- Cross-validate on a frozen split; never tune on the test set.
Common mistakes
- Rewriting the architecture when a 10x LR change and gradient clipping would have fixed it.
- Adding regularization one knob at a time into an overfit mess instead of the right one first.
- Trusting a smooth loss curve as evidence of a good model.
- Ignoring class imbalance until the confusion matrix (post-deployment) reveals it.
Common issues
Loss prints NaN by epoch 2LR too high, log/exp on near-zero values, or fp16 overflow
Drop LR 10x, add `1e-9` clamps to logs, enable mixed-precision autocast (bf16).
All ReLUs dead — every hidden unit outputs 0Init too wide or LR too large permanently zeroed pre-activations
Kaiming init + lower LR; or switch to Leaky ReLU.
Deep net matches a linear baseline exactlyVanishing gradients across depth (sigmoid chain) or degenerate init collapse
ReLU/GELU, residual connections, batchnorm/layernorm, proper initialization.
Debugging tips
- NaN at step K? Run verbose for the K-first batches and print values at the first break spot.
- Flat loss? Check LR isn't 0, then activation saturation, then data ranges.
- Overfit? Compare loss-of-batch vs whole-run: see if it's validation curve shape, not just the number.
- Print preds distribution: if one class always wins, the loss/target alignment is off, or imbalance.
Interview checkpoint
Hands-on lab
- Reproduce exploding gradiendts, dead ReLU, and overfit gaps in controlled runs
- Apply the correct fix and verify the signature changes
- Build a simple 'checkpoint on NaN' safeguard
Induce and Fix Three Failure Modes
30 min · advanced
Quick quiz
Your train loss descends but validation stays flat. What is the most likely diagnosis?
Gradient clipping alone fixes all NaN-loss causes.