Notes
The idea
The idea is simple. You have a big teacher model that already does your task well, and a small student model that does not, yet. Run the teacher on many real inputs and keep its answers. Then fine-tune the student on those pairs, exactly like the previous episode. In production you serve the student, which is far cheaper and faster, and you can host it yourself. The price is breadth: it is good at your task and little else.
- teacher: a big model that already does the task well
- student: a small model that does not, yet
- run the teacher on many real
- inputs, keep its answers, then fine-tune the student on them
- serve the student
Cost: the teacher
Let us put numbers on it, with illustrative prices. Each request sends a thousand input tokens and gets two hundred output tokens back. Say the teacher costs three dollars per million input tokens and fifteen per million output tokens. That is zero point three cents for input plus zero point three cents for output, so zero point six cents a request. Times a million requests, that is six thousand dollars a day, about one hundred and eighty thousand a month.
per request: 1,000 in, 200 out illustrative price per 1M tokens: input 3 USD, output 15 USD in: 1,000 x 3 / 1M = 0.003 out: 200 x 15 / 1M = 0.003 per request = 0.006 USD x 1M a day = 6,000 USD / day x 30 days = ~180,000 USD / month
Cost: the student
Now the student, at fifteen cents per million input tokens and sixty cents per million output. Per request that is zero point zero two seven cents. A million requests cost two hundred and seventy dollars a day, roughly twenty two times cheaper. It is also several times faster. Building it is a one off cost: fifty thousand teacher labels is about three hundred dollars, plus judging and training. It pays for itself within days.
illustrative price per 1M tokens: input 0.15 USD, output 0.60 USD in: 1,000 x 0.15 / 1M = 0.00015 out: 200 x 0.60 / 1M = 0.00012 per request = 0.00027 x 1M a day = 270 USD / day about 22x cheaper than teacher one-off cost: labels + training, a few days of teacher traffic
Real prompts
The inputs should come from real traffic, not prompts you made up, because the student only learns the distribution it sees. Sample from your logs, remove duplicates and near duplicates, and strip personal data. Then deliberately add the rare cases: very long inputs, other languages, messy formatting. First, set aside a test set the student never trains on. Ten thousand to a hundred thousand prompts is a common range for one task.
- sample from production logs, not prompts you invented
- remove duplicates and near-duplicates
- strip personal data
- cover rare cases on purpose (long inputs, odd languages)
- hold out a test set first
- typical: ~10k-100k prompts
Teacher answers
Labelling runs offline, so the teacher can take its time. Use your best and longest prompt, full of examples and rules. Let it reason step by step. Sample several answers per input and keep the best one. None of that slowness reaches users. A bonus: the student absorbs the long prompt's behaviour, so in production it needs only a short one.
- labelling runs offline, so latency does not matter:
- your best long prompt with examples and rules
- let it reason step by step
- sample several answers, keep the best one
- batch APIs: often ~half price
- the student sees only the result
Filter the outputs
The student copies the teacher's mistakes as faithfully as its good answers, so filter before training. Run cheap checks first. Is it valid JSON with the right schema? Is the label in the allowed list? Does the code compile and pass tests? Does it agree with the labels you already trust? Then a model judge, with a rubric, for what code cannot check. Expect to drop five to twenty percent, and read a sample yourself.
- cheap checks first:
- valid JSON, right schema
- label is in the allowed list
- code compiles, tests pass
- agrees with known labels
- then an LLM judge with a rubric for the rest
- drop ~5-20%, and read a sample
Soft labels
So far the student learns from text, the teacher's final answer. Classic distillation goes further, with soft labels. Take a support ticket: card charged twice. A hard label says billing, full stop. The teacher's probabilities say seventy percent billing, twenty percent fraud, eight percent technical. That tells the student billing and fraud are close cousins and technical is far away. Training to match the whole distribution passes on more knowledge per example.
ticket: "card charged twice" classes: billing fraud tech other hard: 1.00 0.00 0.00 0.00 soft: 0.70 0.20 0.08 0.02 soft says: billing, but it looks a bit like fraud, never like tech student loss: match the whole distribution (KL divergence)
Temperature
Soft labels come from the teacher's logits, the raw scores before softmax. Say they are four, two, one and zero. A plain softmax gives about eighty three percent, eleven, four and two. The small ones barely register. Divide every logit by a temperature of two first, and you get fifty eight, twenty one, thirteen and eight. Now the second choices show. Most recipes mix this soft loss with the ordinary loss on the true label.
T = 1: exp = 54.6, 7.39, 2.72, 1
p = 0.83, 0.11, 0.04, 0.02
T = 2: logits / 2 = [2, 1, 0.5, 0]
exp = 7.39, 2.72, 1.65, 1
p = 0.58, 0.21, 0.13, 0.08
higher T: the small classes get
enough weight to learn from
usual mix: soft loss + hard loss Logits or text
Which kind can you actually do? Text distillation works with any teacher, even one behind an API, because it is just fine-tuning on the teacher's answers. Logit distillation needs the teacher's probabilities. For a classifier that is easy if you host the teacher. For generated text it means probabilities over every token, which usually needs an open weights teacher you run yourself, and student and teacher sharing one tokenizer so the tokens line up.
- text (sequence-level): works with any teacher, even behind an API. It is just fine-tuning on its answers
- logits (token-level): needs teacher probabilities, so usually an open-weights teacher you host, and a shared tokenizer for text
Narrow or general
Distillation shines on narrow tasks. Classifying tickets, extracting invoice fields, tagging intent. The student can be tiny, sometimes a small encoder model rather than a chat model, and still keep most of the teacher's quality, because the task needs only a thin slice of what the teacher knows. Distilling a general assistant is a different game. It needs vast, varied data, and the small model still falls behind on reasoning and rare facts.
- task-specific: classify tickets, extract invoice fields, tag intent student can be tiny, even a small encoder; keeps most of the teacher's quality
- general-purpose: a small all-round chat model huge data, big quality gap on reasoning and rare knowledge
Measure what you kept
Train the student with LoRA or a full fine-tune, then measure what you kept on the held-out test set. Say the teacher scores ninety two percent and the student eighty nine. The student keeps eighty nine over ninety two, about ninety seven percent of the teacher's quality. Then look per slice, because averages hide damage. Common classes might sit at ninety three while rare ones drop to seventy one. That gap is what to fix next, or route away.
held-out set, gold labels: teacher accuracy 92% student accuracy 89% retained = 89 / 92 = ~97% per slice, student: common classes 93% rare classes 71% <- gap also: agreement with teacher, latency p95, cost per request
Route hard cases back
You do not have to choose one model. Put a router in front. The student answers first. If its confidence is low, say its top class probability is under zero point eight, or its output fails a check, the request goes to the teacher. If ten percent go back, the daily cost is ninety percent of two hundred and seventy plus ten percent of six thousand, about eight hundred and forty dollars. Still seven times cheaper, with quality close to the teacher.
student answers first if confidence < threshold or a check fails: ask the teacher instead cost with 10% sent back: 0.9 x 270 + 0.1 x 6,000 = 243 + 600 = 843 USD / day ~7x cheaper, near-teacher quality
Licence and terms
Check you are allowed to do this. Hosted model terms often restrict using outputs to train a model that competes with the provider, so read them for your exact use. Open weights licences vary too. Some limit how derived models may be used, or require attribution in their names. And the prompts are your users' data, so confirm your privacy policy allows training on them. Record where every example came from, and involve legal early.
- hosted model terms: many restrict using outputs to build a competing model
- open-weights licences vary: some limit use or require attribution of derivatives
- user prompts: does your privacy policy allow training?
- record where each example came from; ask legal early
Keep it fresh
A student is a snapshot. Your traffic drifts, with new products, new phrasings and new edge cases, and the student will not notice. So send about one percent of requests to the teacher in the background and track how often the two agree. When agreement drops, refresh the set from recent logs, retrain, and rerun the evals. Version every student, and swap only when it wins. When a better teacher arrives, distil again.
- shadow ~1% of traffic to the teacher, track agreement
- alert when agreement drops or new inputs appear
- refresh the set from recent logs, retrain, re-run evals
- version every student; swap only if it beats the old one
- new teacher? re-distil
Common mistakes
The common mistakes are mostly about data. Training on invented prompts that look nothing like real traffic. Skipping the filter, so the student learns the teacher's errors. Testing on prompts that leaked into training, which flatters the score. Trusting one average number and missing the rare slices. Skipping the baseline, when a small model with a good prompt might already be enough. And shipping without a fallback for the cases the student cannot handle.
- invented prompts that do not match real traffic
- no filtering: student learns teacher mistakes
- testing on training prompts
- trusting the average score
- no baseline: a small model with a good prompt may do
- no fallback for hard cases
Numbers worth knowing
Some ballparks. A distilled student is often ten to fifty times cheaper per request and two to ten times faster. One task usually needs five thousand to a hundred thousand examples. Filtering keeps eighty to ninety five percent of the teacher's answers. On a narrow task the student keeps around ninety to ninety nine percent of the teacher's quality, with five to twenty percent of traffic sent back.
cost per request ~10-50x lower latency ~2-10x faster examples per task ~5k-100k teacher answers kept ~80-95% quality kept, narrow ~90-99% traffic to fallback ~5-20% shadow sample ~1% of traffic logit temperature ~2-5 refresh monthly-quarterly
Say it like this
How to say it. The frontier model cost six thousand dollars a day at a million requests. We sampled fifty thousand real prompts, had the frontier model answer them, filtered with schema checks and a judge, and fine-tuned a small model. On a held-out set it keeps ninety seven percent of the teacher's quality. Low confidence requests, about ten percent, fall back to the big model. Cost dropped about seven times, and we monitor agreement for drift.
- "The frontier model costs 6k a day at 1M requests. We labelled 50k real prompts with it, filtered with checks and a judge, and fine-tuned a small model. It keeps 97% of the quality; 10% low-confidence traffic falls back. Total cost dropped about 7x."