Post-mortem: missing model.eval() skewed inference scores
11/26/2026 — 11/26, 15:20·1 sources (all)·1 reports (all)
Key takeaways
- An engineering post-mortem explains that a PyTorch model stays in training mode after loading weights, so torch.no_grad() alone leaves Dropo…
- calling model.eval() before inference fixes it.
Background & analysis
On November 26, 2026, a postmortem published on DEV Community described a PyTorch inference bug that caused unstable scores in production. The author used a damage classifier called DamageNet as the example. In the notebook, the model scored 94 percent. The serving script then loaded the weights with model.load_state_dict(torch.load("best.pt")) and wrapped the scoring function in @torch.no_grad(), but it never called model.eval() before inference. A returns clerk uploaded the same photo twice and received 0.81 the first time and 0.62 the second, despite identical pixels. Over the following week, every score drifted slightly lower. The postmortem explains the mechanism: a PyTorch model has two modes, training and evaluation, and a newly created model starts in training mode. torch.no_grad() does not change that. As a result, Dropout kept randomly dropping parts of the network during inference, and BatchNorm kept using per-image statistics while updating its running mean. The fix the author gives is to call model.eval() before inference. The report does not say when the issue was found or fixed, or whether the service has been redeployed.
AI-generated from 1 reports · updated 3 days ago
- Heat index
- 25
- All sources
- 1
- All reports
- 1
- First seen
- 3 days ago
Reports on this story headlines open the original
A postmortem explains why a served PyTorch classifier scored the same photo 0.81 and then 0.62: loading weights leaves a model in training mode, and torch.no_grad() does not change that. Dropout kept dropping parts of the network per request and BatchNorm normalized each image by its own statistics, so scores also drifted downward over the week. Calling model.eval() before inference fixes it.
DEV Community · AIAI score 53
Other stories people are talking about
- Heat index 763RisingOpenAI countersues Apple over trade secrets and supplier pressure14 sources
- Heat index 367SurgeAnthropic Denies Claims Claude Sabotages ML Research5 sources
- Heat index 293Musk says Google is interested in renting more compute from SpaceX5 sources
- Heat index 166Claude Code adds /ship command for automated PR review3 sources
- Heat index 166RisingGoogle ships Workspace MCP servers and CLI, mandating agent access path2 sources
How is heat calculated?About the methodHide
Heat counts how many independent sources covered a story in the last 48 hours: one source counts once no matter how many posts it published, decaying with a 24-hour half-life. What ranks first is what many people are talking about.
This page aggregates public feeds. Headlines and summaries are machine-organized and remain the property of the original authors; verify important facts at the source. If you believe a headline or summary infringes your rights, email the contact address in the footer with the page URL and basis of your claim, and we will remove or replace it after review.
- Surge
- Discussion rising fast
- New
- First report within 6 hours
- Rising
- Still gathering discussion

