Skip to content

Guides

LLM distillation

Distillation trains a small model to give the answers a large one would. The large model is the teacher, the small one is the student, and the lesson is your own data. Done well, the student handles one job almost as well as the teacher, at a fraction of the cost per call.

The short answer

  • What it is. Run a large model on real inputs, keep its answers, and fine-tune a small model on them.
  • Why do it. A small model is cheaper and faster on every call, and an open one can run where you choose.
  • When it works. One job your app does many times a day, with an answer that has a shape and can be checked.
  • How to know it worked. Hold some inputs back from training and measure how often the student gives the teacher’s answer on them.

Where the idea comes from

The term comes from a 2015 paper by Geoffrey Hinton, Oriol Vinyals and Jeff Dean, which described training a small model to match a cumbersome one, using the large model’s output probabilities as “soft targets.” Those probabilities carry more information than a single right answer, such as which wrong answers are nearly right, so the small model learns to generalize the way the large one does.

With today’s language models the idea is the same, but the teacher is often a model you can only reach through an API, so the student usually learns from the teacher’s text rather than its probabilities.

The main methods

MethodWhat the student learns fromNotes
Answer distillationThe large model’s final answers on your inputsWorks with any model you can call, including closed APIs. The most common kind for one job.
Rationale distillationThe answers plus the large model’s reasoningCan train a stronger student from fewer examples, at the cost of longer training data.
Logit distillationThe large model’s probabilities over possible next tokensThe original method. Needs access to the teacher’s full output distribution, which closed APIs rarely give.

Adding the teacher’s reasoning can make a large difference. In Google’s 2023 study “Distilling step-by-step,” training with the large model’s rationales let a 770-million-parameter T5 model outperform few-shot prompted 540-billion-parameter PaLM on a benchmark, using 80% of the available data.

How to distill a model for your app

  1. Pick one job. A decision your app makes again and again, such as routing tickets, flagging risky transactions or pulling fields from a document.
  2. Collect real inputs and the teacher’s answers. The calls your app already makes to a frontier model are the best source, because they are the inputs the student will see.
  3. Check a sample. The student copies the teacher, mistakes included. Fix or drop answers that are wrong.
  4. Hold some back. Sous keeps 20% of the calls out of training to test on.
  5. Train a few students. Fine-tune several small open models, usually with LoRA. See LoRA vs QLoRA vs full fine-tuning.
  6. Compare on the held-out calls. Measure how often each student gives the teacher’s answer, and what each costs per call.
  7. Switch carefully. Move traffic to the student when it matches well enough, and send the answers it is unsure of to the teacher or a person.
  8. Keep it current. Retrain as new calls come in, so the student follows changes in your data.

When distillation works, and when it doesn’t

  • Good fit: labels from a fixed list, yes or no with a reason, extracted fields, scores, short rewrites to a policy.
  • Poor fit: open-ended writing, questions that need fresh outside knowledge, and jobs that change from one call to the next.
  • Watch for: a teacher that is often wrong, too few examples of rare answers, and inputs that drift away from what the student trained on.

Check the terms

Using a commercial model’s outputs as training data is governed by your agreement with the provider. OpenAI’s business terms prohibit using output to develop models that compete with OpenAI’s products and services, and have carved out models primarily intended to categorize, classify, or organize data, as long as they are not distributed to third parties. Read the version you accepted, and check every provider whose outputs you train on.

What it looks like in practice

Two distillation runs as the Sous trainer logged them. Cost is per 1,000 calls, and answers are scored on calls each model never saw in training. The students gave the frontier model’s answer on 84% and 92% of them.

JobCheaper than the frontier modelSame answer as the frontier modelLearned from
PII redactor8.5×84%128 calls from an app
Support ticket router6.2×92%300 past tickets

Sous handles the training, testing, serving and retraining: connect the app that already calls GPT or Claude, check a few answers, and it does the rest. Try the example models in the sandbox, or read the docs.

Questions people ask

Is distillation the same as fine-tuning?

Distillation is a way of getting training data: a large model’s answers become the labels. Fine-tuning is how the small model learns from them. Most LLM distillation is fine-tuning a small model on a large model’s outputs.

Can a distilled model beat the model that taught it?

On a narrow job, it can come close and sometimes do better than the teacher prompted with a few examples. In Google’s distilling step-by-step study, a 770-million-parameter model outperformed few-shot prompted 540-billion-parameter PaLM on a benchmark. On broad, open-ended work, it won’t.

How many examples does distillation need?

Fewer than most people expect for one narrow job. Sous starts training at 30 calls, and 50 or more train better. Harder jobs with many possible answers need more.

Am I allowed to distill GPT or Claude?

Read your provider’s terms. OpenAI’s business terms prohibit using output to develop models that compete with OpenAI’s products, and its terms have carved out models primarily meant to categorize, classify, or organize data. Check the version of the agreement you accepted, and the terms of any other provider you use.

Sources

Train your first model

Wrap your client and keep calling your model. Sous trains a small one on your calls and switches you over when it’s ready. Every account starts with $20 of credit, and a training that fails costs nothing.

Four steps, from your app’s calls to a small model

  1. 1Make a model and an API keyin the app
  2. 2Wrap your clientSous(OpenAI(), model=…)
  3. 3Use your app as usualSous keeps each call
  4. 4Let it switchwhen a student is ready