How does model distillation transfer knowledge from teacher to student?
Intermediate · 2 min read · Fine-Tuning & Adaptation
Open in study mode to save this question and track progressShort answer: Model distillation trains a smaller, faster student model (e.g. 8B parameters) to mimic the output probability distributions or synthetic reasoning outputs generated by a larger, more capable teacher model (e.g. DeepSeek R1 or GPT-4o).
Detail
Running massive models in production incurs high GPU costs and latency. Distillation compresses teacher capabilities into compact student architectures.
[Teacher Model (70B / DeepSeek R1)] ──► Generates Synthetic Reasoning Traces (COT)
│
[Student Model (8B / Llama 3 8B)] ◄── SFT Loss ────┘ (Cross-entropy on teacher logits/text)
Distillation Paradigms
-
Logit-Based Distillation (Traditional KL-Divergence): The student model minimizes the KL divergence between its output logit distribution and the soft logits of the teacher model:
-
Sequence / Synthetic Data Distillation (Modern LLM Distillation): The teacher model generates thousands of synthetic Chain-of-Thought reasoning traces. The student model undergoes SFT directly on these teacher-generated reasoning datasets (used in DeepSeek-R1-Distill models).
Example
Synthetic dataset distillation loop concept in Python:
def generate_distillation_dataset(teacher_model, prompts: list[str]) -> list[dict]:
distilled_data = []
for prompt in prompts:
# Teacher outputs reasoning trace + answer
teacher_output = teacher_model.generate_cot(prompt)
distilled_data.append({
"instruction": prompt,
"response": teacher_output # High-quality synthetic reasoning trace
})
return distilled_dataInterview tips
- Highlight DeepSeek-R1-Distill-Llama-8B as a prime example of synthetic reasoning distillation achieving frontier-level math performance.
- Note legal licensing considerations when using proprietary commercial APIs (e.g. OpenAI terms prohibiting using output to train competing models).