Debugging and Running Training Experiments

A disciplined recipe for getting networks to train: overfit a batch first, sanity-check data, read loss curves and change one thing at a time.

Intermediate · about 4 hours · difficulty 3/5

Learn first: Regularization, Initialization and Normalization

Neural network bugs rarely crash; they silently produce a model that is a bit worse. A methodical process saves days.

A practical recipe

  1. Look at the data after every transform: plot images with labels, decode tokenized text.
  2. Establish baselines: a trivial model and a simple non-neural model.
  3. Overfit one small batch. If the loss cannot reach near zero on 32 examples, something is broken.
  4. Check initial loss: for 10 balanced classes it should be about ln(10) = 2.3.
  5. Scale up gradually, adding regularization only once you can overfit.
  6. Change one thing at a time and log every run.

Common bugs

  • Labels shuffled independently of inputs.
  • Forgetting optimizer.zero_grad() so gradients accumulate.
  • Softmax applied twice, or wrong loss for the output format.
  • Train mode left on during evaluation, or data augmentation applied to validation data.
  • Normalization statistics that differ between training and inference.

Reading curves

Train loss not decreasing: learning rate, bug or capacity. Validation loss rising while train falls: overfitting. Spiky loss: learning rate too high or bad batches.

Good enough to move on when you default to the overfit-one-batch test and can diagnose a failed run from its curves.

Key concepts

  • Visualizing inputs after transforms
  • Overfit a single batch
  • Initial loss sanity check
  • Reading loss curves
  • Common training bugs
  • Ablation discipline

Mini project

Take a working training script, have a friend (or yourself, blind) inject three bugs from the common-bugs list, then find each using only the debugging recipe and write down which check caught it.

Check yourself

Your 10-class classifier starts with a loss of 15 instead of about 2.3. What does that suggest?

Free resources