code
Teaching a small model to say "I don't know"
SFT, DPO and GRPO on Qwen3-1.7B and SQuAD 2.0. SFT did almost all the work.
While building with small models at the application layer, I kept running into hallucinated facts, misread questions (more in a previous note) and arithmetic slips. That made me curious about how small models handle tricky questions. I had also never worked with post-training or RLHF techniques, and this looked like a small, bounded way to get my hands dirty and learn something quickly.
I wanted to know whether a 1.7B model can learn to answer from a paragraph, and to say exactly “I don’t know” when the paragraph doesn’t contain the answer.
The code and every run’s results are on GitHub.
The data
I used SQuAD 2.0,1 a public dataset of questions about Wikipedia paragraphs. Each item is a paragraph, a question about it, and the gold answers: short spans copied from the paragraph, or none if the question is unanswerable. The training set has ~130k questions, about a third of them unanswerable, and the official dev set ~12k, about half unanswerable.
The unanswerable questions were written by crowdworkers to look answerable. Usually they take a real question and swap one detail (a name, a number, a verb, a negation) so the paragraph no longer answers it.
I carved out five fixed splits, each exactly half answerable and half unanswerable:
| Split | Questions | Source | Used for |
|---|---|---|---|
| SFT | 3,000 | SQuAD train | supervised fine-tuning |
| DPO | 2,000 | SQuAD train | sampling the SFT model to build preference pairs |
| GRPO | 1,500 | SQuAD train | sampling the SFT model to pick GRPO questions |
| dev | 300 | SQuAD train | every choice: prompt, epoch, learning rate, checkpoint |
| test | 500 | SQuAD official dev set | final numbers, run once per model |
No question appears in two splits. The test set comes from the official dev set, which uses different Wikipedia articles from training, so the model never saw those paragraphs (data.py).
Baselines
To check that this dataset actually pushes small models, I ran baselines with Qwen3-1.7B and Qwen3-8B. My aim was to use post-training to get the 1.7B to match or beat the 8B.
The results weren’t surprising. On the test set, the 1.7B hallucinated on 51% of the unanswerable questions, and the 8B on 44%. Every model got the same prompt, shown here with a test question:
<|im_start|>system
You answer questions using only the paragraph you are given. If the paragraph contains the answer, reply with the answer copied from the paragraph in 10 words or fewer. Do not write a full sentence and do not add anything else. If the paragraph does not contain the answer, reply exactly: I don't know<|im_end|>
<|im_start|>user
Paragraph:
Oxygen condenses at 90.20 K (−182.95 °C, −297.31 °F), and freezes at 54.36 K (−218.79 °C, −361.82 °F). Both liquid and solid O2 are clear substances with a light sky-blue color caused by absorption in the red (in contrast with the blue color of the sky, which is due to Rayleigh scattering of blue light). High-purity liquid O2 is usually obtained by the fractional distillation of liquefied air. Liquid oxygen may also be produced by condensation out of air, using liquid nitrogen as a coolant. It is a highly reactive substance and must be segregated from combustible materials.
Question: What freezes at 90.20 K?<|im_end|>
<|im_start|>assistant
<think>
</think>
| Model | Reply |
|---|---|
| Baseline 1.7B | Oxygen condenses at 90.20 K. |
| 8B ceiling | Oxygen |
The right answer is “I don’t know”: oxygen condenses at 90.20 K and freezes at 54.36 K. Both models fell for it, so there was plenty of room to improve.
I picked the prompt on dev and then froze it, comparing two versions in a rehearsal with Qwen3-0.6B. The original asked for “a short answer copied from the paragraph and nothing else”; the second asked for the answer “in 10 words or fewer. Do not write a full sentence”.
| Qwen3-0.6B, dev (300) | Hallucination | Over-refusal | Accuracy | Balanced |
|---|---|---|---|---|
| Original prompt | 86.7% | 3.3% | 67.3% | 40.3 |
| 10-word prompt | 54.0% | 14.0% | 63.3% | 54.7 |
The 10-word prompt didn’t make answers more accurate.2 All of its gain came from abstaining more: hallucinations fell from 87% to 54%, at the cost of over-refusals rising from 3% to 14%. I locked it in. Every evaluation after that used exactly this prompt with greedy decoding, and a hash of the prompt and decoding settings is stored with every result, so no number in this post came from a different setup.
Hardware
I rented a single RTX A5000 on RunPod for training and offline inference with vLLM. Its 24 GB of VRAM was plenty: SFT peaked at 5.7 GB. It cost $0.28/hr. Logged training time across every run was about 2.5 hours:
- SFT: 11.5 min
- DPO, both variants: 28 min
- twin DPO, both variants: 39 min
- GRPO: 40 min, plus about 30 for a second run I stopped early
Evaluation, sampling and vLLM start-up (~5 min per model) came on top of that. All in, the GPU time for the whole experiment cost under $5.
The pod during training.
The same GPU during the 8B baseline run. The 8B takes most of the VRAM.
How I measured improvement
The task gives a 2×2 matrix with four outcomes:
| Model answers | Model says “I don’t know” | |
|---|---|---|
| Answerable | ✓ correct, or ✗ wrong (an answer, but not the gold one) | ✗ over-refusal |
| Unanswerable | ✗ hallucination | ✓ correct abstain |
Test results in this matrix (250 answerable + 250 unanswerable):
| Model | Correct | Wrong | Over-refusal | Hallucination | Correct abstain | Balanced |
|---|---|---|---|---|---|---|
| Baseline 1.7B | 178 | 45 | 27 | 127 | 123 | 60.2 |
| SFT | 203 | 12 | 35 | 29 | 221 | 84.8 |
| DPO v1 | 180 | 10 | 60 | 14 | 236 | 83.2 |
| 8B ceiling | 223 | 22 | 5 | 110 | 140 | 72.6 |
“Balanced” is the average of two scores: accuracy on the answerable questions, and the correct-abstain rate on the unanswerable ones. A model that always says “I don’t know” scores 50, and one that always answers scores at most 50, so you only score well by doing both jobs.
grade() assigns the cells. Correct vs wrong applies to answerable questions only, in two versions:
- Lenient (the headline): full credit if a gold answer appears as whole words in an output of at most 20 words. Otherwise the output needs a token-F1 of at least 0.5 against the best gold answer.
- Strict: token-F1 of at least 0.5, with no containment shortcut. This penalises padding like “The Rhine is the longest river in Germany.”
Before trusting any of this, I read 50 random graded outputs from the 0.6B rehearsal by hand. My first grader used only token-F1, and I disagreed with it on 8–10 of the 50. F1 punishes extra words, so a correct answer wrapped in a sentence fails: for the one-word gold answer “Germany”, the sentence above scores F1 = 0.29 and is marked wrong. Small models love answering in sentences (“The well-known archeologist who believed… is Betty Meggers”), so this roughly halved measured accuracy. Adding the containment rule fixed it, leaving 1 disagreement in 50 (“The second level roads have tolls.” for gold “tolls are charged”, a paraphrase it still misses). After that I froze the grader with a fixture of 600 graded outputs, so it couldn’t change silently mid-experiment.
The 2×2 only sees each model’s final decision, so I also logged P(“I don’t know”), the model’s probability of replying exactly “I don’t know”, on every dev question, and summarised it with AUC: the chance that a randomly picked unanswerable question gets a higher P(“I don’t know”) than a randomly picked answerable one. AUC measures how well the model separates the two kinds of question, regardless of how cautious it is overall. A model that just says “I don’t know” more often everywhere keeps the same AUC.
SFT
From the KV caching note, I had a basic idea of how pretraining works: a huge corpus of text gets you a babbling autocomplete. For this experiment I read up on post-training, the techniques that turn a raw pretrained model into one that answers questions, calls tools and learns new behaviour.
- Pretrained model, given “What is the capital of France?”: “What is the capital of Germany? What is the capital of Spain? What…”
- After post-training on question-answer data: “Paris.”
Labs train Instruct versions of their models to make the babbling models follow instructions instead of generating text that resembles the prompt. One such technique is supervised fine-tuning (SFT), which relies on good examples: show the model a good example, and shift its weights so it sounds more like it.
is the model (the policy), the prompt and the target answer. This is the same loss as pretraining, except that the sum runs over the answer tokens only, not the whole prompt. The loss is high when the correct tokens get low probability, so the weights move to fix that.
Since this updates an already-trained model, you probably don’t need to update (or compute gradients for) every weight. For small, simple behaviours, the change can live in a low-rank subspace, so you add a low-rank update to the frozen weights and train only that. This is LoRA (Low-Rank Adaptation):
stays frozen, and the rank is usually 8–32. My SFT run:
- LoRA with rank 16 on every linear layer: 17.4M trainable parameters, 1% of the model.
- 2,870 examples, half of them unanswerable. The target is the shortest gold span or exactly “I don’t know”, with the loss on the answer tokens only.
- 2 epochs at learning rate 2e-4, which took 11.5 minutes. Epoch 2 scored higher on dev (83.7 vs 81.3).
SFT training loss, and dev error rates per epoch.
The loss collapses within the first ~30 steps: copying a span or writing “I don’t know” is an easy format to learn. On dev, epoch 1 overshoots slightly towards refusing (18% over-refusal), and epoch 2 pulls it back to 12%.
On test, hallucination fell from 51% to 12% and balanced score rose from 60 to 85. I expected SFT to overshoot into refusing everything, but over-refusal rose only 3 points. On dev, its AUC was 0.94, better than the prompted 8B’s 0.89.
Three dev questions, before and after SFT (all unanswerable):
| Question | Paragraph says | Baseline 1.7B | SFT |
|---|---|---|---|
| What is Juan House an originator of? | “Juan Atkins, an originator of Detroit techno music…” | Detroit techno music. ✗ | I don’t know ✓ |
| By what year was indigo a low export for the Lowcountry? | “indigo was a leading export by 1750” | 1750 ✗ | I don’t know ✓ |
| Who refused to pass labor legislation? | “the Labor-controlled Senate refused to pass his banking legislation” | Labor-controlled Senate. ✗ | the Senate ✗ |
The first two are the typical SFT win: one swapped detail, and SFT’s P(“I don’t know”) goes from ~0 to 0.997 and 1.0. The third shows what’s left. The swap (“banking” → “labor”) hides behind a word that sits right next to the answer (“Labor-controlled”), and SFT puts only 0.009 on “I don’t know”. The 8B falls for it too.
DPO
Next, I looked at the RL techniques used to teach subtler behaviours, starting with the direct alignment algorithms chapter of Nathan Lambert’s RLHF book. The standard RLHF objective is
so it pulls in two directions: score high, and don’t drift from the reference model. It needs a trained reward model to score answer to input .
DPO (Direct Preference Optimization) skips the reward model by using preference data instead. Each example is an input and two responses: , the preferred one, and , the rejected one.3
Relative to the reference model, the trained model should raise the probability of the chosen response by more than it raises the rejected one, so DPO pushes each pair apart.
This is a reformulation of the RLHF objective. The reward can be written in terms of the policy’s own log-probabilities, and the part that depends only on the prompt cancels out when you take the difference between the two answers. The implicit reward is times the log-probability shift from the reference.
To keep the pairs on-policy, I built them from the SFT model’s own mistakes. I sampled it 4 times per question at temperature 1.0 on the 2,000 DPO questions and graded every sample. On unanswerable questions, “I don’t know” was preferred over each hallucinated answer. On answerable ones, a correct answer (the model’s own if it produced one, otherwise the gold span) was preferred over a sampled “I don’t know” or a wrong answer. Two real pairs, the first unanswerable and the second answerable:
{"question": "Who was the first caliph?",
"chosen": "I don't know", "rejected": "Muhammad"}
{"question": "When was Jiang Hua's term?",
"chosen": "1956-1968", "rejected": "I don't know"}
Training continued the SFT LoRA adapter, with a frozen copy of SFT as the reference and . For each variant I ran 2 epochs at two learning rates and picked the best (learning rate, epoch) on dev.
v1 had 558 pairs, balanced between answerable and unanswerable questions. But “I don’t know” ended up as the preferred answer 279 times and the rejected one only 172 times, so training pushed the model towards refusing. On test, hallucination fell to 5.6% but over-refusal rose to 24%, and balanced landed at 83.2, close to SFT’s 84.8. Every flip went one way: 15 hallucinations fixed and none introduced, 22 correct answers turned into refusals and none the other way. A typical loss: “What kind of T cells kill cells that are infected with pathogens?” went from “Killer T cells” (correct) to “I don’t know”.
v2 fixed the imbalance: 657 pairs, with “I don’t know” preferred 252 times and rejected 252 times. By the end of training it ranked 85–93% of training pairs the right way round, but that didn’t show up on dev: P(“I don’t know”) on dev barely moved (left panel below). It was memorising the training pairs. It also started shortening answers: “both explanations are reasonably well supported by the available data” became just “both”. The best checkpoint (lr 2e-5, epoch 1) beat SFT on dev by a net 2 questions out of 300 (5 gained, 3 lost). Then it was worse than SFT on test: 82.2 vs 84.8, with 18 questions lost and only 5 gained.
Twins. Next I tried showing the model a real question next to its edited version.4 I matched unanswerable SQuAD questions to the real question each was most likely edited from in the same paragraph5 (“Where was Avicenna once imprisoned?” / “Where was Avicenna twice imprisoned?”). That gave 387 training twins and 200 held-out ones. The input-side variant prefers the gold answer after the real question over after the edited one, and “I don’t know” the other way round, so the only signal is the change in the question.
It didn’t help. SFT already gave the edited question the higher P(“I don’t know”) on 97.5% of held-out twins, so there was little left to learn. At the higher learning rate it went the wrong way: P(“I don’t know”) fell on both kinds of question (right panel), and dev AUC dropped from 0.937 to 0.909. The loss only compares pairs, so nothing pins down the overall level.
Mean P(“I don’t know”) on dev during DPO v2 and twin DPO training.
Every result below is compared with SFT on the same questions: the change in balanced score, and the questions the model got right that SFT got wrong (gained) and the other way round (lost).
| Dev (300) | Halluc. | Over-ref. | Accuracy | Balanced | vs SFT | Gained / lost |
|---|---|---|---|---|---|---|
| SFT | 12.7% | 12.0% | 80.0% | 83.7 | — | — |
| DPO v1 | 8.7% | 19.3% | 74.0% | 82.7 | −1.0 | 6 / 9 |
| DPO v2 | 12.0% | 10.7% | 80.7% | 84.3 | +0.7 | 5 / 3 |
| Twin DPO, input-side | 11.3% | 12.0% | 81.3% | 85.0 | +1.3 | 6 / 2 |
| Twin DPO, output-side | 11.3% | 10.0% | 82.7% | 85.7 | +2.0 | 7 / 1 |
| Test (500) | Halluc. | Over-ref. | Accuracy | Balanced | vs SFT | Gained / lost |
|---|---|---|---|---|---|---|
| SFT | 11.6% | 14.0% | 81.2% | 84.8 | — | — |
| DPO v1 | 5.6% | 24.0% | 72.0% | 83.2 | −1.6 | 15 / 23 |
| DPO v2 | 12.4% | 17.2% | 76.8% | 82.2 | −2.6 | 5 / 18 |
| Twin DPO, output-side | 12.4% | 14.4% | 79.6% | 83.6 | −1.2 | 6 / 12 |
From the twin runs on, a model only got a test run if it beat SFT on dev by at least 2 points, with more questions gained than lost. Twin input-side didn’t, so it never ran on test. The output-side variant was a control.
v1 refused more everywhere because “I don’t know” won more pairs than it lost. v2 balanced that, but memorised pairs and shortened answers.
GRPO
GRPO (Group Relative Policy Optimization) gets rid of the critic model that PPO needs. For each question, the model writes 8 answers and the grader scores each one. Each answer’s advantage is its reward relative to the rest of its group:
Above-average answers are made more likely and below-average ones less likely, and a KL penalty keeps the model close to SFT.6
The reward reuses the grader (grader.py): for a correct “I don’t know”, for a hallucination, the answer’s lenient score (0 to 1) for answering an answerable question, and for refusing one, plus a small penalty for malformed outputs:
def reward(output, answerable, golds, h=1.0, r=0.5):
g = grade(output, answerable, golds)
if answerable:
base = -r if g["abstain"] else g["lenient_score"]
else:
base = 1.0 if g["abstain"] else -h
# empty, over 30 words, or "I don't know" mixed with other text
fmt = 0.0 if g["format_ok"] else -0.5
return base + fmt
A group where all 8 answers score the same has zero advantage and teaches nothing, and the SFT model gets most questions right every time. So I sampled SFT 8 times on each of the 1,500 GRPO questions and kept only the 518 where its answers disagreed. I dropped 36 answerable ones whose only contrast was “I don’t know” vs a wrong answer, which can only teach guessing. I then topped up with unanswerable questions from the DPO split and repeated unanswerable ones to get back to 50/50: a pool of 684 rows.
My GRPO runs:
- Training continued the SFT LoRA adapter, with a frozen copy of SFT as the KL reference (KL coefficient 0.04).
- Each step took 4 questions and 8 answers per question, sampled at temperature 1.0. Two passes over the pool came to 342 steps.
- I used TRL’s
GRPOTrainerwith loss typedapoand a constant learning rate, and checked dev every 50 steps.
The two runs, compared with SFT on dev:
| Run | h, r, learning rate | Best dev checkpoint | vs SFT | Gained / lost |
|---|---|---|---|---|
| G-default | 1, 0.5, 1e-6 | step 200: 84.3 | +0.7 | 8 / 6 |
| G-equal | 1, 1, 1e-5 | step 200: 85.0 | +1.3 | 10 / 6 |
G-default ran all 342 steps; I stopped G-equal at 250. Neither beat SFT on dev by 2 points, so neither ran on test.
The two runs were meant to test the penalties, and the penalties turned out not to matter. TRL’s default scale_rewards="group" is the division by the group’s standard deviation above. In a group with only two outcomes, say seven “I don’t know”s and one hallucination, that normalisation erases the size of the penalty. I checked: and gave the same advantages to within 0.0002. Only about a fifth of groups had three or more distinct rewards, so the two runs mostly tested the learning rate.
G-equal, the higher learning rate, learned to pad its answers. The lenient score gives full credit to any answer of up to 20 words that contains the gold answer, so listing more of the paragraph costs nothing. Its best checkpoint’s dev answers averaged 3.5 words, against SFT’s 2.6. Asked “How many bits of control flags did USB 2.0 add?”, SFT answered “seven” (wrong); G-equal answered “seven-bit hub number, 12 bits of control flags, and a five-bit CRC” and got full credit.
GRPO also ran short of signal as training went on. As the model got more consistent, more groups went silent (all 8 rewards equal, so no gradient): on unanswerable questions, from 27% to 55% for G-default and from 39% to 78% for G-equal.
GRPO: share of silent groups by class, and dev answer length.
Why nothing beat SFT
To see what DPO and GRPO actually changed, I took SFT and varied only its threshold: abstain whenever its own P(“I don’t know”) is above a cut-off, swept from 0.05 to 0.95. That traces every hallucination vs over-refusal trade-off SFT can reach just by being more or less cautious. Then I placed every trained model on the same chart. All of them land on SFT’s line: at each model’s hallucination rate, its over-refusal is about what SFT gets by thresholding.
SFT’s threshold curve vs every model’s operating point on dev. Lower-left is better.
AUC on dev barely moved either:
| Model (dev) | P(“I don’t know”) AUC | vs SFT |
|---|---|---|
| Baseline 1.7B | 0.797 | −0.140 |
| 8B ceiling | 0.892 | −0.046 |
| SFT | 0.937 | — |
| DPO v1 | 0.939 | +0.002 |
| DPO v2 | 0.940 | +0.002 |
| Twin DPO, input-side | 0.940 | +0.002 |
| Twin DPO, output-side | 0.942 | +0.004 |
| GRPO G-default | 0.941 | +0.004 |
| GRPO G-equal | 0.941 | +0.004 |
The later methods changed how cautious the model was. None of them improved how well it tells the two kinds of question apart. DPO v1 and G-default slid along the line towards refusing; the others stayed near SFT’s point.
The hallucinations that are left are hard. I hand-coded SFT’s mistakes (analysis). About 13 of its 19 dev hallucinations are near-miss edits like the “labor legislation” question above: one detail of a paragraph sentence swapped, and the model answers from that sentence. And about 7 of its 29 test hallucinations are label noise: the paragraph does answer the question, so no amount of training should “fix” them. Many of the over-refusals, on the other hand, are easy, with the answer stated almost word for word in a sentence that mirrors the question.
What I learned
- SFT teaches the shape of the behaviour, and what a correct answer looks like: copy a short span, or say exactly “I don’t know”. One 11.5-minute LoRA run did most of the work.
- DPO does teach what’s correct and what’s wrong. It doesn’t necessarily teach why something is wrong. DPO v2 got most of its training pairs the right way round, but P(“I don’t know”) on dev barely moved. Learning the why might need more training, different data, or a lot more data.
If I’ve messed up somewhere, please hit me up by email.
Disclaimer: I used Claude Code to help write the experiment code, draw the figures, and edit this note.
Footnotes
-
From the SQuAD 2.0 paper (Rajpurkar, Jia and Liang, 2018). Of the training set’s 130,319 questions, 43,498 (33%) are unanswerable; of the official dev set’s 11,873, 5,945 (50%) are. ↩
-
On the lenient grader described below, accuracy went from 67.3% to 63.3%. On the strict one, which penalises answering in sentences, it rose from 48 to 67 correct out of 150, so the shorter format did help there. ↩
-
DPO works best when both responses come from the model being trained. Pairs written by someone else are off-policy: they push the model towards behaviour it never exhibited. ↩
-
Claude Opus suggested this one as something to try. ↩
-
SQuAD doesn’t record which question an unanswerable one was edited from, so the match is a guess from wording. A pair is kept only if the two questions are at least 0.8 similar, the match beats the runner-up by at least 0.1, each question is used once, and the gold answer is 10 words or fewer (
twins.py). Not every unanswerable question gets a twin. ↩ -
GRPO also clips each update, as PPO does, so no single step moves the policy too far. Here each batch of rollouts got exactly one optimiser step, so training stayed fully on-policy and the clip never triggered. ↩