Distillation
Quantization shrinks the bits of an existing model. Distillation does something different: it trains a brand-new, smaller model to imitate a big one. You pay an upfront training run once, and then serve a model that is cheaper on every token for the rest of its life. That trade — one training bill for a permanently lower inference bill — is the whole point.
The idea
Section titled “The idea”Take a large, accurate teacher model and a small student model. Train the student not just on the right answers, but on the teacher’s full output distribution. The student learns to produce the same outputs as the teacher, at a fraction of the size and cost.
┌─────────────┐ soft labels / logits ┌──────────────┐ │ TEACHER │ ───────────────────────▶ │ STUDENT │ │ (large) │ │ (small) │ └─────────────┘ "imitate me" └──────────────┘ expensive, once cheap, foreverWhy soft labels carry more signal
Section titled “Why soft labels carry more signal”A hard label says “this token is cat, everything else is wrong.” The teacher’s soft labels — its probabilities over all tokens — say much more: “85% cat, 10% kitten, 4% feline, …”. That distribution encodes the teacher’s learned similarity structure (a cat is closer to a kitten than to a truck). The student learns this richer signal in one example instead of needing thousands to infer it.
To expose this structure you soften the teacher’s distribution with a temperature T before computing the loss:
softmax_T(z)_i = exp(z_i / T) / Σ_j exp(z_j / T)Higher T flattens the distribution, amplifying the small probabilities (the “dark knowledge”) that carry the relational information. A typical loss blends two terms:
L = α · KL(student_soft ‖ teacher_soft) ← match the teacher + (1-α) · CE(student, hard_label) ← still get the truth rightWhy it works
Section titled “Why it works”The teacher has already done the expensive job of carving a good function out of a huge parameter space. The student doesn’t have to rediscover that function from raw data — it just has to fit the teacher’s outputs, a far easier target than the original task. A small model trained from scratch on hard labels often underfits; the same small model trained to mimic a strong teacher reaches noticeably higher quality, because the teacher hands it a smoother, more informative target.
Three flavors
Section titled “Three flavors”| Type | Student matches… | Cost / detail |
|---|---|---|
| Response (logit) | teacher’s output probabilities | simplest, most common; only needs teacher outputs |
| Feature | teacher’s intermediate hidden states | richer signal, needs layer alignment |
| Relation | relationships between examples/layers | matches structure, not just values |
Response-based distillation is the default — you can even do it through an API by collecting the teacher’s outputs on a corpus of prompts.
Examples
Section titled “Examples”- DistilBERT-style — a classic: a student with ~40% fewer parameters than BERT retains roughly ~95–97% of its quality while running materially faster. The template for “encoder distillation.”
- Smaller chat models — many compact instruct/chat models are trained on outputs generated by a larger, stronger model (sequence-level distillation: the teacher’s generated text becomes the student’s training data). The small model inherits much of the big model’s behavior at a fraction of serving cost.
The cost, stated plainly
Section titled “The cost, stated plainly”Distillation is not free magic:
- Upfront training run. You need the teacher (often the expensive part — generating soft labels or synthetic data over a big corpus) plus the student’s training compute. This is real money, paid once.
- Some quality loss. The student is smaller; it will trail the teacher, especially on the long tail of hard cases. You’re trading a few accuracy points for a large, permanent cost reduction.
The dollars view
Section titled “The dollars view”Concretely: suppose a 70B teacher costs $X per million tokens to serve and a distilled 7B student that keeps ~90% of the quality costs roughly $X/8. The distillation run might cost the equivalent of a few million tokens of teacher inference. If you serve hundreds of millions of tokens a month, that one-time cost is recovered in days, and from then on every token is ~8× cheaper — in latency, memory, and dollars — for the life of the deployment.
The architect’s lens
Section titled “The architect’s lens”Step back from soft labels and temperature and weigh distillation as a deployment decision:
- Why does it exist? Because a small model trained from scratch on hard labels underfits, while the same model trained to mimic a strong teacher’s full output distribution reaches noticeably higher quality — you buy a permanently cheaper model with one training run.
- What problem does it solve? A high, recurring per-token inference bill: a distilled 7B student keeping ~90% of a 70B teacher’s quality serves each token at roughly 1/8th the cost — in latency, memory, and dollars — forever.
- What are the trade-offs? It moves cost from inference (recurring) to training (one-time, often dominated by generating the teacher’s soft labels) and accepts some quality loss, especially on the long tail of hard cases.
- When should I avoid it? When inference volume is low — the training run may never amortize, so just quantize an off-the-shelf model instead.
- What breaks if I remove it? Nothing structurally — you either keep serving the big teacher (higher quality, far higher cost) or ship a from-scratch small model that underfits the same data.
Check your understanding
Section titled “Check your understanding”- Why do a teacher’s soft labels carry more learning signal than the hard ground-truth label?
- What does the temperature
Tdo in the distillation softmax, and why is a higherTuseful? - Distinguish response, feature, and relation distillation in one line each.
- Why can a small model distilled from a strong teacher beat the same small model trained from scratch on hard labels?
- Under what traffic conditions does distillation’s economics actually pay off, and when does it not?
Show answers
- They give a full probability distribution over all classes, encoding the teacher’s learned similarity structure (which wrong answers are close), so the student learns relational “dark knowledge” the single hard label can’t convey.
Tsoftens (flattens) the distribution by dividing logits before softmax; higherTamplifies the small probabilities that carry the relational information, exposing the teacher’s structure to the student.- Response = match the teacher’s output probabilities; Feature = match its intermediate hidden states; Relation = match relationships between examples/layers rather than raw values.
- The teacher provides a smoother, more informative target than raw hard labels; fitting that target is an easier optimization problem than rediscovering the function from scratch, so the student underfits less.
- It pays when inference volume is large and sustained, so the permanently lower per-token cost outweighs the one-time training bill; for low-traffic workloads the training run may never amortize, and quantizing an existing model is better.