[Hyperparameters] Batch/Batch size/Epoch/Iteration 배치, 에포크

딥러닝 모델의 하이퍼파라미터 Batch size와 Epoch에 대한 개념을 정리합니다.

Must specify the "batch size" and "# of epochs" for training. 딥러닝 모델 훈련을 위해 batch_size=epoch=를 지정해야하는데, 관련 개념들을 정리해보자.

Batch/Batch size/Epoch/Iteration

훈련 데이터는 하나 이상 혹은 그 이상의 batches 로 나눌 수 있다.

Iteration

  • A single update of a model's weights during training 훈련 중 한번의 모델 파라미터 업데이트
  • An iteration consists of computing the gradients of the parameters with respect to the loss on a single batch of data.

Epoch

  • # of complete passes through the whole training set (1 ≤ Epoch ≤ infinity)
  • 전체 훈련 데이터를 한 번 도는 것으로 훈련 단계를 구분하는데 쓰인다.
  • An epoch is comprised of one or more batches

Batch

  • 한 번의 Iteration에 사용되는 훈련 샘플 셋, 전체 훈련 데이터 셋의 N 개 표본

  • Batch size: 모델 파라미터 업데이트 전 처리하는 훈련 샘플의 개수(#), 한 번의 Iteration에 사용되는 훈련 데이터 셋의 크기 (1 ≤ Batch size ≤ # of the samples in the training set)

  • 하나의 배치를 훈련한 후 모델 파라미터를 업데이트한다.

  • a tension between batch size and the speed and stability of the learning process

  • The larger the batch, the more samples propagate through the model in the forward pass. Since a batch size increase will require more GPU memory, a lack of GPU memory can prevent you from increasing the batch size.

Example

A dataset with 200 samples (rows of data) and you choose a batch size of 5 and 1,000 epochs.

  • batch size : 5 , total samples : 200
    ⇒ $\frac{200}{5}=$ 40 batches each with 5 samples
  • 1 epoch will involve 40 batches (the whole data set) / 40 updates to the model
    ⇒ 1,000 epochs : the model will pass through the total of 40,000 batches during the entire training process