C.W.K.
Stream
Lesson 02 of 06 · published

배치 크기 & Gradient Accumulation

~18 min · batch-size, gradient-accumulation, effective-batch

Level 0관찰자
0 XP0/43 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Effective batch 공식

effective_batch = per_device_batch × gradient_accumulation_steps × num_GPUs

큰 effective batch는 더 부드럽고 안정적 학습 주지만 step당 메모리 더 씀. 큰 배치가 VRAM에 안 들어가면 gradient accumulation 써 — 여러 작은 배치에 대한 gradient를 합한 다음 가중치 업데이트.

Effective batch 가이드라인

데이터셋 크기추천 effective batch
1,000개 미만4~8
1,000~10,00016~32
10,000+32~128

Code

Achieve effective batch size of 32 on a single GPU·python
from trl import SFTConfig

args = SFTConfig(
    per_device_train_batch_size=2,      # small batch fits in VRAM
    gradient_accumulation_steps=16,     # accumulate 16 steps
    # Effective batch: 2 × 16 = 32
)

External links

Exercise

세 셋업에서 effective batch 16 달성할 옳은 gradient_accumulation_steps 계산: 24GB GPU 한 장 + per_device=4, 80GB GPU 한 장 + per_device=8, 24GB GPU 4장 + per_device=2. 수학 검증.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.