Train mode 와 eval mode 는 다른 함수
일부 PyTorch layer — Dropout, BatchNorm, LayerNorm 의 affine=True 는 보통 같음 — 이 model 이 training 인지 evaluation 인지에 따라 행동 변함. Dropout 은 train 에서 random unit zero, eval 에서 identity. BatchNorm 은 train 에서 batch statistics, eval 에서 running statistics. Switch 잊으면 silent metric noise.
model.train() 과 model.eval() 로 switch. Recursive — top-level module 에 호출하면 모든 submodule switch.
model.train() 으로 시작, 모든 validation loop 가 model.eval() 로 시작. 5 줄 전에 올바르게 set 한 거 '안다' 해도.Eval mode 와 no_grad/inference_mode pair
Evaluation 에 gradient 안 필요, 계산하면 memory 와 시간 낭비. torch.inference_mode() (newer, faster) 또는 torch.no_grad() (older, 대부분 use case 에 equivalent) 사용.
흔한 eval bug
GPU 에서 accuracy 계산 후 CPU 값 print — 모든 .item() 이 CUDA sync 강제. GPU 에서 aggregate, epoch 끝에 한 번 sync.
Mismatched preprocessing — training 은 augmentation (random crop, flip, color jitter) 적용, evaluation 은 deterministic preprocessing (resize, center crop, normalize) 만. 둘 섞는 게 vision training 의 가장 흔한 silent bug.