Concepts / Teacher-Student Model Training

Teacher-Student Model Training

Knowledge distillation, also called model distillation, trains a small student model to mimic a larger teacher model.

  • Programming

When a Capable Model Costs Too Much

Imagine you have trained a very capable language model. It answers questions well, but it is large, and running it for every user request takes substantial computing resources. The model works, yet the cost of putting it into a product may be too high, or its responses may arrive too slowly. Knowledge distillation is one response to this kind of problem. Instead of accepting the size of the capable model as fixed, you train a second, smaller model to behave like it.

What do you think happens?

If you train a much smaller model to imitate a large capable model, what do you expect to happen to its performance?

  • It becomes identical to the large model

  • It becomes comparable to the large model but not identical

  • It becomes better than the large model in every way

Reveal answer
Answer:

It becomes comparable to the large model but not identical.

Distillation trades some capability for efficiency. The source says the student is expected to be comparable to, not identical to, the teacher, and that it is smaller and faster. It does not promise a free improvement in every dimension.

Tracing Knowledge from Teacher to Student

The name is a useful clue. In distillation, the knowledge held by the large model is passed along to the small one, much as a liquid is separated from a mixture and collected in a new container. The large model, called the teacher, does the work of producing behavior that the student should reproduce. The small model, called the student, is trained so that its behavior moves toward the teacher's behavior. The student is the one that ends up deployed, because it is the smaller and faster of the two.

InputsTeacher model (large)does the work of producingbehaviorTeacher behavior oninputsStudent model (small)trained to move towardteacherDeployed modelthe studentinputproducesguides trainingdeployed
What moves from the teacher to the student during training, and in which direction does it flow?

Read the flow in the diagram as a sequence of hand-offs. Inputs go to the teacher, the teacher's behavior on those inputs guides the student, and the student's training is adjusted so that it imitates the teacher more closely. The teacher is not being modified in this process. The knowledge moves in one direction, from the large model into the small one.

Defining the Teacher-Student Arrangement

Definition

Knowledge distillation, also called model distillation, trains a small student model to mimic a larger teacher model.

The teacher-student arrangement is a paradigm, meaning a pattern for how two models relate during training. The larger model guides the training of the smaller one. The two models do not play symmetric roles. The teacher exists to supply the behavior to be imitated, and the student exists to absorb that behavior in a compact form. The student is defined by the goal of mimicry, not only by its small size.

Two Ways to Build a Student

The student does not have to start from nothing. The source identifies two ways it can be built. In the first, the student is trained from scratch, as DistilBERT was. In the second, the student is finetuned from a pre-trained model, as Alpaca was. Both are still distillation, because in both cases the student's training is shaped by a larger model's behavior. What changes is where the student's training begins.

DistilBERTdistilled from BERTStudent trainingbeginsno pre-trained studentstarting pointAlpacastudent is Llama7BStudent trainingbeginsstarts from pre-trainedLlama7Bthenthen
Where does the student's starting point come from in each case, and how does that change what the reported results mean?

The two cases differ in where they begin, and that difference affects how you should read their results. The sections below take each case in turn.

Reading the DistilBERT Result Correctly

Worked example

Reading the reported DistilBERT numbers

The source reports that DistilBERT, relative to BERT, is 40% smaller, retains 97% of BERT's language comprehension capabilities, and runs 60% faster. What does each figure actually tell you?

  1. 1
    Identify the baseline

    Every figure is stated relative to BERT, the teacher. None of the numbers is an absolute score on a fixed benchmark.

  2. 2
    Read the size figure

    A 40% reduction means the student is smaller than the teacher by that proportion. It describes the model's size, not its quality.

  3. 3
    Read the comprehension figure

    Retaining 97% of language comprehension means the student keeps most, but not all, of the teacher's capability. The student is comparable to the teacher, not identical to it.

  4. 4
    Read the speed figure

    Running 60% faster refers to speed relative to BERT. It is the efficiency gain that makes the student attractive for deployment.

  5. 5
    Combine the readings

    Together the figures describe a deliberate trade: some capability is given up in exchange for a smaller, faster model. The source presents this as a balance, not a free improvement.

Result

The DistilBERT results say the student keeps most of BERT's comprehension while being smaller and faster. They do not say the student matches BERT on every task.

Comparing the Teacher and Student Trade-offs

The table below collects the reported figures for both cases side by side. Use it to check which numbers are relative comparisons and which describe a starting point or setup.

CaseTeacherStudentReported result
DistilBERTBERTDistilled student, trained from scratch40% smaller, 97% of language comprehension retained, 60% faster
Alpacatext-davinci-003 (175 billion parameters)Llama7B (7 billion parameters), finetunedBehaves similarly to the teacher; 4% the size of the teacher

Reported figures for the two cases in the source

Mistakes Beginners Make with Distillation

  • Common mistake

    Treating the 97% figure as an accuracy score

    What it looks like

    Reading DistilBERT's 97% as meaning it gets 97% of answers right.

    Why it fails

    The source says DistilBERT retains 97% of BERT's language comprehension capabilities. It is a retention figure relative to the teacher, not a benchmark accuracy.

    Do this instead

    Read it as the share of the teacher's comprehension that the student keeps.

  • Common mistake

    Assuming the student is identical to the teacher

    What it looks like

    Expecting a distilled student to behave exactly like its teacher on every input.

    Why it fails

    The source says the student is expected to be comparable to, not identical to, the teacher.

    Do this instead

    Expect close but not identical behavior, and evaluate the student on the tasks you care about.

  • Common mistake

    Believing the teacher is changed during distillation

    What it looks like

    Thinking that training the student also updates BERT or text-davinci-003.

    Why it fails

    The source states the teacher is not being modified in this process. Knowledge moves one way, from the large model into the small one.

    Do this instead

    Keep the teacher fixed in your mental model and focus on what the student learns from it.

  • Common mistake

    Thinking distillation requires training from scratch

    What it looks like

    Assuming Alpaca is not distillation because it did not start from nothing.

    Why it fails

    The source says both approaches are still distillation. Only the starting point of the student's training differs.

    Do this instead

    Ask where the student's training begins, not whether it is distillation.

  • Common mistake

    Confusing the teacher with the student because the teacher is the one that is more capable

Checking Your Reading of a Distillation Claim

MEDIUM

A team reports that their small student model, finetuned from a pre-trained model using outputs of a much larger teacher, is 4% the size of the teacher and behaves similarly on their test prompts. Without assuming any extra facts, explain (1) where the student's training began, (2) whether this is still distillation, and (3) what the report does and does not show about identical behavior.

Hints
  • Ask whether the student started from a pre-trained model or from scratch, and connect that to the Alpaca case.
  • The source says both starting points are still distillation, because the student's training is shaped by the larger model's behavior.
  • The source says the student is comparable to, not identical to, the teacher.

Key Takeaways

  • Knowledge distillation, also called model distillation, trains a small student model to mimic a larger teacher model, and the student is the smaller, faster model usually deployed.
  • Distillation exists because a capable large model can be too costly or too slow to run for every request, and the student offers a cheaper alternative.
  • A student can be trained from scratch, as DistilBERT was, or finetuned from a pre-trained model, as Alpaca was. Both are still distillation; only the starting point differs.
  • Reported results are relative comparisons. DistilBERT keeps 97% of BERT's language comprehension while being 40% smaller and 60% faster, and Alpaca behaves similarly to text-davinci-003 at 4% of its size.
  • Distillation trades some capability for efficiency, so the student is comparable to the teacher, not identical to it.

Related concepts

More concepts starting with T