Distilling a frontier model intoone you can run

At some point the API bill for one narrow task stops making sense. Here is how we turn a frontier model into a small, task-specific model you own, the evaluation harness that makes it trustworthy, and the arithmetic that tells you whether to bother.

Published
Updated
Read
10 min
Topic
AI
A frontier model being distilled into a small model that runs on your own hardware
A frontier model being distilled into a small model that runs on your own hardware

Almost every AI feature we've seen start life the same way. Someone writes a prompt, pastes in an API key, and a frontier model does the job beautifully. That's the right first move. I'd do it again tomorrow. It is just not where you should still be in month six.

By then the bill has a shape. The feature does one narrow thing, maybe classifying support tickets or pulling line items out of supplier invoices, and it does it tens of thousands of times a day. You are paying frontier prices for a task a far smaller model could handle. Every call ships customer data to a third party. And your p95 latency is whatever the provider's queue feels like that afternoon.

Distillation is the way out. You use the big model as a teacher to produce a smaller, task-specific student that you own and run yourself. We've done this enough times now to have opinions about it, so here they are, along with the arithmetic that decides whether you should do it at all.

When it is actually worth doing

I want to be honest about this up front, because distillation is a satisfying engineering project and satisfying projects get started for the wrong reasons. You want at least two of these three:

  • The task is narrow and stable. Classification, extraction, routing, structured summarisation. If the feature is "chat about anything", keep the frontier model and move on.
  • Volume is high or latency is tight. Somewhere above a million calls a month, or below a few hundred milliseconds per call, a small hosted model wins on both counts.
  • The data cannot leave. Health records, financial transactions, anything under the DPDP Act or HIPAA with a residency clause. A model on your own infrastructure deletes an entire category of security-questionnaire answers.

If none of those hold, you have an engineering project with no customer. Don't start it.

The pipeline, as we actually run it

Production promptslogged · PII strippedTeacher labelsfrontier model · schemaFilterkeep only valid outputsHeld-out set≥1k human-checkedStudent1B–8B · LoRA / full FTQuantise4-bit / 8-bit · re-evaluateServevLLM · batching · warm poolscorecard: teacher vs student vs quantisedlow confidence → fall back to teacher
Figure The pipeline. Real production prompts go in, a quantised student comes out, and the teacher stays on call for the hard cases.

Collect the real inputs first. Log every prompt the frontier model has handled, with its output and, where you have one, the human correction. Thirty thousand real examples beat three hundred thousand synthetic ones every time, because real inputs carry the mess your users actually produce: the abbreviations, the half-filled forms, the invoice photographed at an angle. Strip personal data at this stage, not later. Later never happens.

Let the teacher label what you don't trust yet. For inputs without a verified answer, run the frontier model with a strict output schema and keep only outputs that validate. Reject the rest. A student trained on malformed JSON learns, faithfully, to produce malformed JSON.

Pick the student. One to eight billion parameters is the usual range. Smaller than that and quality drops off a cliff for anything with nuance; larger and you lose the latency and cost advantage that justified the project. We start at the small end and only move up when the evaluation says so, not when someone feels nervous.

Fine-tune, then quantise. LoRA or a full fine-tune depending on budget, then 4-bit or 8-bit quantisation for serving. Quantisation is where most of the cost saving lives and where most quality regressions hide, so it gets its own evaluation run. We've shipped a model that looked perfect in fp16 and lost four points on exact-match after quantising. Nobody would have noticed without the second run.

Serve it properly. A batching inference server (vLLM or equivalent), a request queue, a warm pool sized to your p95, and a circuit breaker that falls back to the frontier model when the student's confidence is low. The fallback is not an admission of failure. It's how you ship with a two percent error budget instead of waiting forever for zero.

The evaluation harness is the actual product

Nobody trusts a model because the training loss went down. They trust it because a scorecard says it matches or beats the teacher on the number the business cares about. So we build the harness before the first training run, and it has four parts:

  • A held-out set of at least a thousand real examples with human-verified answers, never used in training, kept in a separate bucket with separate permissions.
  • The task metric, not a proxy. Exact-match on extracted fields, F1 on classes, a rubric score on summaries.
  • A drift check that runs weekly on fresh production traffic, so you find out the inputs have changed before your customers do.
  • A side-by-side report: teacher, student, student-quantised. Three columns, same examples.

Every model that ships has a row in that report. Every model we've pulled has one too, and that row is usually what told us to pull it.

Exact-match on held-out setIllustrative
Teacher (frontier API)94%

p95 1.8 s

Student, fp1693%

p95 210 ms

Student, 4-bit92%

p95 180 ms

Exact-match on held-out set
ItemValue
Teacher (frontier API)94%
Student, fp1693%
Student, 4-bit92%
Figure An illustrative scorecard. The quantised student stays within a point of the teacher on the task metric while cutting latency by an order of magnitude.

The arithmetic

Here's a worked example from the shape of a recent engagement, rounded so nobody can identify it:

Frontier APIDistilled, self-hosted
Calls per month3M3M
Cost per 1k calls₹60₹4 (GPU amortised)
Monthly cost₹1.8L₹12k + ₹40k GPU
p95 latency1.8s180ms
Data leaves your accountYesNo
Monthly cost, ₹ thousandsIllustrative
Frontier API
180k
Distilled: inference
12k
Distilled: GPU
40k
Monthly cost, ₹ thousands
ItemValue
Frontier API180k
Distilled: inference12k
Distilled: GPU40k
Figure Monthly cost at three million calls, illustrative. The GPU line is the one people forget to include.

The project itself cost about two months of one engineer and a few hundred GPU-hours. Payback was inside a quarter. At a tenth of the volume it would not have been worth doing, which is really the whole point of the table: run the numbers before you run the training job.

What goes wrong

A short list, all of which we have either done or watched someone do.

  • Training on the teacher's mistakes. The student learns every error in the labels, faithfully. Spot-check the teacher before you trust it to teach.
  • Evaluating on training data. It happens more than anyone admits, usually because the two sets live in the same folder. Separate buckets, separate permissions.
  • Forgetting the fallback. A student with no escape hatch turns a two percent error rate into two percent angry customers.
  • No owner after launch. Models rot. Someone has to run the drift check, read it, and have the authority to retrain. If that person isn't named, it's nobody.

If you're paying frontier prices for a narrow task at volume, you already have the one thing a distillation project needs most: the data. The rest is engineering, and it's well understood. If you'd like a second opinion on whether your task will distil, that's a conversation we're happy to have.

AImodel distillationfine-tuningsmall language modelsLLM costself-hosted inferenceevaluation harnessDPDP ActvLLM

Start a project

Working onsomething similar?

Tell us what you are building. We reply within two working days with a point of view, not a sales deck.