Coding, Filming, and Nothing

날짜: 2023년 3월 14일

where get inspired: Multi-GPU learning을 하다가 용어 발견

Answer sources: new Bing(LLM)


유효한 배치 크기(Effective Batch Size)란?

유효한 배치 크기는 모델이 각 업데이트 단계에서 처리하는 샘플의 총 수를 의미합니다. 단일 장치(예: 단일 GPU)에서 훈련할 때 유효한 배치 크기는 데이터 로더에서 지정된 배치 크기와 같습니다.

 

그러나 데이터 병렬성 또는 분산 데이터 병렬성을 사용하여 여러 장치(예: 여러 GPU)에서 훈련할 때 각 장치는 전체 배치의 일부를 받습니다. 이 경우 유효한 배치 크기는 데이터 로더에 지정된 배치 크기에 훈련에 사용되는 장치 수를 곱한 값과 같습니다.

예를 들어, 배치 크기가 2이고 devices=[2,3]을 사용하여 두 개의 GPU를 사용하는 경우 각 GPU는 각 순방향 및 역방향 패스마다 2개의 크기의 배치를 받게 됩니다. 모델이 각 업데이트 단계에서 볼 수 있는 유효한 배치 크기는 4(각 GPU당 2)입니다.

 

모델이 각 업데이트 단계에서 처리하는 샘플 수 관점에서 여러 GPU에 걸쳐 데이터 병렬성 또는 분산 데이터 병렬성을 통해 얻은 유효한 배치 크기 4는 단일 GPU에서의 배치 크기 4와 동등합니다. 그러나 두 시나리오 사이에 최적화 동작 차이가 있을 수 있습니다. 데이터 병령성 또는 분산 데이터 병령성을 사용할 때 기울기가 각 GPU에서 독립적으로 계산되고 모델 매개변수를 업데이트하기 전에 GPU간 평균이 계산됩니다. 이로 인해 단일 GPU에서보다 추가적인 잡음이 기울기 추정값에 들어갈 수 있습니다.

 

실제로 이 차이들은 종종 작으며 학습률 및 다른 하이퍼파라미터 조정으로 완화될 수 있습니다. 그러나 여러 개의 GPU와 데이터 병렬성 또는 분산 데이터 병렬성을 사용하는 것은 다행일 하나의 대형 배치를 사용하는 것과 정확히 동등하지 않다는 점을 명심해야 합니다.

 

 

 

 

 

 

==

Eng.

 

 

Effective Batch Size: What It Is and How It Works

When training a machine learning model, one important concept to understand is the effective batch size. In this post, we’ll explain what the effective batch size is and how it differs from the batch size specified in the data loader.

The effective batch size refers to the total number of samples processed by the model during each update step. When training on a single device (e.g., a single GPU), the effective batch size is equal to the batch size specified in the data loader.

However, when training on multiple devices (e.g., multiple GPUs) using data parallelism or distributed data parallelism, each device receives a portion of the full batch. In this case, the effective batch size is equal to the batch size specified in the data loader multiplied by the number of devices being used for training.

For example, if you have a batch size of 2 and use two GPUs with devices=[2,3], each GPU will receive a batch of size 2 for each forward and backward pass. The effective batch size seen by the model during each update step is 4 (2 per GPU).

In terms of optimization behavior, there may be some differences between using an effective batch size achieved through data parallelism or distributed data parallelism across multiple GPUs and using a single larger batch on a single GPU. When using data parallelism or distributed data parallelism, gradients are calculated independently on each GPU and then averaged across GPUs before updating the model parameters. This can introduce some additional noise into gradient estimates compared to calculating gradients on a single larger batch on a single GPU.

In practice, these differences are often small and can be mitigated by adjusting hyperparameters such as learning rate. However, it’s important to keep in mind that using multiple GPUs with data parallelism or distributed data parallelism is not exactly equivalent to using a single larger batch on a single GPU.

profile

Coding, Filming, and Nothing

@_안쑤

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!