Skip to main content

Distillation

Customer framing: A customer needed a large hosted model's answer quality from a small open-weight model running on their own hardware. Here is the architecture and the tradeoffs.

Official docs:


What it is​

A large teacher model's behaviour is transferred to a smaller student. The student is fine-tuned to do what the teacher does on one task.

WhyGain
CostA smaller model per request
LatencyFewer parameters to read per token
HostingRuns on-prem or on smaller GPUs
Lock-inThe student's weights are yours

A separate axis from LoRA​

QuestionAnswered by
Which weights get trained?Full fine-tuning, LoRA, QLoRA
Where does the training signal come from?Human labels, or a teacher model (distillation)

The two stack. The usual recipe is distillation for the data and LoRA for the training.

Types​

TypeStudent learns fromNeedsUse when
Sequence-level (response)Teacher's final answers, as ordinary SFT pairsOnly API access to the teacherDefault. The only option with a closed teacher.
Logit-levelTeacher's token probabilitiesTeacher logprobs and a compatible tokenizerYou can query the teacher's logprobs, and teacher and student share a model family
RationaleTeacher's answers plus its reasoning stepsA teacher that explains its stepsThe task needs multi-step reasoning, not just a format
Best practice

Check the teacher's terms of use before distilling from a hosted model. Some providers restrict training competing models on their outputs.


Sequence-level distillation with LoRA​

The common recipe. A stronger teacher answers your prompts, you filter the answers, and you run ordinary LoRA or QLoRA SFT on a small student. It is SFT with a model as the data source. The teacher only builds the training set; it is not involved in training.

For Meridian, the teacher is the hosted model that serves cloud tenants. The student is the open-weight model already running on vLLM in the airgapped tenants. The task: given a question and retrieved chunks, write a grounded, cited answer, or say the context doesn't cover it.

Amber marks the two stages that decide the student's quality: filtering and evaluation. The dashed edge loops back for more or better data.

#StageJobFailure if skipped
1Collect promptsInputs that represent the real task: production logs first, synthetic generation to fill gapsA student that is good at the wrong distribution
2Teacher generatesOne answer per prompt, from the same RAG context the student will seeAnswers that rely on context the student never gets
3FilterRule checks, an LLM judge, dedupeBad teacher outputs become bad student habits
4FormatRender each pair with the student's chat templateThe student learns a format it never sees at inference
5LoRA SFTTrain an adapter on the kept pairsn/a
6EvaluateScore against a test set independent of the teacher: human labels or programmatic checksYou measure imitation, not correctness

For Meridian, filtering is mostly code: every citation must point at a chunk that was in the context, and "not covered" answers must have a context that really lacks the answer. The RAG guardrails double as the filter. Deploy the result as an adapter, with multi-LoRA if there are several tasks.

Why LoRA fits distillation​

Property of distillationWhy LoRA suits it
The task is narrowA small update is enough
Iteration is the norm (filter, retrain, re-evaluate)Each run is cheap
Several tasks get distilled over timeOne base model serves every task adapter

β†’ See LoRA


On-policy logit distillation​

Sequence-level distillation trains on the teacher's answers. On-policy distillation trains on the student's own answers: the student generates, a frozen teacher from the same model family scores each token, and the student is pushed toward what the teacher would have said.

Amber is the teacher's only job: scoring tokens the student wrote. The student fixes its own mistakes, not mistakes it would never make.

ModeTeacher returnsTraining signalBehaviour
Sampled reverse KLThe logprob of the one token the student sampledTeacher logprob minus student logprob, per tokenMode-seeking: commits to the teacher's top answer
Top-K forward KLIts top-K tokens and their probabilities as soft labels (K capped at 5 on Fireworks)Cross-entropy against that sparse targetMass-covering: keeps the teacher's spread of plausible tokens

Worked example. At one position the teacher's probabilities are Paris 0.90, Lyon 0.03, "the" 0.02. The student sampled "Paris".

ModeWhat the student learns at this position
Sampled reverse KLOnly about "Paris": raise or lower it by the gap to the teacher's 0.90
Top-K forward KLMove toward all three: Paris 0.90, Lyon 0.03, "the" 0.02
UseWhen
Sequence-levelClosed teacher, or the first version of anything. Simpler and usually enough.
On-policy logitSame-family teacher with logprob access, and sequence-level has plateaued

Design choices​

ChoiceOptionsDecide by
Student sizeSmallest to largest that fits the hardwareThe smallest model that clears the quality bar on the held-out set
Data volume vs qualityMore pairs vs stricter filteringFiltering usually matters more. Add volume only after the filter is strict.
Sequence vs logitAnswers only vs token probabilitiesTeacher access: a closed API means sequence-level
Merge vs adapterMerged model vs served adapterOne latency-critical task: merge. Several tasks or tenants: adapter.
Best practice

Set the quality bar in numbers, against the independent test set, before the first training run. Otherwise every run looks promising.