Classic ML interview trap: forget model.eval() and BatchNorm makes predictions batch-dependent

cneuralnetwork · x · 2026-11-06

A genuinely tricky ML interview question: why does BatchNorm behave differently between training and inference?

During training, BatchNorm normalizes using the current mini-batch statistics; during inference, it switches to running estimates collected throughout training. That mismatch is the whole answer.

The practical gotcha: if you forget to call model.eval() in PyTorch before evaluating, BatchNorm (and Dropout) stay in training mode, so your predictions end up dependent on how the input is batched—the same data can yield different outputs with different batch compositions.

Original post →

More from Research

Research channel →