Overview

7 Knowledge distillation: Capturing frontier model intelligence

This chapter shows how knowledge distillation can turn a strong teacher model into a smaller, cheaper student that preserves much of the teacher’s behavior. In practice, the process looks like supervised fine-tuning with a different data source: prompts are sent to a teacher, the responses are collected, filtered for quality, and then used to train a student on your own infrastructure. The appeal is not just performance, but the combination of lower cost, better privacy, lower latency, and greater operational independence. The chapter frames this as a black-box pipeline that works whether the teacher is a local model or a frontier API.

The hands-on workflow emphasizes that most of the success comes from the data pipeline rather than the training code. Good prompt design matters, especially diversity across normal cases, edge cases, difficult cases, and even adversarial prompts. Teacher outputs must then be screened for truncation, repetition, refusals on benign inputs, contamination with test examples, and other low-quality patterns before training begins. Once the verified data is ready, the student is trained with the same LoRA and SFT machinery used earlier in the book, and evaluation compares base, teacher, and student side by side. The key metric is retention: how close the student comes to the teacher’s score, with category-level analysis helping identify where the student keeps up and where it falls behind.

The chapter also explains when distillation is the right tool and when it is not. It is most attractive for stable tasks with enough query volume to justify the upfront work, especially when privacy, latency, or cost pressures make direct API use undesirable. However, distillation is lossy: it compresses behavior rather than creating new capability, and safety alignment does not reliably transfer unless refusal examples are explicitly included. The chapter closes by comparing forward and reverse KL as optimization choices, noting that standard forward-KL-style training is usually enough for enterprise use, while more specialized divergence methods matter only in narrower cases. Overall, the message is that distillation is a practical way to capture frontier-model behavior, but only if the data, evaluation, and safety checks are handled carefully.

Black-box distillation pipeline
Teacher data quality filtering and category distribution after the 159/40 split.
Student distillation training dashboard: a healthy run, with loss falling to 1.2, validation loss tracking it, and token accuracy around 69%.
Three-way Token-F1 comparison across categories on the held-out test split: the distilled student retains about 98% of the teacher’s score.
White-box vs. black-box distillation: black-box trains on the teacher's text outputs with any API; white-box trains on the teacher token probabilities and needs access to the teacher weights.
DeepSeek-R1 retention by student size: MATH-500 holds above 86% at every size, while AIME 2024 falls to 36% at 1.5B.

Summary

  • Distillation is supervised fine-tuning where the training data comes from a stronger teacher model rather than from human annotators; the student inherits the teacher's behavioral patterns at a fraction of the inference cost.
  • Distillation is a capital investment: spending $1,000 to $2,000 upfront on teacher data generation and student training saves $1,000+ per month in ongoing API costs, with break-even typically at one to three months.
  • Black-box distillation (training on teacher text outputs) is the practical default for enterprise work because it works with any teacher model, including proprietary APIs.
  • The commonly cited 70 to 90% retention range is heavily task-dependent: well-matched tasks can exceed 95%, while hard reasoning tasks with small students can drop well below 70%.
  • Data quality drives student quality: filtering degenerate teacher outputs (terse answers, repetition) is a cheap safeguard worth keeping even when few examples are caught.
  • Distillation reproduces the teacher's behavior cheaply. Still, it copies the teacher's gaps too: in our run, the student matched the teacher's house format on every held-out test prompt and reached about 98% of its Token-F1, yet it lost harmful-request refusals the base model had. Safety alignment does not carry over via distillation, so each student model must be independently tested for safety regressions before deployment.

FAQ

What is knowledge distillation in LLM customization?Knowledge distillation is essentially supervised fine-tuning where the training data comes from a stronger “teacher” model instead of human annotators. A smaller “student” model learns to reproduce the teacher’s behavior, so you can run a cheaper model locally while keeping much of the teacher’s quality.
Why do teams use distillation instead of calling a frontier model directly?Distillation can reduce cost, protect privacy, lower latency, and improve operational independence. Instead of sending every user request to an external API, you use the teacher only to generate training data once, then serve a local student at inference time.
What are the main stages of a black-box distillation pipeline?The pipeline has five stages: design prompts for the task, generate teacher responses, filter low-quality outputs, train the student on the verified data, and evaluate the student against both the base model and the teacher.
How important is prompt diversity when generating teacher data?Very important. A smaller set of diverse prompts usually works better than a larger set of repetitive ones. Good distillation prompts should cover common production queries, edge cases, varying difficulty levels, and even adversarial inputs when refusal behavior matters.
What is the purpose of quality filtering in distillation?Quality filtering removes degenerate teacher outputs before they become training data. Typical checks include minimum and maximum length limits and repetition detection. This helps prevent the student from learning short, broken, or repetitive responses.
How do you evaluate whether a distilled student is good enough?Use a three-way comparison: base model, teacher, and student. The chapter’s main metric is retention rate, defined as the student’s score divided by the teacher’s score on the same held-out evaluation set. A common goal in black-box distillation is around 70% to 90% retention, though results vary by task.
Why might Token-F1 be insufficient for judging distillation quality?Token-F1 measures lexical overlap, so it can miss important behavioral differences. A student can paraphrase correctly and score low, or copy similar words while giving a worse answer and score high. That’s why the chapter also recommends behavioral checks and, when needed, an LLM judge.
When should you think about forward KL versus reverse KL in distillation?For most enterprise distillation projects, forward KL is the default because standard SFT on teacher outputs already matches that setup. Reverse KL matters more when you need a very focused student, have white-box access to teacher probabilities, or need tighter control over precise output formats. In practice, data volume usually matters more than changing the divergence.
Does safety alignment automatically transfer from teacher to student?No. The chapter emphasizes that safety does not transfer reliably through distillation. A student trained only on benign teacher outputs may lose refusal behavior, so you should explicitly include harmful prompts paired with the teacher’s refusals and run a robustness check before deployment.
When is distillation worth it, and when should you skip it?Distillation is most attractive for stable tasks with moderate to high query volume, where a 10% to 20% quality gap is acceptable and latency or privacy matter. It is usually not worth it for low-volume use cases, rapidly changing tasks, or high-stakes domains where even a small quality loss is unacceptable.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Customization and Fine-Tuning ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Customization and Fine-Tuning ebook for free