You are handed a training script whose validation accuracy stays at chance. Name the ten bugs you would check first.
Answer
Model answer, written in a candidate's voice
In short
- First diagnostic: overfit one batch/small subset; if it cannot, suspect the loop/data pipeline, not capacity.
- Missing optimizer.zero_grad(); gradients accumulate.
- model.eval() left on, or BN/dropout misconfigured.
- Labels shuffled independently of inputs.
- Wrong label dtype/shape (float vs long, wrong shape).
- Softmax applied before CrossEntropyLoss.
- LR too high or too low.
- Frozen parameters not passed to the optimiser / optimiser built before unfreezing.
- loss.backward() on a detached tensor / no grad path.
- Train/val normalisation mismatch, NHWC vs NCHW channel order, augmentation applied to labels.
In full
I’d start by overfitting one batch: if the model cannot drive a tiny batch to near-zero loss, the bug is in the training loop or data pipeline, not capacity. Then I’d check missing optimizer.zero_grad(), model.eval() left on or BN/dropout misconfigured, labels shuffled independently of inputs, wrong label dtype/shape, softmax before CrossEntropyLoss, LR too high or too low, frozen parameters not passed to the optimiser, loss.backward() on a detached tensor, and train/val normalisation mismatch, NHWC vs NCHW channel order, or augmentation applied to labels. I’d verify the loss is finite and gradients are nonzero, then re-check the validation loader separately from the training loader. If it still sits at chance, I’d suspect the validation labels or metric are wrong rather than the model.
What a strong answer covers
- Missing
optimizer.zero_grad();model.eval()left on, or BN/dropout misconfigured. - Labels shuffled independently of inputs; wrong label dtype or shape; softmax before CrossEntropyLoss.
- LR too high or too low; frozen parameters not passed to the optimiser;
loss.backward()on a detached tensor. - Normalisation mismatch between train and val; channel order (NHWC vs NCHW); data augmentation applied to labels.
- The overfit-one-batch test as a first diagnostic.
Common mistakes
- rewriting the model instead of systematically bisecting the pipeline.