gradient accumulation
-
Don't forget to accumulate the Gradient라이브러리/PyTorch 2022. 4. 26. 11:24
ViT와 같은 self-Attention based model 또는 CNN을 Group Normalization + Weight Standardization (Batch Normalization 대신)와 사용중이라면 gradient를 accumulate하는 것을 잊지마세요! Batch Normalization이 사용되고 있을 땐 gradient accumulation이 효과적이지 않을 지도 모르지만, 위와 같은 모델을 사용중이고 GPU VRAM이 한정적이여서 배치 사이즈를 작게 세팅하는 경우 효과적일 거야. AMP+Gradient accumulation은 더 효과적! from torch.cuda import amp scaler = amp.GradScaler() n_accumulate = 16 # n_ac..