C.W.K.
Stream
Lesson 04 of 07 · published

파인튜닝이 실제로 뭘 하는 건지

~20 min · gradients, transfer-learning, mental-model

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

같은 학습 루프, 다른 데이터

안을 들여다보면, 파인튜닝은 gradient 기반 최적화야 — 모델 사전학습할 때 쓴 것과 정확히 같은 과정 — 네 데이터에 훨씬 적은 step만 돌리는 거야.

  1. Forward pass: 학습 예제가 모델을 통과해서 예측(다음 토큰 분포)을 만들어.
  2. Loss: 예측이 원하는 출력과 비교돼. Cross-entropy가 표준.
  3. Backward pass: gradient 계산 — 각 파라미터가 에러에 얼마나 기여했는지.
  4. Update: 옵티마이저(보통 AdamW)가 loss 줄이려고 각 파라미터를 살짝 nudge.
  5. Repeat: 수백~수천 예제, 몇 epoch.

Transfer learning이 마법의 정체

사전학습된 모델은 이미 언어, 기본 추론, 방대한 세상 지식을 알아. 파인튜닝은 그 지식을 네 도메인으로 transfer해. 영어를 가르치는 게 아니라, 네 영어를 가르치는 거야.

그래서 파인튜닝이 trillion 토큰 대신 수백~수천 예제로 작동하는 거야. 기초는 이미 있어; 표현만 조정하는 거야. 가장 깔끔한 비유: 사전학습은 의대, 파인튜닝은 심장학 펠로우십. 해부학 다시 안 배워.

변화가 사는 곳

Full 파인튜닝은 모든 파라미터를 업데이트해. PEFT 기법(LoRA, QLoRA, DoRA — Track 4)은 추가된 작은 subset만 업데이트, 보통 파라미터의 0.1~1%야. 이게 컴퓨트 비용도 줄이고 동시에 베이스 모델의 일반 능력이 덮어쓰여지지 않게 보호해.

Code

What a single training step looks like in PyTorch·python
import torch
from torch.optim import AdamW

model.train()
optimizer = AdamW(model.parameters(), lr=2e-5)

for batch in train_loader:
    # 1. Forward pass — model produces logits over the vocab
    outputs = model(**batch, labels=batch["input_ids"])
    loss = outputs.loss

    # 2. Backward pass — compute gradients
    loss.backward()

    # 3. Update — optimizer nudges weights using the gradients
    optimizer.step()

    # 4. Reset gradients for the next batch
    optimizer.zero_grad()

    print(f"loss={loss.item():.4f}")
# That's the entire core. Everything else (LoRA, mixed precision,
# gradient checkpointing) is optimization wrapped around these four lines.

External links

Exercise

기억으로 4단계 루프 종이에 그려: forward, loss, backward, update. 그 다음 mixed precision(bf16/fp16), gradient checkpointing, LoRA가 각각 그 4단계 중 어디를 어떻게 바꾸는지 두 문장씩 설명.

Progress

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

댓글 0

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

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