The overfit-one-batch test and training diagnostics
What it is
First verify that a tiny, fixed batch can be overfit: loss should approach zero and predictions should become correct. This deliberately removes generalisation, throughput, and data-diversity questions so a failure points to labels, shapes, objective, parameter registration, gradients, or update code. Once it passes, inspect inputs and labels, loss scale, gradient norms, parameter deltas, activation distributions, and train-versus-validation curves one hypothesis at a time. Log examples and intermediate outputs as well as scalar metrics; a plausible average can hide systematically broken preprocessing.
Why it matters
A large training run confounds every failure mode. A tiny controlled test separates broken code or labels from an honest capacity or generalisation problem. It also creates a regression test for the training system: when a refactor breaks the ability to overfit one batch, stop before spending hours or GPU budget on a full run.
In the real world: A 5-minute check that catches most bugs before launching a costly multi-day training run.
Visual example
Deep learningStart with the smallest experiment that can falsify a basic assumption.
import torch
def overfit_one_batch(model, batch, optimizer, steps=200, target=0.01):
"""The first test to run, and a permanent regression test afterwards."""
x, y = batch
model.train()
for step in range(steps):
optimizer.zero_grad(set_to_none=True)
loss = loss_fn(model(x), y)
loss.backward()
optimizer.step()
if loss.item() < target:
return step, loss.item()
raise AssertionError(f'could not overfit one batch: loss stuck at {loss.item():.4f}')
fixed = next(iter(loader)) # the SAME batch every step
overfit_one_batch(model, fixed, optimizer)Changing architecture, optimiser, augmentation, and batch size together. When the result changes you learn nothing; isolate one variable and log the baseline.