Distillation, also called knowledge distillation, trains a small model to imitate a large one. The large model is the teacher, the small model is the student, and the training signal comes from the teacher's outputs rather than from ground-truth labels alone.
"Once the cumbersome model has been trained, we can then use a different kind of training, which we call 'distillation' to transfer the knowledge from the cumbersome model to a small model that is more suitable for deployment."
Source: Hinton, Vinyals, and Dean (2015), Distilling the Knowledge in a Neural Network
Hinton, Vinyals, and Dean named the technique and introduced temperature-scaled soft targets in Distilling the Knowledge in a Neural Network (2015), building on Buciluǎ, Caruana, and Niculescu-Mizil's 2006 model-compression work, which showed an ensemble's knowledge could be compressed into a single model. Hinton et al.'s own example: an image of a BMW may have only a small chance of being mistaken for a garbage truck, but that mistake is still many times more probable than mistaking it for a carrot. A model whose outputs encode that has learned something real about the structure of the problem. A one-hot label throws all of that away.
In LLM practice, distillation is a way to cut cost on narrow, high-volume tasks that are being served by a model far more general than the task requires.
Teacher and student
A distillation setup needs a capable teacher, a smaller student, and a transfer set of inputs on which the teacher's behavior is observed.
The transfer set needs no labels, only inputs (Hinton et al. note it "could consist entirely of unlabeled data"), which is what makes distillation practical, because unlabeled production traffic is abundant while labeled data is not. Whatever the transfer set covers is what the student inherits, and whatever it misses is where the student will be worst.
Size ratios vary widely. DistilBERT is 40% smaller than BERT and 60% faster while retaining 97% of its language-understanding capabilities; Kim and Rush's best translation student ran 10 times faster than its teacher with little loss in performance.
Dark knowledge and soft targets
The relative probabilities a teacher assigns across all classes, which Hinton, Vinyals, and Dean called dark knowledge in their 2014 talk, encode a similarity structure the teacher learned and a hard label cannot express. Hinton et al. found that soft targets carry much more information per training case than hard targets, so the student can often be trained on much less data. In their speech experiment, a model trained on soft targets from just 3% of the data recovered almost all of the accuracy of training on the full set.
High-entropy soft targets also produce much less variance in the gradient between training cases, so the student can use a much higher learning rate (same paper).
Distillation temperature vs. sampling temperature
The two are easy to confuse because both divide logits by a scalar before a softmax. Otherwise they are unrelated.
| Distillation temperature | Sampling temperature | |
|---|---|---|
| When it applies | Training, in the loss function | Inference, when generating tokens |
| Applied to | Teacher and student logits, identically | The model's output distribution |
| Purpose | Expose the teacher's low-probability structure | Control randomness of generated text |
| Typical value | 2.5 to 20 in Hinton et al. | Within the provider's allowed range |
| Lifecycle | Discarded once training ends | Set per request, forever |
At T = 1 a confident teacher's distribution is nearly one-hot and the dark knowledge is numerically invisible. Raising T softens both distributions so those small differences dominate the loss. Gradient magnitude from the soft term scales as 1/T², so Hinton et al. multiply the soft loss by T² to keep its contribution stable across temperature settings. Check for that factor in any hand-rolled distillation loss.
Once training ends, the student is served at whatever sampling temperature the application wants. The two settings never interact.
Sequence-level distillation
Matching full token distributions requires the teacher's full output distribution, which hosted APIs expose at most partially (OpenAI's top_logprobs returns at most the 20 most likely tokens per position). The practical alternative is sequence-level distillation: generate outputs from the teacher, then train the student on those outputs as ordinary supervised examples. Kim and Rush formalized this in Sequence-Level Knowledge Distillation, showing that training on teacher-generated sequences rather than token-level distributions improves performance and, usefully, seems to eliminate the need for beam search.
In practice, the recipe is to collect real inputs, generate outputs with a frontier model, filter hard, and fine-tune a small open-weight model on the survivors.
Whether the recipe produces a usable student depends on how the data is built:
- Filter the teacher's outputs. An unfiltered teacher dataset teaches the student the teacher's errors as if they were ground truth. Where outputs are checkable (code that compiles, JSON that validates, an answer that matches a known label), verify and discard. Prioritize filtering over adding volume.
- Sample the real input distribution. Hand-written synthetic prompts cluster around cases you already thought of. Production traffic contains the malformed, ambiguous, and adversarial inputs that decide whether the student survives deployment.
- Distill rationales, not only answers. Hsieh et al. show in Distilling Step-by-Step that using teacher reasoning as additional supervision lets smaller students beat larger models with less data: their fine-tuned 770M T5 model outperformed few-shot prompted 540B PaLM using 80% of the available data on one benchmark.
- Generate with the batch API. Teacher generation can be the largest cost and has no latency requirement, which makes it a natural fit for a provider's asynchronous batch endpoint. Both OpenAI and Anthropic price batch requests at 50% off.
The mechanics of the training step are ordinary supervised fine-tuning, covered in fine-tuning. Distillation is a strategy for producing the dataset, not a different training algorithm.
Distillation vs. other ways to get a smaller model
| Approach | What it changes | Cost to produce | Preserves | Main risk |
|---|---|---|---|---|
| Distillation | Trains new, smaller weights on teacher behavior | Teacher generation plus a fine-tune | Task behavior, not general capability | Student is narrow; inherits teacher errors |
| Quantization | Precision of existing weights | About four GPU hours for a 175B model with GPTQ | The same model, approximately | Emergent outlier features need special handling (LLM.int8()) |
| Pruning | Removes weights, heads, or layers | One-shot methods such as SparseGPT need no retraining | Architecture with reduced capacity | Hardware speedups need a supported pattern such as 2:4 (Mishra et al.) |
| Smaller off-the-shelf model | Nothing, you switch models | Zero | Nothing specific to you | Weaker on the task with no path to improve |
The approaches combine. You can distill first, then quantize the student, and the reductions multiply: a 10x smaller model at 4-bit is roughly 40x less weight memory than the BF16 teacher.
Start with the off-the-shelf small model, though. If a well-prompted small model already meets your bar, distillation is wasted work, and knowing how far the cheap option gets you is the baseline you need to judge the student anyway.
The economics
For a narrow, high-volume task, distillation attacks the per-token price directly, while caching and prompt trimming reduce the number of tokens.
Production tasks are narrow. A frontier model can write poetry, debug Rust, and reason about tax law; your ticket classifier needs one of those capabilities and pays for all of them on every request.
It pays off on high-volume, stable tasks where a one-time training cost amortizes, on latency-sensitive paths (a small model is faster as well as cheaper, with lower time to first token and higher tokens per second), and under deployment constraints such as on-device or air-gapped serving where a frontier API is not an option at any price.
It does not pay off at low volume (the training cost never amortizes), on open-ended tasks (the capability you are cutting is the product), or against fast-moving requirements (each change means regenerating and retraining).
Check licensing terms before you distill
Licensing carries commercial risk. Some provider agreements restrict using model outputs to build competing models. Anthropic's commercial terms state that a customer may not "access the Services to build a competing product or service, including to train competing AI models." Check every provider's terms for similar clauses.
Before you distill:
- Read the specific agreement covering your account, not a summary. Terms differ between consumer, standard commercial, and enterprise contracts, and they change.
- "Competing model" is the operative phrase and it is not self-defining. A model that classifies your own support tickets reads very differently from a general-purpose assistant you intend to sell.
- Open-weight teachers have their own licenses. Meta's Llama 3.1 license, for example, requires any distributed model trained or fine-tuned on Llama outputs to put "Llama" at the beginning of its name.
- Keep provenance records: which teacher, which version, which terms were in force, and which outputs went into which training run.
Spend five minutes on legal review before you spend a month on distillation.
Evaluating the student
The student is a new model and needs a real comparison, not a vibe check.
- Agreement with the teacher on held-out inputs is the primary metric, since reproducing the teacher is the objective. Measure it on outputs the training set never saw.
- Task metrics against the same baseline as the teacher. Equal agreement can still mean worse absolute quality if the teacher was wrong on a systematic subset.
- Where the gap concentrates. Aggregate agreement of 95% is fine if the 5% is spread evenly and unacceptable if it is entirely your highest-value input category.
- Robustness outside the transfer distribution. Test the student on inputs the transfer set did not cover, since an eval drawn from the same distribution will not show how it handles them.
- A general capability check. The student lost something; the question is whether you needed it.
Run teacher and student behind one API so the comparison is a config change. Bifrost OSS lets you compare model quality, cost, and latency across providers behind one endpoint.
Key takeaways
- Distillation temperature is a training-time knob applied to logits in the loss (with a T² correction) and is unrelated to inference sampling temperature.
- Sequence-level distillation fits hosted teachers: generate teacher outputs, filter them hard, fine-tune the student. Prioritize filtering over volume.
- Some provider terms (Anthropic's among them) prohibit using outputs to train competing models; verify the license before committing to a teacher.
Sources and further reading
- Hinton et al., Distilling the Knowledge in a Neural Network (full text)
- Hinton et al., Distilling the Knowledge in a Neural Network (arXiv 1503.02531)
- IBM, What is knowledge distillation?
- Sanh et al., DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter
- Kim & Rush, Sequence-Level Knowledge Distillation
- Hsieh et al., Distilling Step-by-Step! Outperforming Larger Language Models with Less Training Data and Smaller Model Sizes
- PyTorch, torch.nn.functional.kl_div
- OpenAI, Chat API reference
- OpenAI, Batch API
- Anthropic, Batch processing
- Anthropic, Commercial Terms of Service
- Meta, Llama 3.1 Community License Agreement
- Bifrost, OpenAI SDK integration
- Bifrost, Files and Batch API
- Bifrost, Built-in Observability
- Bifrost, OSS for Startups
- Buciluǎ, Caruana & Niculescu-Mizil, Model Compression (KDD 2006)
- Frantar et al., GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers
- Dettmers et al., LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale
- Hinton, Vinyals & Dean, Dark knowledge (TTIC talk slides, 2014)
- Mishra et al., Accelerating Sparse Deep Neural Networks
- Frantar & Alistarh, SparseGPT: Massive Language Models Can Be Accurately Pruned in One-Shot