# 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. Free notes, key...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/training-debugging
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/machine-learning/regularization-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

- [A Recipe for Training Neural Networks](https://karpathy.github.io/2019/04/25/recipe/) (Andrej Karpathy)
- [Google Deep Learning Tuning Playbook](https://github.com/google-research/tuning_playbook) (Google Research)

Previous: [Regularization, Initialization and Normalization](https://www.internhack.in/roadmaps/tracks/machine-learning/regularization-and-normalization) · Next: [PyTorch](https://www.internhack.in/roadmaps/tracks/machine-learning/pytorch)

## More in Neural Network Fundamentals

- [Perceptrons and Multilayer Networks](https://www.internhack.in/roadmaps/tracks/machine-learning/neural-networks-basics)
- [Backpropagation and Autograd](https://www.internhack.in/roadmaps/tracks/machine-learning/backpropagation)
- [Activation and Loss Functions](https://www.internhack.in/roadmaps/tracks/machine-learning/activations-and-losses)
- [Optimizers and Learning Rate Schedules](https://www.internhack.in/roadmaps/tracks/machine-learning/deep-learning-optimizers)
- [Regularization, Initialization and Normalization](https://www.internhack.in/roadmaps/tracks/machine-learning/regularization-and-normalization)
- [Debugging and Running Training Experiments](https://www.internhack.in/roadmaps/tracks/machine-learning/training-debugging)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
