Topic 5 of 5 · 5 min read
Reading loss and validation curves
Goal: Read a training log, classify the run as healthy, overfitting, diverging or stalled and give the next action for each.
Read the training loss and the validation loss together: the gap and the direction of each tell you whether the run is healthy, overfitting, diverging or stalled, and each case has a different next step. A training log is the main instrument you have, and an AI assistant's summary of it is a guess unless you read the numbers.
Check yourself · 1 of 3
Training loss keeps falling, while validation loss fell until epoch 7 and has risen since. What is this called?
Why it matters
Runs cost hours of GPU time. Catching a diverged run at step 300 instead of step 30,000 saves the money. Telling overfitting from a bad learning rate keeps you from tuning the wrong thing.
The four shapes
Training loss on data the model learns from; validation loss on held-out data it never trains on.
- Healthy. Both fall, noisily at first, then flatten. Validation sits a little above training. Action: keep going, save checkpoints.
- Overfitting. Training loss keeps falling while validation loss bottoms out and rises. The model is memorising. Action: stop at the validation minimum (early stopping), add data, add regularisation such as weight decay or dropout, or use a smaller model.
- Diverging. Loss climbs, spikes by orders of magnitude or becomes
NaN. Action: lower the peak rate, add warmup, add gradient clipping, check for bad batches and for fp16 overflow. Restart from the last good checkpoint, not from the NaN weights. - Stalled. Both losses stay flat near the starting value. Action: raise the rate, check that labels line up with inputs, check that the optimizer actually holds the parameters, and confirm the model can overfit 10 examples. If it cannot memorise a tiny set, the bug is in the code, not the data.
Spikes and clipping
A single loss spike that recovers within a few hundred steps is common in long runs and often comes from one odd batch. A spike that does not recover needs action. Gradient clipping rescales the gradient when its norm exceeds a limit, commonly 1.0, so one bad batch cannot throw the weights far.
loss.backward()
grad_norm = torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)
optimizer.step()
Log grad_norm: a norm that suddenly jumps by a factor of 10 or more often comes before a loss spike.
Before and after
Weak: "Loss looks fine, ship epoch 20." The log shows training loss 0.21 but validation loss rising since epoch 7 from 0.48 to 0.71. Fixed: pick the epoch 7 checkpoint, which is where validation was lowest, and add weight decay for the next run.
What goes wrong
- Judging by training loss alone. It keeps falling even when the model is getting worse on new data.
- Validation data leaking into training. Both curves look great and production fails.
- Resuming from a NaN checkpoint. Every later step is NaN.
Examples
A log to classify
epoch train_loss val_loss
1 1.82 1.79
4 0.74 0.81
7 0.31 0.62
10 0.12 0.84
Training keeps falling, validation turned up after epoch 7. Overfitting. Keep the epoch 7 checkpoint and add regularisation.
A spike with a clue
At step 4,100 the loss jumps from 2.1 to 6.8 and falls back by step 4,400. grad_norm was 0.9 for thousands of steps and read 84 at step 4,099. One bad batch. Clipping at 1.0 would have limited the step.
Key points
- Always plot training and validation loss together, not training loss alone.
- Overfitting looks like falling training loss with validation loss that has turned upward.
- Divergence looks like growing loss or NaN, and the usual fixes are a lower rate, warmup and clipping.
- A stalled run should be able to overfit a tiny set of examples; if it cannot, suspect a code bug.
- Gradient clipping rescales an oversized gradient, and a jump in grad norm often warns of a spike.
Common mistakes
- Judging a run by the training loss alone.
- Resuming from a checkpoint saved after the loss became NaN.
- Treating every spike as divergence, or ignoring one that never recovers.
- Letting validation examples appear in the training set.
Check yourself · 2 of 3
What does gradient clipping with max_norm = 1.0 do?
Check yourself · 3 of 3
A new training run shows a flat loss near its starting value for 500 steps. What is a useful first check?
Practice items, not counted towards your mastery.
Start here
- Google ML Crash Course: gradient descent (opens in a new tab)CourseFree
Gradient descent on a linear model with the update rule and learning rate shown step by step.
- CS231n: Optimization (opens in a new tab)CourseFree
Stanford notes on loss functions, gradients and numeric checks, with clear intuition.
- PyTorch docs: torch.optim (opens in a new tab)DocsFree
The optimizer API and learning rate schedulers you call in a training loop.
More for this topic
- Google ML Crash Course: interpreting loss curves (opens in a new tab)CourseFree
Examples of healthy, oscillating and overfitting loss curves and what each one means.
- Google Research Deep Learning Tuning Playbook (opens in a new tab)ArticleFree
Practical advice on tuning learning rate, batch size and schedules, and on reading training runs.