Hard Distillation vs Soft Distillation

마지막 수정:

distillationhard-distillationsoft-distillationlogitssynthetic-data

모델 증류에서 가장 먼저 갈라지는 선택지는 무엇을 target으로 삼을 것인가다.

hard distillation: teacher가 고른 token/문장을 target으로 삼는다.
soft distillation: teacher의 전체 확률분포를 target으로 삼는다.

둘 다 teacher에서 student로 행동을 옮기지만, 필요한 접근 권한과 학습 신호가 다르다.

Hard distillation

Signal
teacher text / tokens
Loss
cross-entropy on target tokens
Access
teacher outputs are enough
Cost shape
cheap to store, easy to run offline

Soft distillation

Signal
teacher probabilities / logits
Loss
KL divergence between distributions
Access
needs logits or logprobs
Cost shape
large tensors, often online or same-family
Rule of thumb Use hard distillation when you only have generated text. Use soft distillation when you can afford teacher distributions and tokenizer alignment.
Hard and soft distillation differ by the training target. Hard distillation imitates the selected teacher sequence; soft distillation imitates the teacher's full uncertainty over alternatives.

Hard distillation

hard distillation은 teacher가 만든 결과물을 정답 sequence처럼 놓고 student를 학습한다.

prompt
  -> teacher answer
  -> student learns by next-token prediction

LLM에서는 이것이 매우 자연스럽다. teacher가 문제 풀이, 코드, 설명, tool-use trace를 생성하면, 그 text를 학습 데이터로 저장하고 student를 SFT하면 된다.

input:  "Explain gradient descent"
target: teacher가 생성한 설명 문장들
loss:   target token에 대한 cross-entropy

장점은 단순하다.

teacher logits가 없어도 된다.
API model 출력만으로 데이터셋을 만들 수 있다.
plain text라 저장과 필터링이 쉽다.
teacher와 student tokenizer가 달라도 처리하기 쉽다.

그래서 현대 LLM distillation, 특히 reasoning distillation에서는 hard distillation이 자주 쓰인다. DeepSeek-R1-Distill류 접근도 teacher의 reasoning trace와 answer를 curated dataset으로 만들고, student를 next-token prediction으로 fine-tune하는 형태에 가깝다.

Soft distillation

soft distillation은 teacher가 고른 token 하나만 보지 않는다. 같은 위치에서 가능한 모든 token이나 class에 대한 teacher의 분포를 student가 맞춘다.

teacher distribution q
student distribution p
loss ~= KL(q || p)

이 방식은 이전 카드에서 본 dark knowledge를 직접 전달한다. teacher가 선택하지 않은 token이라도 “그럴듯한 후보”라면 높은 확률을 받을 수 있고, student는 그 미묘한 차이를 배운다.

예를 들어 다음 token 후보가 있을 때:

Paris   0.92
Lyon    0.03
London  0.02
banana  0.00

hard distillation은 Paris만 target으로 본다. soft distillation은 LyonLondon의 낮지만 의미 있는 확률까지 본다.

단점은 비용과 접근성이다.

teacher logits/logprobs가 필요하다.
긴 sequence에서 full vocabulary distribution은 매우 크다.
teacher와 student vocabulary가 맞아야 비교가 쉽다.
training 중 teacher를 같이 돌려야 할 수도 있다.

그래서 soft distillation은 closed API teacher만 쓸 수 있는 상황에서는 어렵다. 반대로 같은 model family 안에서 teacher logits에 접근할 수 있고, 작은 모델이 teacher의 uncertainty를 배워야 한다면 강력한 선택지가 된다.

Hard와 soft는 반대말이 아니다

실제로는 둘을 섞을 수 있다.

total loss
  = hard-label cross entropy
  + soft-target KL divergence

hard loss는 grounding 역할을 한다. student가 실제 정답이나 teacher가 선택한 sequence를 놓치지 않게 만든다.

soft loss는 relationship transfer 역할을 한다. teacher가 후보들 사이에 나누어 둔 확률 구조를 옮긴다.

고전적인 Hinton식 distillation은 이 조합을 많이 떠올리게 한다. 반면 modern LLM distillation은 full distribution을 저장하기 어려워서 teacher-generated text를 쓰는 hard distillation 쪽으로 자주 기운다.

선택 기준

카드를 읽을 때는 다음 질문으로 판단하면 된다.

teacher logits를 볼 수 있는가?
student와 teacher tokenizer가 맞는가?
긴 reasoning trace 전체 분포를 저장할 수 있는가?
정답 sequence 모방이면 충분한가?
오답 후보 사이의 미묘한 분포까지 필요한가?

대부분의 제품형 LLM distillation은 먼저 hard distillation으로 시작한다. 데이터 생성, 필터링, 평가 루프를 만들기 쉽기 때문이다.

하지만 soft distillation은 여전히 중요하다. 다음 카드의 temperature와 KL loss는 바로 이 soft distillation을 제대로 쓰기 위한 장치다.

참고 자료

  • Geoffrey Hinton, Oriol Vinyals, Jeff Dean, Distilling the Knowledge in a Neural Network
  • Yoon Kim, Alexander M. Rush, Sequence-Level Knowledge Distillation
  • 로컬 참고: reference-books/reasoning-model-from-scratch/ch08-Distilling-reasoning-models-for-efficient-reasoning.md
  • 로컬 참고: reference-books/deepseek from scratch/ch08-Knowledge-distillation-Making-powerful-models-practical.md
  • 로컬 참고: reference-books/rlhf-book/ch12-Synthetic-Data.md

확인

  • hard distillation은 teacher의 무엇을 target으로 삼는가?
  • soft distillation은 왜 teacher logits 또는 logprobs가 필요한가?
  • LLM에서 hard distillation이 soft distillation보다 실용적인 경우가 많은 이유는 무엇인가?