ealeng
Menu

Episode 25 of 25 · Fine-tuning

Distillation, DPO and RFT

Three ways to train a small model when nobody has written the right answers: copy a big model's answers (distillation), learn from which of two answers is better (DPO), or learn from a checker's ticks and crosses (RFT). What each one got on the same shop's emails, and what each one quietly taught the model.

Lab 11 · Fine-Tuning13 min read
Video transcript8:07

0:00Cold open

0:01

Our shop sorts its support emails with a model.

0:04

For each email, it fills in four things: what the customer wants, the order, the product, and how urgent it is.

0:12

This customer already owns her tent. She asks if it copes with hard frost.

0:17

Our rule: low urgency is for people still deciding to buy, not owners. She owns it, so: normal.

0:24

A big model, the one we pay for, says: low. A small slip.

0:29

Then I trained a small model by copying the big one’s answers. It says low too.

0:35

Another small model practised on the true answers. It says normal.

0:41

When a model learns by copying another, what else does it copy?

0:46Intro

0:47

Hands-on AI engineering: fine-tuning, part three.

0:51

Today: how to train a small model when nobody has written the right answers.

0:57No answer key

0:58

I’m Lea. In parts one and two, training was like practice exams with an answer key.

1:04

The model answers an email, checks the key, and gets nudged toward the right answer.

1:09

Those right answers are often called labels.

1:13

I had two thousand, because I picked the answers first, then had a model write an email for each one. A real shop has the emails, but nobody has written the answers.

1:24

So, picture three teachers who can’t hand over an answer key.

1:28

Teacher one writes her own answer key, slips included.

1:32

Teacher two only says which of two answers is better.

1:36

Teacher three only marks each answer right or wrong: a tick or a cross.

1:4201 · Teacher one

1:43

Teacher one is the big model. It answered all two thousand practice emails, and its answers became the answer key.

1:51

Ninety-seven of every hundred were right. So the key has slips.

1:56

The small model, the student, practised only on that key. This is called distillation.

2:02

Then a test, on emails none of them had practised on.

2:05

The student that practised on the true answers got ninety-nine percent. The big model itself got ninety-six.

2:13

What did the student that copied the big model get?

2:18

Ninety-six. The same as its teacher, within one email.

2:2402 · The slips

2:25

But did it copy only the teacher’s score, or its actual mistakes?

2:30

On the test, the big model got twelve emails wrong.

2:34

On six of those twelve, the copying student gave the exact same wrong answer.

2:40

The student that practised on the true answers: not once.

2:44

Why? Most of them are the same case as the tent: a customer who already owns the item.

2:50

The practice emails had forty-four like that. On twenty-seven, the answer key had the wrong urgency.

2:57

So the student practised that wrong answer, on twenty-seven emails. A slip the teacher repeats, the student learns.

3:05

Still, it’s a good deal. As good as its teacher, nothing to pay per email, and faster.

3:1203 · Teacher two

3:14

Teacher two only says which of two answers is better. That suits a job with no single right answer.

3:21

Like writing a reply to the customer. Many different replies could be good, as long as they follow our house style, checked by rules.

3:29

To score a reply, another model acts as a judge. It asks: does it answer the email, and invent nothing? If so, the reply counts as helpful.

3:39

Before any practice, forty-one of a hundred replies were helpful.

3:44

Then teacher one again: the big model wrote six hundred good replies in our house style, and the small model practised on them. Seventy-eight helpful.

3:54

Now teacher two. For each email, two replies: the big model’s, marked better, and the small model’s, marked worse. The worse one always broke a style rule.

4:04

Training pushes the model toward the better one of each pair. It’s called D P O.

4:09

Did the pairs keep it helpful?

4:1404 · It made things up

4:15

Here’s one email. The customer got the wrong item.

4:19

After the good replies alone, it asks for a photo of what arrived.

4:24

After the pairs, it says: the replacement scan shows the wrong size and color code.

4:30

There is no scan. It made it up.

4:33

Across a hundred replies, helpful ones fell from seventy-eight to thirty-two. Worse than before any practice.

4:4205 · Why it failed

4:43

My pairs were the likely problem. Here’s one like them.

4:47

The better reply came from the big model. The worse one came from the small model, before any practice.

4:54

They’re easy to tell apart at a glance. Within ten training steps, it picked the better reply in every pair it saw.

5:01

My guess: it learned “don’t sound like my old self”, and nothing about being helpful.

5:07

The usual advice is pairs that are close: two of the model’s own replies, one better than the other. I haven’t tested that here.

5:1606 · Teacher three

5:18

Teacher three never shows a right answer. She only marks each answer with a tick or a cross.

5:24

Back to sorting emails. Here’s Ravi. He wants to return a filter. Urgency: normal.

5:30

Before any practice, the small model answers his email eight times. Each try comes out a little different.

5:38

A checker marks each try. Two get a tick. Six get a cross: they called it high, or low.

5:44

The model practises on its first ticked try, for each email that got at least one tick. In round one, that’s a hundred and eighty of the five hundred.

5:53

One honest note: my checker compares with answers I already have. It stands in for a real check.

6:00

That’s one round. Then it tries again. This is called reinforcement fine-tuning.

6:0707 · Two rounds

6:08

First, the honest score: ask once, and see if it’s right. Before practice: fourteen times in a hundred.

6:15

After two rounds: eighty-three.

6:19

Then the test, on new emails. Can it match a student that practised on the true answers for just these five hundred?

6:27

Close. Eighty-seven percent, against ninety-one.

6:32

So where do the missing four points come from?

6:3508 · Never a tick

6:37

One more customer. She shouts URGENT, but she’s only asking where her tent is. Our rule says that’s normal.

6:44

Eight tries. All eight say high, and miss what she wants too. Eight crosses.

6:50

With no tick, there’s nothing to practise on.

6:53

The practice emails had thirty-one like hers. Eight tries before each round: sixteen in all. Never once was the urgency right.

7:03

On the test, it got one of fifteen like that. The student with the true answers got all fifteen.

7:09

On every other test email, the two got exactly the same number right. That’s the whole gap.

7:16

Plenty of emails it got wrong at first, it learned. But a kind of email it never gets right, it can’t learn.

7:2409 · What I do now

7:25

So here’s what I do now. Before copying a big model, I check its answers, field by field. The student will copy its slips.

7:34

For which-is-better training, I’d use pairs that differ in what I care about, not pairs from two different models.

7:41

With only ticks and crosses, I first look for a kind of email it never gets right. That kind, it can’t learn.

7:48

That’s the series. Practice can teach a small model a lot. And whatever it practises on, it inherits.Lea: Check what it copies.

7:56Summary

7:57

A student copies its teacher, slips included.

8:01

Ticks and crosses can’t teach a kind of answer it never gets right.Lea: Thanks!

Key takeaways

  • ✓Distillation: a big model (the teacher, gpt-5.4-mini) labelled 2,000 practice emails, 97% fully right, and a 0.6B student trained only on those labels. On 300 test emails the student got 96%, the same as its teacher, against 99% for a student trained on the true answers (p = 0.012). It runs at $0 per email and 0.21 s, against $1.46 per 1,000 and 0.67 s for the teacher.
  • ✓The student copied the teacher's slips, not just its score. On the 12 test emails the teacher got wrong, the copying student gave the exact same wrong answer 6 times; the true-answers student never did. 5 of the 6 were customers who already own the item, and in practice the teacher's key had the wrong urgency on 27 of the 44 emails like that.
  • ✓DPO trains on pairs: a better and a worse answer to the same email. After practice on 600 good replies, 78 of 100 replies were helpful. DPO on 600 pairs (the big model's reply better, the small model's old reply worse) kept the house style (98%) but cut helpful replies to 32, below the 41 before any practice. It started inventing facts, like a "replacement scan" that doesn't exist.
  • ✓The pairs were too easy: better and worse came from two different models. From step 3 of 150 the model picked the better reply in every batch, so it learned "don't sound like my old self", not "be helpful". The usual advice, not tested here, is pairs of the model's own replies that differ in what you care about.
  • ✓RFT with only a checker: 8 tries per email, practise on a passing try, repeat. Right when asked once went 14% → 63% → 83% on the 500 practice emails in two rounds, and 87% on the test against 91% for true answers on the same 500 emails (p = 0.049). The whole gap is one kind of email it never got right: fake URGENT, 0 right in 16 tries on all 31, and 1 of 15 on the test against 15 of 15.

Earlier in this section, training was like practice exams with an answer key. The model answers an email, checks the key, and gets nudged toward the right answer. Those right answers are called labels. The lab had 2,000 of them, because it picked the answers first and then had a model write an email for each one.

A real shop has the emails, but nobody has written the answers. This chapter is about training a small model anyway. Picture three teachers who can't hand over an answer key:

  • Teacher one writes her own answer key, slips included. That's distillation.
  • Teacher two only says which of two answers is better. That's preference tuning, here DPO.
  • Teacher three only marks each answer right or wrong: a tick or a cross. That's reinforcement fine-tuning (RFT).

The source is Lab 11 (Fine-Tuning), and this chapter covers three of its scripts: 05_distillation.py, 06_dpo.py and 07_rft.py. The student is always Qwen3-0.6B with a LoRA adapter, trained on a laptop (see Fine-tune a small model with LoRA). The task is the same one as the rest of the section: the made-up outdoor shop Lantern Outfitters sorts each support email into four fields (what the customer wants, the order, the product, and how urgent it is). The emails are made up, with known labels, so every result can be checked against the truth.

Teacher one: copy a big model

Distillation means a big model, the teacher, answers the practice emails, and its answers become the answer key. A small model, the student, trains only on that key. It never sees a true label.

Here the teacher is gpt-5.4-mini with the rules and 10 examples in its prompt, the best prompted setup from earlier in the lab. It labelled all 2,000 practice emails for $2.91. 1,936 of 2,000 (97%) were fully right. Of its 70 wrong fields, 55 were urgency and 11 the product.

Then a test, on 300 emails none of them had practised on:

Model All four fields right Cost per 1,000 emails Median time per email
Teacher (gpt-5.4-mini) 96% (288 of 300) $1.46 0.67 s
Student trained on the true answers 99% (296) $0 -
Student trained on the teacher's answers 96% (287) $0 0.21 s

The copying student scored like its teacher, and below the student trained on true answers (p = 0.012). The true-answers student is the one from the LoRA chapter.

Still, that's a good deal. It matches its teacher with no per-email bill, about a third of the time, and a prompt of 115 tokens instead of 1,769 (the rules are now in its weights). The local time is 30 emails, one at a time, on the laptop; the API time is from the same laptop.

It copied the slips

Did it copy only the teacher's score, or its actual mistakes? On the test, the teacher got 12 emails wrong. On 6 of those 12, the copying student gave the exact same wrong answer. The student trained on the true answers: not once.

Here's the one from the video. A customer already owns her family tent and asks if it copes with hard frost. The shop's rule: low urgency is for someone still deciding to buy (or who says there's no rush), not an owner. So the answer is normal. The teacher said low. The copying student said low. The true-answers student said normal.

Switch between the two students and click any slip to read the email:

Try it · The teacher's slipsLab 11 · script 05 · 12 test emails the big model got wrong

All 300 test emails, all four fields right

Big model (teacher)96% (288/300)
Copying student96% (287/300)

Bars start at 90%.

On the teacher's 12 slips, the student gave the exact same wrong answer 6 of 12 times.

same wrong answer as the teacher right wrong in its own way

K0037 Already owns the item, asks about it · German

“Hallo Lantern Outfitters, ich habe die family tent schon seit einiger Zeit und würde gern wissen, ob sie auch bei strengen Frosten in der Gefrierwetter-Umgebung gut funktioniert, danke schön für die Info! Viele Grüße, Chloe”

Rule for urgency here: normal: not a question before buying

intentorder_idskuurgency
true answerproduct_questionnoneTENT-4Pnormal
teacherproduct_questionnoneTENT-4Plow
copying studentproduct_questionnoneTENT-4Plow

The student repeated the teacher's answer, slip included.

Why the owners' emails: in the 2,000 practice emails, 44 came from customers who already own the item, and the teacher's answer key had the wrong urgency on 27 of them.

Why these emails? Five of the six copied slips are the same case as the tent: a customer who already owns the item. The practice emails had 44 like that, and on 27 of them the teacher's key had the wrong urgency. So the student practised that wrong answer on 27 emails. A slip the teacher repeats, the student learns as a rule. Random noise averages out over 2,000 examples; a habit doesn't.

The lab also tried a filter: keep only the teacher's labels whose order number checks out in the email. It removed 1 label of 2,000 (97% on the test, not significantly different). The teacher's order numbers were already right; its slips were in urgency, which that check can't see. A filter helps only on the field where the teacher fails, so check the teacher field by field first.

Teacher two: which reply is better

Some jobs have no single right answer. Writing a reply to a customer is one: many replies could be good. For those, a preference pair is easier to give than an answer key: one email, a better (chosen) reply, and a worse (rejected) one. DPO (Direct Preference Optimization) trains on the pairs directly. It raises the chance of the better reply and lowers the worse one, measured against the model it started from. A setting called β (beta) is the leash: how far the model may move from where it started.

The new job: replies in the shop's house style, seven rules checked by code (greet by first name, at most 60 words, no stock apologies, no exclamation marks, mention the order number, promise no money, sign off as "Lantern Outfitters Support"). Style isn't everything, so a second model, a gpt-5.4-mini judge, reads each reply and asks: does it answer the email, and invent nothing? If so, it counts as helpful.

The pairs: for each of 600 practice emails, the better reply came from gpt-5.4-mini with the style guide (kept only if it passed all seven rules), and the worse reply was the small model's own default reply, which always broke a rule. On 100 English test emails:

Setup All 7 style rules Judge: helpful Style and helpful
Qwen3-0.6B, before any practice 0% 41 0%
Practised on the 600 better replies (SFT) 99% 78 77%
Then DPO on the 600 pairs 98% 32 31%
DPO on the pairs, straight from the base model 0% 0 0%
gpt-5.4-mini with the style guide 100% 97 97%

SFT (supervised fine-tuning) is the plain practice from the earlier chapters: show the model good examples and train it to write them. On its own, it got the style to 99% with 78 helpful replies. Adding DPO on top kept the style and cut helpful replies from 78 to 32, worse than before any practice (p < 0.001 for "style and helpful"). DPO straight from the base model broke it entirely: replies ran to 140 words on average, and 85 of 100 repeated one sentence three or more times.

It made things up

One test email: Mei ordered a Ridgeline 45L backpack and got a completely different product.

  • After the good replies alone: "Please reply with a photo of the item you received and the packaging, plus your shipping address."
  • After the pairs: "Order A-7040 for the Ridgeline 45L Backpack was checked. The replacement scan shows the wrong size and color code."

There is no scan. Nothing in the email mentions one. The lab read the 51 emails where the SFT reply was helpful and the DPO reply wasn't, and found the same pattern: confident, well-formatted replies about statuses and checks that don't exist. The style checker passed them. Only the judge caught it.

Why the pairs failed

The likely problem was the pairs themselves. The better reply came from a big model; the worse one from the small model before any practice. They're easy to tell apart at a glance. From step 3 of 150, the model picked the better reply in every batch it saw, and by step 10 the loss was about 0.0001. Once the pairs are told apart, there's nothing left to learn from them.

The lab's guess: the model learned "don't sound like my old self", and nothing about being helpful. Nothing in either reply of a pair showed what makes a reply helpful, because the worse reply was worse at style, not at substance.

The usual advice is pairs that are close: two of the model's own replies, one better than the other in exactly what you care about. For example, sample four replies from the SFT model, have the judge pick a helpful and an unhelpful one, and train DPO on those. The lab didn't test that; it's the lab's suggested next exercise.

Teacher three: only ticks and crosses

Reinforcement fine-tuning (RFT) needs no right answers at all, only a grader (or checker): code that marks an answer pass or fail. The simplest version is rejection sampling: let the model try each email several times, keep a try that passed, train on it, and repeat with the improved model. The model only ever learns from its own answers.

Back to sorting emails, with 500 practice emails. Each round, the model answers each one 8 times (at temperature 1.0, so each try comes out a little different) with the rules in its prompt. The grader gives a tick only if all four fields are right. The model practises on its first ticked try, for each email that got at least one tick: 180 of the 500 in round one, 379 in round two.

One honest note: here the grader compares with answers the lab already has. It stands in for a real check, like tests that a piece of code must pass.

Two numbers describe how much there is to harvest:

  • pass@1: the share of emails where the first try is right. The honest "ask once" score.
  • pass@8: the share of emails with at least one tick in 8 tries. Rejection sampling can only practise on these, so this is roughly its ceiling for the next round.

Pick an email to see its eight tries, then follow the 500 emails through two rounds and onto the test:

Try it · Ticks and crossesLab 11 · script 07 · Qwen3-0.6B, 8 tries per email

1 · One email, eight tries before any practice

“Hello Lantern Outfitters, I’m writing about order number A-1290. The filter doesn’t fit me as expected, and I’d like to return it and receive a refund. Please let me know the next steps for shipping it back, and you can reach me at 555-0146. Thank you for your help. Ravi”

true answer: return_refund · A-1290 · FILT-1 · urgency normal

try 1✓normal
try 2✗high
try 3✗low
try 4✗low
try 5✗low
try 6✗high
try 7✓normal
try 8✗low

2 ticks. The model practises on its first ticked try (try 1, outlined).

2 · The 500 practice emails, before and after each round

Before practiceasked once, right 14% · never right 320 · trains on 180
After round 1asked once, right 63% · never right 123 · trains on 379
After round 2asked once, right 83% · never right 41
right when asked once a tick in some of 8 tries no tick in 8 tries

121 emails never got a tick in either round, including all 31 fake-URGENT ones.

3 · The test: new emails, all four fields right

Before practice57/300
After round 1189/300
After round 2260/300
True answers, same 500274/300

Two rounds with only a checker: 87%, against 91% for a student that practised on the true answers of the same 500 emails (p = 0.049).

Asked once and right went 14% → 63% → 83% over two rounds, and pass@8 went 36% → 75% → 92%. Each round makes the model's occasional successes its usual answer, and that unlocks new emails for the next round. On the 300 test emails, round two got 87%, against 91% for a student trained on the true answers of the same 500 emails (p = 0.049). Before any practice it got 19%.

Never a tick, never learned

Where do the missing four points come from? One customer shouts URGENT but only asks where her tent is. The rule: capital letters or the word "urgent" alone don't make it high, so it's normal. All eight tries said high, and missed what she wants too (missing package, or cancel). Eight crosses. With no tick, there's nothing to practise on.

The practice emails had 31 like hers. In 16 tries each (8 before each round), the urgency was never once right. All 31 were among the 121 emails that never got a tick in either round.

On the test, round two got 1 of 15 of those fake-URGENT emails. The true-answers student got 15 of 15. On the other 285 test emails, both got exactly 259 right. That's the whole gap.

RFT can turn what the model sometimes does into what it usually does. It can't teach what it never does. Count the kinds of input with pass@k = 0 before you start: that's what it won't learn.

Caveats

  • Made-up emails, one small model. The emails were written by a model from labels picked first, and the student is always Qwen3-0.6B with rank-8 LoRA. Your teacher, data and model will give other numbers.
  • The label audit. Reading 40 test emails by hand, 3 urgency labels were arguable, two of them owners wanting another item. So some "copied slips" are on debatable labels; the point is that the student copied the teacher's choice either way.
  • Two different "true answers" students. The 99% distillation comparison is trained on all 2,000 true labels with a short prompt; the 91% RFT comparison on the same 500 emails as RFT, with the rules prompt.
  • DPO was one pair design. The result shows what too-easy pairs did here, not that DPO fails. Better pairs were not tested. The judge is a model too, and lenient: some SFT replies that passed it also invented details.
  • The RFT grader knows the answers. Here it's an exact match against known labels, so a passing try is the true label; RFT differs from SFT only in which emails it practises on. A real grader (tests, a format check) is usually weaker.
  • Small test sets. 300 test emails for 05 and 07, 100 for 06. The 87% vs 91% gap is just significant (p = 0.049).
  • Where the lab's README and the recorded data differ: the README gives the student's median time as 0.22 s; the recorded results give 0.21 s, which this chapter uses. The README says DPO's loss hit zero "within 25 steps"; the recorded step history shows every batch told apart from step 3 and a loss near zero by step 10.

The checklist

  1. Before copying a big model, check its answers field by field on a sample with known answers. The student will copy its slips, especially the repeated ones.
  2. Write label filters for the field where the teacher fails, not the field that's easy to check.
  3. For which-is-better training, use pairs that differ in what you care about, ideally two of the model's own answers, not answers from two different models.
  4. Watch the pair accuracy during DPO. If it hits 100% within a few steps, the pairs are too easy.
  5. Check substance separately from style. A checker for the thing you trained on will pass the model; a judge for everything else may not.
  6. Before RFT, measure pass@1 and pass@k, and look for a kind of input that never gets a tick. That kind, it can't learn; seed it with a few true examples or give partial credit.

Practice: what did the student copy?

Count how many of the teacher's slips a student copied, using the 12 real test emails the teacher got wrong; write the DPO loss for one pair and see why too-easy pairs drive it to zero; and compute pass@1, pass@k and the tries rejection sampling would keep.

Try it · Practice in PythonRuns in your browser · ⌘/Ctrl + Enter to run
labels_practice.py55 lines

Quiz

Try it · Check your understanding0 of 6 answered
  1. 1.What is distillation?

  2. 2.The teacher's labels were 97% right. Why didn't 2,000 of them average its mistakes away?

  3. 3.On the 12 test emails the teacher got wrong, how often did the copying student give the exact same wrong answer?

  4. 4.After DPO, the style checker passed 98% of replies. Why wasn't that good news?

  5. 5.Why were the lab's DPO pairs a poor design?

  6. 6.In RFT by rejection sampling, what can the model never learn?

Check your understanding

Try each question before opening its answer.

What are a teacher and a student in distillation?

The teacher is a big model that answers unlabelled inputs. Its answers become the answer key. The student is a small model trained only on that key; it never sees a true label. Here the teacher was gpt-5.4-mini and the student Qwen3-0.6B.

The copying student matched its teacher at 96%. What did it cost to get there, and what did it save?

It cost $2.91 for the teacher's 2,000 labels and about 7 minutes of training, and it scored below a student trained on the true answers (99%, p = 0.012). It saves the per-email bill ($0 vs $1.46 per 1,000) and time (0.21 s vs 0.67 s), with a 115-token prompt instead of 1,769.

How do you know the student copied the teacher's mistakes, not just its score?

Look at the emails the teacher got wrong. On those 12 test emails, the copying student gave the exact same wrong answer 6 times; the true-answers student never did. Most were owners' emails, where the teacher's key had the wrong urgency on 27 of 44 practice emails.

What does a DPO preference pair contain, and what went wrong with the lab's pairs?

One input, a better (chosen) answer and a worse (rejected) one. The lab's better replies came from a big model and the worse ones from the small model's old replies, so they were trivially easy to tell apart. The model learned to sound unlike its old self: style stayed at 98%, but helpful replies fell from 78 to 32 and it invented facts.

What are pass@1 and pass@8, and why do they matter for RFT?

pass@1 is the share of emails whose first try is right; pass@8 the share with at least one right answer in 8 tries. Rejection sampling only practises on emails with a passing try, so pass@8 is roughly how far the next round can reach. Before practice they were 14% and 36%.

Why did RFT stop 4 points short of training on the true answers?

One kind of email: a customer shouting URGENT with no real deadline. In 16 tries on each of the 31 practice emails like that, the urgency was never right, so there was never a tick to learn from. On the test, RFT got 1 of 15 of them against 15 of 15, and both got 259 of the other 285.

This is the latest chapter. More episodes from the same labs are on the way.

Learning something useful?

New labs, articles, and videos on evaluating and testing AI systems come out regularly. Follow along so you don't miss the next one.