Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 10 / Topic 6 of 7

Evaluation mode

Two switches, different jobs, both needed when measuring:

  • model.eval() — layers change behaviour: Dropout stops dropping (verified: in eval mode it passes inputs through unchanged), BatchNorm uses running statistics.
  • torch.no_grad() — stops gradient recording: faster, less memory.
model.eval()
with torch.no_grad():
    acc = (model(X_te).argmax(1) == y_te).float().mean()

Forgetting model.train() on the way back is the symmetric bug — the next epoch then trains without dropout.

🧪 Quick quiz

  1. What does model.eval() change, and what does it not do?
Show the answer

Dropout and BatchNorm switch to inference behaviour. It does NOT stop gradient tracking — that is torch.no_grad()'s job; use both for evaluation.

Done here? The practice set for Part 10 — 4 exercises with solutions — is on the part page.

Search the guide