티스토리 뷰

NLP /이것저것

Accumulated gradients

제이gnoej 2021. 8. 3. 17:00

batch-size 는 중요한 hyper parameter 중에 하나임. 

 

  • Batch size 가 너무 클 때: overfitting 
  • Batch size 가 너무 작을 때: noisy / slow convergence  => 하나의 data sample 미치는 영향이 너무 커지기 때문에 each step 이 noisy 

이 때, GPU 가 하나밖에 없고, memory limitation 도 있어서 내가 원하는 batch-size 로 training 하기 어려울 때 쓰는 테크닉이 바로 Accumulated gradients ! 

 

GPU memory 가 부족할 때는 mini-batch 란 것을 또 사용할 수 있음. batch 1개당 error 가 back propagate 되면서 optimization step 한번을 하는데, mini-batch 여러개 = global batch 1개가 되는거임. 

그니까 여러개의 GPU 를 가지고 있는데, 각 GPU 의 memory 가 작다면 mini-batch 를 이용해서 error 계산은 parallel 하게 하되, 얘네들의 error 을 다 모은다음에 gradient 계산은 은 여전히 global batch level 에서 하는거지. 그리고 이걸 이용해서 다시 각 mini-batch 에서 parameter update 가 일어나는건가?  => hugging face 에서 data parallelism 쓰면 자동으로 이렇게 되는 듯. 

"In data parallelism, data are split across multiple GPUs, where each GPU executes its own forward and backward operation and subsequently gradients are aggregated and results are broadcast back to the GPUs."

 

Gradient accumulation 은 상당히 비슷한데, GPU 가 하나만 있을 때! 

참고자료: 

https://towardsdatascience.com/how-to-break-gpu-memory-boundaries-even-with-large-batch-sizes-7a9c27a400ce

 

How to Break GPU Memory Boundaries Even with Large Batch Sizes

Overcoming the problem of batch size and available GPU memory in training neural networks

towardsdatascience.com

http://d2l.ai/chapter_computational-performance/multiple-gpus.html

 

12.5. Training on Multiple GPUs — Dive into Deep Learning 0.17.0 documentation

 

d2l.ai

 

'NLP > 이것저것' 카테고리의 다른 글

N-gram language model  (0) 2021.12.20
Naïve Bayes Classifier  (0) 2021.12.06
Word embedding vs Contextual embedding  (0) 2021.05.04
Cross entropy loss (feat. negative log likelihood)  (3) 2019.10.21
Subword encoder - tensorflow  (0) 2019.09.02
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함