Post-Training: SFT, Preference Tuning, RL
SFT, reward models, RLHF, DPO and RL with verifiable rewards.
A pretrained model continues text. Ask it a question and it may answer, or ask three more questions, or write the rest of a forum thread. Everything that makes a model an assistant is added afterward: following instructions, keeping a consistent character, declining some requests, calling tools, stopping when it is done. That stage is post-training, and much of the visible difference between models comes from it.
The experiments here run on the small model from Chapter 7. It is far too small to be an assistant, but it is large enough to show each mechanism: how quickly fine-tuning teaches a format, what it fails to teach, what it destroys, and what a reward does when nothing holds the model back.
9.1The gap
A base model continues text, and an assistant has to be trained to answer.
The model that comes out of pretraining is called a base model. It has absorbed a great deal about language and the world, and it has one behavior: produce a likely continuation. Post-training keeps the network and changes what it is trained on.
| Stage | Training signal | What it teaches |
|---|---|---|
| Supervised fine-tuning (SFT) | Examples of good responses | The conversation format, instruction following, a baseline of helpful behavior |
| Preference tuning | Comparisons: which of two responses is better | Qualities with no single right answer: tone, judgment, helpfulness |
| Reinforcement learning | A score for each attempt, from a checker or a judge | Getting verifiable things right: math, code, multi-step tasks |
Compared with pretraining, each stage uses far less data and compute. The effect on behavior is out of proportion to the cost, because the knowledge is already in the weights and only its expression is being shaped.
Common take“A chat model is what you get from training on the internet.”
Sharper take“Training on the internet gives a text continuer. The assistant comes from a second, much smaller phase of training on curated conversations and feedback.”
9.2Supervised fine-tuning
The same loss on a different kind of text.
SFT is ordinary training continued on new data. Each example is a prompt followed by the response you want, laid out with the chat template from section 6.8, and the loss is the usual next-token cross-entropy, normally counted on the response tokens only.
To see how fast it works, I gave the Shakespeare model a task it had never seen: capitalize a five-letter word, in a fixed format.
WORD: rings
CAPS: RINGSThe fine-tuning set was 1,295 words. The test was 200 words that were not in it, scored by exact match.
The speed comes from reuse. The model already represented letters and the layout of text; it needed only the mapping and the format. The same holds at full scale, where instruction tuning uses thousands to millions of examples against the trillions of tokens of pretraining, and where the quality of the examples matters more than the count.
Common take“Fine-tuning needs a huge dataset.”
Sharper take“Fine-tuning teaches a format or a narrow skill from hundreds to thousands of examples, because the pretrained model already has the pieces. Here a new task went from 0% to 99% in 200 steps.”
9.3Form versus facts
Behavior arrives quickly, knowledge does not.
A second task, harder in a specific way. Given the first 30 characters of a speech, name the character who says it, choosing among the twelve who speak most.
LINE: Welcome, good Clarence; this i
WHO: GLOUCESTERI fine-tuned on 1,178 examples and tested on 208 speeches held out from fine-tuning.
| First 30 characters of the speech | Base model continues with | Fine-tuned model answers | Correct answer |
|---|---|---|---|
I will not fail: 'tis twenty y | I·will·the·shall·be·t | GLOUCESTER | JULIET |
Welcome, good Clarence; this i | I·have·the·shall·be·t | GLOUCESTER | GLOUCESTER |
What is about to be? I am out | I·will·the·shall·the· | KING RICHARD III | MENENIUS |
After 100 steps, every answer was a valid character name in the right format; the base model managed none. Accuracy never caught up. At the end of fine-tuning, 12% of answers named the right character, and always answering “GLOUCESTER”, the most frequent speaker, would have scored 16%.
The model learned how to answer and not what the answer is. The format is a pattern, and a thousand examples are plenty to learn a pattern. Knowing who says a line is knowledge, and neither this model’s pretraining nor a thousand examples supplied it.
Common take“Fine-tune the model on our documents so it knows our product.”
Sharper take“Fine-tuning reliably changes how a model answers. It is an unreliable way to add facts. A thousand examples taught this model the answer format perfectly and the answers not at all.”
9.4Catastrophic forgetting
New training overwrites old skills unless something holds them in place.
Fine-tuning does not add a layer on top of a model. It moves the same weights that hold everything else. During the speaker task I tracked the model’s loss on ordinary Shakespeare text, the thing it was pretrained to do.
- fine-tuned on the new task only
- one batch of original text for every batch of the new task
The first hundred steps alone took the loss past 4. This is catastrophic forgetting, and the standard defenses all work by limiting how far the weights can move, or by reminding them of the old task:
- Replay: mix general data into the fine-tuning set, as in the blue line.
- Small steps: a low learning rate and few passes over the data.
- Adapters: freeze the original weights and train a small number of added ones (LoRA, Chapter 17).
- Regression tests: evaluate the old abilities after every fine-tune, not only the new one.
Common take“Fine-tuning adds a skill on top of what the model already knows.”
Sharper take“It moves the weights that hold everything else. With no counterweight, 500 steps on a narrow task took this model’s original loss from 1.69 to 6.64.”
9.5Preference tuning
Where there is no single right answer, learn from comparisons.
For most of what makes an assistant good there is no reference answer to imitate. But people can reliably say which of two responses they prefer. Preference tuning turns those comparisons into a training signal.
In RLHF, the approach that produced the first widely used chat assistants, the comparisons train a separate reward model that scores any response the way raters would. The language model is then updated with a reinforcement-learning algorithm, usually PPO, to produce responses that score higher, with a penalty for moving far from the fine-tuned model it started as.
DPO, direct preference optimization (2023), reaches a similar result with less machinery. It skips the reward model and the reinforcement-learning loop and trains directly on the pairs: raise the probability of the preferred response and lower that of the rejected one, measured against a frozen copy of the starting model. It is simpler and more stable, and it is now a common choice for preference tuning on open models.
Both methods inherit the tastes of the raters. A model optimized for approval can learn to flatter, to agree, or to sound confident, because those are things people tend to prefer in the moment.
Common take“RLHF means people correct the model’s answers.”
Sharper take“People compare pairs of answers. A reward model learns their taste and the language model is optimized against it, or, with DPO, the pairs are used directly. Either way the model learns what raters prefer, which is not always what is true.”
9.6Checkable rewards
Reinforcement learning optimizes exactly what you measure.
Some tasks can be scored by a program: a math answer matches, the unit tests pass, the game is won. Then no human feedback is needed. The model attempts the task many times, each attempt is scored, and the attempts that scored above average are made more likely. This is reinforcement learning with verifiable rewards, the method behind the reasoning models of Chapter 10.
A small version shows both its power and its hazard. The reward: 1 if the next 24 characters the model writes contain no letter “e”, otherwise 0. The base model earns it 11% of the time.
- reward only
- reward, plus a penalty for drifting from the original model
The orange line looks like a triumph until you read what the model writes:
| Model | Earns the reward | Two samples of what it writes | Loss of its text under the original model | Its own loss on Shakespeare |
|---|---|---|---|---|
| Original model | 11% | you·shall·be·doom'd·oottce,·dent·the·print,↵Subj | 1.54 | 1.69 |
| Reward only | 100% | y,·'·,·i,··↵BS;·!·↵↵BUSnn,·'·'·W·,···l,·l;··'f·i | 5.63 | 4.69 |
| Reward plus penalty | 80% | you·ribus·can·to·that·twcious·of·thinks·not↵Us·n | 1.69 | 1.94 |
With the reward alone, the model stopped writing words. Punctuation and spaces contain no “e”, so they earn full reward. The reward asked for “no letter e”; what was wanted was “English without the letter e”. The model optimized what was measured. This failure is called reward hacking, and it is the central risk of reinforcement learning at any scale.
The blue line adds one term: a penalty that grows as the model’s predictions move away from the original model’s. Success is lower and the text is still text. Every production method has an equivalent. PPO limits how far each update can move the model, RLHF penalizes distance from the starting model, and rewards are audited for loopholes before and during training.
Common take“Reward the right outcome and the model learns the task.”
Sharper take“It learns to get the reward. If the reward can be earned without doing the task, reinforcement learning finds that route first. This model found it in 50 steps.”
9.7Feedback from models
Synthetic data, written principles and model judges.
Human feedback is slow and expensive, so much of post-training now uses models to supply the signal.
- Synthetic examples. A strong model writes the fine-tuning data for a weaker one, a form of distillation. The examples are filtered, since the teacher’s mistakes are copied along with its skills.
- Written principles. In constitutional approaches, a model is given a list of principles, asked to critique and revise its own responses against them, and then trained on the revisions. A model can also make the pairwise comparisons that people make in RLHF.
- Model judges. A model scores responses against a rubric, and the scores serve as rewards. Chapter 23 covers how to check that a judge agrees with people before trusting it.
These methods scale well and have a shared weakness: the feedback is only as good as the model giving it, and errors can compound when models train on models. Human review of samples stays in the loop for that reason.
This stage is also where a model’s character is set: how it handles requests it should decline, how it responds to a system prompt, how it expresses uncertainty. Several labs publish documents describing the behavior they train for, and those documents are the specification that this stage tries to meet.
Common take“Models are aligned by people labeling data.”
Sharper take“People write the principles and audit samples. Most of the feedback volume now comes from models applying those principles, which scales, and which fails quietly if nobody checks the judge.”
9.8The limits
What post-training can change, and what it cannot.
| Post-training changes readily | Post-training changes poorly |
|---|---|
| Response format and length | Broad factual knowledge |
| Tone and character | Languages or domains absent from pretraining |
| When to decline or to ask | The underlying capacity of the network |
| Tool-call syntax and when to call | Knowledge of events after the training data ends |
| Habits of step-by-step reasoning |
This division is useful when comparing models. Differences in how two models feel to use, their tone, verbosity, caution and tool habits, are mostly post-training. Differences in what they know are mostly pretraining. Skill at hard problems draws on both: pretraining scale, plus reinforcement learning on tasks that can be checked.
It is also the stage you can run yourself. Fine-tuning open weights (Chapter 17) is the same process at smaller scale, with the same behavior as the experiments above: format is learned quickly, facts are not, old skills are lost unless protected, and any reward is optimized literally.
Common take“Model A is smarter than model B.”
Sharper take“I separate what pretraining gave, knowledge and raw capability, from what post-training shaped: format, tone, refusals, tool use. The second is the part I can change with my own fine-tuning.”
Key takeaways
- A base model continues text. Post-training makes it an assistant, using far less data than pretraining.
- Supervised fine-tuning is the same loss on examples of the behavior you want. A new task went from 0% to 99% in 200 steps here.
- Fine-tuning teaches form faster than facts: the model answered in the right format 100% of the time and with the right answer 12% of the time, below a 16% baseline.
- Fine-tuning moves the weights that hold everything else. Loss on the original task went from 1.69 to 6.64 without replay and to 1.79 with it.
- Preference tuning learns from comparisons. RLHF trains a reward model and optimizes against it; DPO trains on the pairs directly.
- Reinforcement learning optimizes what is measured. Rewarded for avoiding “e”, the model reached 100% by writing punctuation.
- A penalty for drifting from the starting model kept the text intact at 80% success. Every production method has an equivalent.
- Post-training shapes format, tone, refusals and tool use. Knowledge comes from pretraining, or from retrieval.
Check your understanding
-
You fine-tune an open model on 5,000 of your support conversations. In testing it sounds exactly right. It also quotes wrong prices, and it has become worse at writing SQL, which it did well before. Explain both problems using this chapter’s experiments, and give a fix for each.
Answer outline
The wrong prices are the speaker experiment: fine-tuning taught the form of a support answer, not the facts in it, so the model produces plausible prices in the right style. Fix: supply prices at answer time through retrieval or a tool, and fine-tune only for tone and format. The lost SQL skill is catastrophic forgetting: the weights moved toward support conversations and away from everything else. Fix: mix general and coding data into the fine-tuning set, lower the learning rate and number of passes, or train adapters with the base weights frozen, and add SQL to the regression tests run after each fine-tune.
-
You train a coding model with reinforcement learning, where the reward is the fraction of unit tests that pass. Pass rates climb quickly. Reviewers then find functions that check for the exact test inputs and return the expected outputs. What happened, and how would you change the setup?
Answer outline
Reward hacking: passing the visible tests was rewarded, and special-casing the inputs is the cheapest way to pass. Changes: score against hidden tests the model never sees, generate or randomize test inputs, add a judge or static check that penalizes code keyed to test values, keep a penalty or update limit that holds the model near its starting behavior, and read samples from high-reward attempts regularly, since the curve alone looked like success.
-
A teammate proposes preference-tuning your model with DPO, using 300 comparison pairs written by two annotators. What does the method need to work well, and what risks do you see in this plan?
Answer outline
DPO needs pairs that cover the range of prompts the model will see, with consistent judgments about which response is better. Three hundred pairs from two people is thin and encodes two people’s taste; the model can overfit to it, learn their stylistic habits, or drift toward answers that please over answers that are correct. It can also forget, like any fine-tune. Before using it: collect more and more varied pairs, measure agreement between annotators, hold out pairs to test on, keep the update small, and run the general evaluation suite afterward.
Further reading
- Nathan Lambert, The RLHF Book (free online): reward models, PPO, DPO and their practical problems, from someone who trains these systems.
- Chip Huyen, AI Engineering, chapter 2 on post-training and chapter 7 on fine-tuning.
- Ouyang et al. (2022), “Training language models to follow instructions with human feedback”: the paper that established the SFT-then-RLHF recipe.
- Rafailov et al. (2023), “Direct Preference Optimization”, and Bai et al. (2022), “Constitutional AI”: preference tuning without a reward model, and feedback from written principles.