18.9 Distillation data, student rollouts, and deployment
Distillation transfers a teacher’s behavior into a student with a different cost or deployment profile. The important choices are what the teacher supplies, which prefixes the student sees, what discrepancy is optimized, and how the final student is evaluated. The KL implementation covers the probability arithmetic; this part covers the recipe and its engineering.
Concepts from other sections (6)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- logits: unnormalized log-scores that softmax turns into probabilities; here the table stores . Read more: 6.1 Byte bigram: counts, logits, safetensors v0
- Entropy: , the average surprise of a distribution. Read more: 17.1 Entropy, cross-entropy, KL, JS, and the k3 estimator in Mathematics
- forward KL: , weighted by the teacher; mass-covering. Read more: 18.4 Distillation with forward and reverse KL
- reverse KL: , weighted by the student; mode-seeking. Read more: 18.4 Distillation with forward and reverse KL
- Task success: whether an agent accomplished its objective end to end; the agent metric that matters most. Read more: Chapter 29: LLM Evaluation
- time to first token (TTFT): the time until the first body byte of an answer is ready to send to the client. Read more: 25.3 The SSE streaming proxy
Learning objectives
- Separate sequence distillation, distribution distillation, and feature matching.
- Treat prefix distribution and KL direction as independent choices.
- Measure compression using quality and total serving cost.
What evidence can the teacher provide?
Section titled “What evidence can the teacher provide?”| Teacher access | Training signal | Engineering consequence |
|---|---|---|
| Generated text only | SFT on accepted teacher answers | Works with text APIs; records one answer rather than the full distribution |
| Token probabilities/logits | Cross entropy or KL on aligned token distributions | Large tensors; vocabulary alignment and exact normalization matter |
| Hidden representations | Feature or attention matching with projections if needed | Requires internal model access and compatible layer/shape mappings |
| Scores on student answers | Reward or preference signals, or sampled distribution objectives | Needs a clearly specified estimator; it is not automatically full-logit distillation |
For sequence-level distillation, generate candidate answers, filter or score them, and train on accepted examples. A single sampled target omits alternatives and can teach teacher errors. A deterministic decoding teacher and a stochastic teacher produce different datasets. Freeze prompts, generation parameters, teacher revision, provenance, and filtering decisions.
For distribution distillation, freeze the teacher and differentiate through the student. With teacher and student , forward KL weights by teacher mass; reverse KL weights by student mass. The original distillation paper introduces temperature-softened targets. Teacher entropy, student capacity, and the chosen discrepancy all affect behavior.
Whose prefixes are used?
Section titled “Whose prefixes are used?”Offline text or teacher trajectories offer reusable targets. Student-generated prefixes expose the teacher to the states the student actually visits, including mistakes. This is on-policy distillation in the prefix-distribution sense. It does not prescribe forward or reverse KL; one can evaluate several discrepancies on those prefixes. On-policy distillation explicitly studies this distribution-shift problem.
An illustrative mixed objective is
Specify the prefix source, response mask, reduction denominator, temperature, and mixing coefficient. Both distributions use the same temperature in this formulation. The factor compensates for a high-temperature gradient-scale effect; it does not guarantee one learning rate works for every temperature or student.
When teacher and student vocabularies differ, tokenwise KL over vocabulary indices is undefined without a justified alignment. Use text targets or an explicitly designed cross-tokenizer method. A top-k log-probability API also omits probability mass: renormalizing its top-k entries creates a different distribution. Do not present it as exact full-vocabulary KL.
Data and memory budgeting
Section titled “Data and memory budgeting”With 100,000 sequences, 512 scored positions, 32,000 vocabulary entries, and two-byte logits, a full cached tensor would occupy about 3.28 TB before metadata and masks. Streaming teacher batches, recomputing logits, restricting positions, or storing sparse summaries trades storage against compute and approximation. Name the approximation and test its effect.
Student rollouts add generation cost, teacher scoring cost, and synchronization just as RL does. A frozen teacher need not reside alongside all learner optimizer state if scoring is a separate stage. Conversely, copying the teacher to every learner rank can dominate memory. Plan the pipeline by live tensors, not parameter counts alone.
Validate the student after export
Section titled “Validate the student after export”Evaluate base student, distilled student, and teacher on the same held-out tasks. Include errors the teacher makes, long contexts, uncommon formats, calibration where relevant, and robustness to student-generated imperfect prefixes. Teacher agreement is a training-related metric; actual task success is a separate outcome.
Then measure time to first token, inter-token latency, goodput, weight/cache memory, output length, and total task cost on the deployment runtime. A student that answers with twice as many tokens or escalates frequently may not deliver the expected saving. Conversion, adapter merge, and quantization each require new artifact and numerical checks.
Key terms
Section titled “Key terms”- Sequence distillation: training on teacher-generated target sequences.
- Distribution distillation: training against a teacher’s probability distribution.
- Prefix distribution: the histories on which teacher and student predictions are evaluated.
Summary
Section titled “Summary”Choose teacher access, prefix source, discrepancy, and deployment target separately. Evaluate task performance and end-to-end cost after every transformation.
Review questions
Section titled “Review questions”-
Does student-generated data force reverse KL?
Answer
No. Prefix source and divergence direction are independent design choices. -
Can an API’s top-five token probabilities establish exact full-vocabulary KL?
Answer
No. The omitted mass and its allocation are unknown. Any renormalization or tail approximation must be specified.