模型蒸餾解説:大模型以 49 美分撰寫 420 個問題,三個小模型從其決策中學習
Model Distillation Explained: A Bigger Model Wrote 420 Questions for 49 Cents, and Three Small Models Learned From Its Decisions
作者以 Claude Sonnet 4.5 花費 $0.49 生成並標註 420 個真實問法,再用其中 183 個標籤訓練三個小模型。Qwen2.5-0.5B-Instruct 在 172 道教師生成測試題上的整體準確率由 58.1% 升至 75.0%。不過,三個模型在這批測試題上均未能於預設門檻達到 98% 精確率;作者指出,與教師標籤一致不代表答案正確。
Part 9 of ten. Each post is a short, plain-words tour of one lesson from e=mc², a free build-an-LLM-from-scratch course; the full lesson, notebook and numbers are on the site.
A small model trained on templates learns the catalog, not how people talk. That is the wall Lesson 08 left me at. My tiny decider gave a valid answer to every template question and got 71.3% of them exactly right, and then a real person would type something like "which representative handles T-123?" and it had never seen a sentence shaped that way in its life.
Tonight's lesson is about the cheapest fix I know. Let a bigger model handle the realistic questions, keep its decisions, and train the small model on those decisions. The whole run, three small models before and after, took 169.6 seconds on an Apple Silicon Mac. The teacher cost 49 cents.
Ella becomes the teacher
In this course Momo the monkey is the model and Ella the elephant is the one who corrects him. Until now Ella has been drilling Momo on sentence patterns, thousands of template questions with the codes and dates swapped in and out. Momo got good at patterns. Real customers do not speak in patterns.
So Ella changes jobs. She already answers everything Momo passes to her, so tonight she writes 420 realistic questions herself, then labels each one with the operation the counter should run. Momo studies her decisions.
That is application-level distillation. The classic version of distillation copies a big model's probabilities, its whole spread of maybe-this and maybe-that. This lesson copies something plainer: its decisions, inside the actual application. In the real system the teacher is the same slow planner that undecided questions already go to, so the labels cost nothing extra. Here I had to rent one.
Renting a teacher for 49 cents
The open-source project this course builds toward, pankhllm, uses a local 12B model as its planner, and its teacher-written questions are not public. So I had Claude Sonnet 4.5, reached through OpenRouter, stand in. It wrote 420 questions from the catalog's plain descriptions rather than its regular expressions (the project's dataset notes record a teacher once copying a regex straight into its questions), then labelled each one against the catalog without being told what it had been written for.
Validation threw out 14 labels, mostly months written as words. 406 remained. That took 49 calls and $0.49 as reported by OpenRouter. After removing near-duplicates, 405 questions: 183 to learn from, 50 to set each model's confidence threshold, and 172 held back as the test that nobody trains on.
Why 183? Because that is the number from pankhllm's own published benchmark, where 183 teacher labels added to 20,000 template questions raised coverage by about ten points without losing precision. I wanted to see whether the same step would hold for three very different students.
Three students, one teacher
- Momo from scratch. Lesson 08's decider, 0.84 million parameters, continued for 300 more steps with eight teacher questions in every batch of 64, so it saw each label about 13 times.
- BERT-mini, a 4-layer encoder with 11.2 million parameters. An encoder reads the whole question at once, like a reader.
- Qwen2.5-0.5B-Instruct, a decoder, 495 million parameters with its adapters. A decoder writes left to right, so its answer is literally its next word.
The two borrowed models are not retrained. They get LoRA, Lesson 06's trick: freeze the borrowed book, learn small sticky notes to stick on it. For Qwen the whole decision becomes one token. After "Question:... Operation:", the next word is one of eight short words, and the probability of each word is the model's confidence in that choice.
WORD = {"kpi_value": " value", "kpi_rank": " rank", "kpi_vs_benchmark": " benchmark", "kpi_change": " change",
"kpi_trend": " trend", "prescriber_list": " list", "coverage_owner": " owner", "UNSUPPORTED": " none"}
LABEL_IDS = [tok(WORD[op], add_special_tokens=False)["input_ids"][0] for op in OPS] # one token each
model = get_peft_model(qwen, LoraConfig(task_type="CAUSAL_LM", r=8, lora_alpha=16,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"]))
enc = tok([f"Question: {shape}\nOperation:"], return_tensors="pt")
p = F.softmax(model(**enc).logits[0, -1, LABEL_IDS], -1) # the next token is the decision
All three read the question's shape, Lesson 07's stickers over codes, months and numbers. And all three face the same rule: abstain if your favourite operation does not structurally fit the question, otherwise decide only when your confidence clears a threshold chosen before the test, the lowest at which both calibration sets hold 98% precision.
The numbers, honestly
On the 172 teacher-written test questions, the share each model decided and the precision it held, before and after the 183 labels:
- From scratch: 19.2% at 90.9% before, 27.9% at 95.8% after. The best precision of the three: two wrong in 48 decisions.
- BERT-mini with LoRA: 20.3% at 85.7% before, 30.2% at 92.3% after.
- Qwen with LoRA: 30.8% at 86.8% before, 65.1% at 88.4% after. Its accuracy across all 172 questions went from 58.1% to 75.0%.
All three improved. Qwen improved most, and Qwen is 44 times larger than BERT-mini and pretrained; this run does not separate the two causes. The labels helped on the old template test as well: Qwen's template accuracy rose from 74.3% to 95.8%.
Now the part a teaser would normally skip. None of the three held 98% precision on the teacher-written questions at its fixed threshold. Even if I cheat and tune the threshold on the test set itself, the best any model manages at 98% is Qwen's 17.4%. Part of that is a ceiling nobody can train past: 11.0% of the teacher's own test labels name an operation the question does not structurally fit, so under the abstain rule no student can ever decide those.
One more honest line. Precision on a set the teacher labelled means agreement with the teacher, not truth. The teacher makes mistakes of its own, and pankhllm's docs list disagreements where the small model was right and the teacher was not.
Speed, one question at a time on a CPU: from scratch 0.643 ms, BERT-mini 1.384 ms, Qwen 45.95 ms. The simple regression baseline, 0.083 ms. Keep that gap in mind for tomorrow.
What I took from it
A few hundred labels copied from a bigger model's own decisions are cheap, and they helped every student, including one with under a million parameters. They did not buy the 98% rule here. On the lesson page a label counter widget retrains two of the models with 45 and 90 labels too, and the curve is not smooth: at 90 labels the decider decided 48.8% at 90.5%. With only 50 calibration questions, one or two confident mistakes move a threshold a long way, which is also why a model can decide less while getting more precise.
The full results table, the glossary in Momo's words, the widget and the notebook are all on the lesson page. The postcard version is this: when templates run out, borrow a bigger model's judgement, keep its decisions, and measure what they bought you.
Want to actually build it?
This post is the postcard. The lesson is the trip. Lesson 09 of e=mc² on theaivibe.org walks you through every piece with widgets you can poke, a notebook that runs on a free GPU in minutes, and the honest numbers at every step. No account, no paywall, nothing to install.
- Start here: https://theaivibe.org/emc2/application-level-distillation-small-decision-model
- The whole ten-lesson journey: https://theaivibe.org/emc2
Tomorrow: the three students are shrunk to int8, timed, and put in front of pankhllm's own binary, which decides whether either of them earns a lane.
來源:DEV Community · dev.to