Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Pre-flight checks for training runs
Pilots run through a checklist before every flight, even though the plane usually works. Training a neural network deserves the same habit. A broken pipeline rarely crashes: it trains, prints losses, and quietly produces a worse model. A few minutes of sanity checks catch most bugs before hours of compute are wasted.
For safety-relevant models, such as perception for landing or anomaly detection on telemetry, a silently buggy training run is worse than a crash. Systematic checks and careful reading of training curves are part of a defensible engineering process. They are also the fastest way to stop wasting expensive GPU time.
- 1. A buggy training pipeline usually…
- 2. Training loss near zero with high validation loss means…
- 3. A loss that jumps up to NaN usually means…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.The checks by hand
1. Initial loss. With small output weights, a classifier predicts nearly uniform probabilities, so the cross-entropy should start near ln k. That is 2.30 for k = 10 and 6.91 for k = 1000. A start of 11.5 for 10 classes means badly scaled outputs; 0.5 suggests labels leaking into the inputs.
2. Overfit one batch. Take 10–20 examples and train on them alone. A working model and optimiser drive the loss close to 0. If not, something in the model, loss or optimiser is broken.
3. Gradient check. Compare backprop with central finite differences in float64 (E0-3). The relative error should be around 10⁻⁷ or smaller.
4. Beat a baseline. After training, validation accuracy must clearly exceed chance (1/k), or the majority class, or a simple model.
5. Read the curves. Smooth with a moving average (for example, a 3-point moving average of 1, 2, 3, 4, 5 gives 2, 3, 4).
| pattern | likely cause |
|---|---|
| both losses high and flat | learning rate too low, a bug, or too small a model |
| loss explodes or becomes NaN | learning rate too high or a numerical bug |
| train ≪ validation, growing gap | overfitting |
| validation near the baseline | no signal, often misaligned data and labels |
- 1. Expected initial loss for 4 classes?
- 2. If a model cannot overfit 16 examples, suspect…
- 3. The generalisation gap is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Running the checks
Exercise 1 (a 2-layer ReLU network on 3-arm spirals, 600 training and 600 validation points):
| check | result |
|---|---|
| initial loss ≈ ln 3 | pass (1.095 vs 1.099) |
| overfit 16 examples | pass (loss 0.0159) |
| gradient check | pass (3.2 × 10⁻⁹) |
| beats chance on validation | pass (0.997) |
A backward pass that forgot the ReLU derivative failed the gradient check, with a relative error of 0.59.
A debugging workflow (after Karpathy, 2019):
- Look at the data. Check the labels, preprocessing and augmentation on a few examples.
- Start with a simple model and a simple loss, and check the initial loss.
- Overfit one batch.
- Train on the full data and get a validation baseline.
- Only then scale up: regularise, tune and enlarge.
Change one thing at a time, fix the random seeds, and log everything: losses, gradient norms, learning rate, and a few predictions.
model.train(); xb, yb = next(iter(loader))
for step in range(500): # overfit a single batch
loss = F.cross_entropy(model(xb), yb); opt.zero_grad(); loss.backward(); opt.step()
print(loss.item()) # should approach 0- 1. The first step of a debugging workflow is to…
- 2. Why change one thing at a time?
- 3. In exercise 1, the missing ReLU derivative was caught by…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory behind the symptoms
Why the initial loss is ln k. With output weights near 0, the logits are all about equal, so softmax gives 1/k for every class and the cross-entropy is −log(1/k) = ln k. A larger value means confidently wrong predictions at initialisation, which waste early training. A smaller one means the network already “knows” the answer, which is suspicious.
Memorisation. Zhang et al. (2017) showed that large networks can fit even random labels on image data. That is why overfitting a batch tests the machinery, not generalisation. Fitting is easiest when inputs are high-dimensional. In exercise 2, a small network on 2-D inputs could not memorise 16 shuffled labels, because nearby points carried conflicting labels.
Curve shapes.
- Learning-rate problems show in the first hundred steps.
- Overfitting shows as a growing gap.
- Validation loss can rise while validation accuracy still improves: the predictions become overconfident (calibration), so watch both.
Other common silent bugs:
- the model left in eval mode during training (dropout and batch norm off), or train mode during evaluation;
- data leakage between splits;
- the wrong normalisation statistics;
- labels off by one;
- forgetting to zero gradients;
- a loss that expects logits receiving probabilities (double softmax).
Interview questions.
- The loss goes down but accuracy stays at chance. What could be wrong? Label encoding or argmax over the wrong axis, a metric computed on the wrong split, or a loss and metric on different outputs.
- Validation is better than training. Is that a bug? Not necessarily: dropout and augmentation are active only in training, and the training loss is averaged during the epoch while the model is still improving.
- 1. Zhang et al. (2017) showed large networks can…
- 2. Validation loss rising while accuracy improves suggests…
- 3. Passing softmax probabilities into a loss that expects logits causes…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Which check catches which bug?
History.
- Y. LeCun et al. (1998, “Efficient BackProp”) collected practical training checks.
- Y. Bengio (2012) wrote practical recommendations for gradient-based training.
- C. Zhang et al. (2017) showed that networks memorise random labels.
- A. Karpathy (2019) wrote the widely used “A recipe for training neural networks”.
Exercise 2. Each pipeline has one injected bug; all four checks are run.
| bug | initial loss | overfit batch | gradient check | beats chance | caught by |
|---|---|---|---|---|---|
| none | pass | pass | pass | pass | — |
| gradient ascent (sign flipped) | pass | fail | pass | fail | overfit, validation |
| softmax over the wrong axis | fail | fail | fail | fail | all four |
| missing ReLU derivative | pass | fail | fail | pass | overfit, gradient |
| inputs ×1000 (no normalisation) | fail | fail | pass | fail | initial loss, overfit, validation |
| labels shuffled against inputs | pass | fail | pass | fail | overfit, validation |
| learning rate ×100 | pass | fail | pass | fail | overfit, validation |
- The clean pipeline passed everything, and every bug failed at least one check.
- Overfitting a single batch caught all six bugs, the best value of any single check here. Shuffled labels were caught too, because this small network on 2-D data could not memorise contradictory labels.
- The gradient check caught only backward-pass bugs. It is blind to data, optimiser and learning-rate errors.
- Validation accuracy missed the broken ReLU gradient. The network still learned the task with a wrong gradient, so “it trains and validates fine” does not prove the code is correct.
- No check is redundant. Run them all; each takes seconds.
Debugging training in AI, robotics and aerospace
- Data-pipeline bugs: misaligned sensor timestamps or label files are the robotics version of “shuffled labels”. Validation against a simple baseline catches them.
- Expensive runs: run the checks on a small slice of data before launching multi-day training on shared GPU clusters.
- Assurance: recorded sanity checks, curves and seeds are evidence in a model’s verification and validation file.
References
- A. Karpathy (2019). “A recipe for training neural networks.” Blog post.
- Y. Bengio (2012). “Practical recommendations for gradient-based training of deep architectures.” In Neural Networks: Tricks of the Trade.
- C. Zhang, S. Bengio, M. Hardt, B. Recht, O. Vinyals (2017). “Understanding deep learning requires rethinking generalization.” Proc. ICLR.
- Y. LeCun, L. Bottou, G. Orr, K.-R. Müller (1998). “Efficient BackProp.” In Neural Networks: Tricks of the Trade.