Code RoomDropout enabled during validation
MediumPrep Room Coding #2253

Dropout enabled during validation

Code reviewCode quality & reviewMid–Senior~16 min

Review this PyTorch validation function.

Validation accuracy is noisy across runs and lower than expected for a model with dropout and batchnorm. What's wrong?

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 16 min
Mark a line and say what kind of problem it is.0 findings
1import torch
2 
3def validate(model, val_loader):
4 correct, total = 0, 0
5 for xb, yb in val_loader:
6 logits = model(xb) # model has Dropout + BatchNorm layers
7 preds = logits.argmax(dim=1)
8 correct += (preds == yb).sum().item()
9 total += yb.size(0)
10 return correct / total
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.