TECHNOLOGY

Why model.eval changes dropout while no-grad changes recording

In this article
THE QUICK TAKE

Evaluation behavior and derivative recording are independent controls, so a reproducible model experiment must state both choices.

A model can evaluate a prediction while gradients remain enabled, or perform a forward pass without recording gradients while training behavior remains active. Understanding these combinations prevents two independent controls from being collapsed into a single informal inference switch.

Training flags affect the forward behavior of some layers

A module’s training flag is read by layers whose behavior differs between training and evaluation. Dropout is a familiar example: training introduces its defined stochastic transformation, while evaluation uses the documented prediction behavior. Other components may also depend on the flag. This is about the forward computation the model performs. It is not a declaration that all parameters are frozen or that derivative information must not be recorded. A module can participate in gradient-based analysis even when its forward behavior is configured for evaluation.

Gradient recording concerns the computation graph

Autograd settings determine whether eligible operations build the derivative history for later backward computation. Disabling that recording does not inherently tell dropout to select evaluation behavior. A hypothetical developer who wraps a model in no-grad but forgets its training flag can therefore obtain a different forward process from the one intended for ordinary prediction. This is a configuration example, not a reported defect in any model. The mismatch is explained by the independence of the two controls rather than a contradiction in their names.

Use a controlled comparison to expose the distinction

Take an illustrative model containing a stochastic layer and a trainable output. Keep its parameters and input fixed, then compare the relevant combinations of forward mode and gradient recording. Inspect output variability separately from whether a backward path exists. Identical output in one trial does not establish determinism, just as a stored gradient does not establish training-mode dropout. A small controlled exercise provides distinct observations for distinct questions and makes the result easier to interpret than a single end-to-end score.

Record state alongside the model artifact

A checkpoint contains learned values, but a complete execution record also needs the selected forward behavior and derivative mode. For reproducibility, include preprocessing, randomness controls and any state that a layer uses across calls. Evaluation mode alone is not a universal determinism guarantee. Conversely, keeping gradients for an analysis can be intentional and correct. The practical result is a vocabulary that separates what function ran from what derivatives were recorded, allowing prediction, attribution and training experiments to share an artifact without silently sharing every execution assumption.

Primary research and implementation references

Reproducible inference stacks: preserving a GPU pilot’s result; A GPU inference benchmark you can trust.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles