nanoGPT 실전 학습 — GPT-2(124M) 재현 설정
nanoGPT 실전 학습 — GPT-2(124M) 재현 설정
GPT-2(124M)를 OpenWebText로 재현하려면 config/train_gpt2.py 설정 하나로 출발해요. 이 파일은 하이퍼파라미터를 파이썬 모듈로 정의해서, torchrun으로 8장 GPU DDP 학습을 돌리면 약 4~5일에 val loss ~2.85까지 내려가요.
출처: https://raw.githubusercontent.com/karpathy/nanoGPT/master/config/train_gpt2.py
실행 명령
# config for training GPT-2 (124M) down to very nice loss of ~2.85 on 1 node of 8X A100 40GB
# launch as the following (e.g. in a screen session) and wait ~5 days:
# $ torchrun --standalone --nproc_per_node=8 train.py config/train_gpt2.py
배치 크기 산출
# these make the total batch size be ~0.5M
# 12 batch size * 1024 block size * 5 gradaccum * 8 GPUs = 491,520
batch_size = 12
block_size = 1024
gradient_accumulation_steps = 5 * 8
batch_size 12 × block_size 1024 × gradaccum(5×8) × 8 GPU를 곱하면 총 배치가 약 0.5M 토큰이 돼요. 순수한 배치 크기가 아니라 그라디언트 누적과 GPU 수까지 반영한다는 점을 기억하면 돼요.
학습 스케줄
# this makes total number of tokens be 300B
max_iters = 600000
lr_decay_iters = 600000
# eval stuff
eval_interval = 1000
eval_iters = 200
log_interval = 10
# weight decay
weight_decay = 1e-1
max_iters와 lr_decay_iters를 맞춰 전체 학습 동안 러닝레이트가 선형 감소하도록 하고, weight_decay를 1e-1로 둔 것까지가 GPT-2 재현의 핵심 설정이에요.