Alignment and preference optimisation
- Production
- 45 min
- Lesson 5 of 7 in Fine-tuning
- Last verified
Select text in the lesson first to keep it with your note. With the keyboard, move focus here and press the button: the note goes with the section you are reading.
In this module
On this page
Before you start
You will be able to
- Describe the RLHF pipeline (SFT, reward model, policy optimisation), say what the KL penalty to the reference model protects against, and name what the pipeline costs.
- Read the DPO loss, say what beta and the frozen reference model each do, and compute the loss for a given pair of log-ratios.
- Choose among DPO, IPO, KTO, ORPO and SimPO by the data you have and whether a reference model is needed, and say why their reported gains are not a ranking.
- Compute a group-relative advantage as GRPO defines it, say what it removes compared with PPO, and separate the optimiser from the source of the reward.
- Explain reward hacking and over-optimisation, name two defences, and decide when SFT, a preference method or reinforcement learning is worth its cost.
The team asks a few customers to pick which of two answers they prefer. Nearly every vote goes to the one where Aarav sounds sure of himself, even when the other was closer to the policy.
Kavya reads the tally for a long while. “He will learn whatever we reward,” she says. “I am not sure this is what we meant to reward.”
If the votes become the rule, what is Aarav being taught?
Concept
The story is still about fine-tuning, but this lesson is about a different kind of practice. Supervised fine-tuning (SFTSFTShort for supervised fine-tuning: fine-tuning on pairs of a prompt and an ideal response.Open the glossary entry) shows the model one good answer and asks it to imitate. Preference optimisation shows the model two answers to the same prompt and says which one people liked better, so it learns to move toward the better kind. The customers’ votes in the story are preference data.
You already have the short version from Fine-tuning methods: RLHFRLHFReinforcement learning from human feedback: train a reward model on preferences, then optimise the model against it with reinforcement learning.Open the glossary entry trains a reward model and optimises against it, and DPODPODirect preference optimization: trains directly on preference pairs, without a separate reward model or reinforcement-learning loop. It still uses a frozen reference copy of the model.Open the glossary entry skips both the reward model and the reinforcement-learning loop. This lesson goes deeper: the RLHF pipeline and KL penalty, the DPO loss and beta, DPO’s relatives, GRPO and verifiable rewards, and reward hacking. Every method claim is what the named paper reports, with its date, not a settled law.
Why It Matters
Many qualities are easier to compare than to write: helpfulness, tone, concision, when to refuse. A preference dataset needs someone only to pick the better of two answers, which is cheaper, but it hands the model a stand-in goal (“be preferred”). The story shows the risk: confident announcements win the vote, so the model is paid for confidence. A candidate who can name the stand-in problem and its controls sounds like someone who has shipped.
Mental Model
Think of preference optimisation as coaching with a scorecard. The coach (the optimiser) watches Aarav answer, a judge (the reward, learned or checked) marks each answer, and the coach nudges him toward the higher marks. Two controls matter. A leash (the KL penalty, or beta in DPO) keeps him from wandering far from how he already writes. The scorecard itself must be trusted, because he will find whatever it rewards.
Where the analogy breaks: a person knows the scorecard is a proxy for doing the job well. A model does not. It optimises the numbers it is given, and nothing inside it asks whether the numbers still mean what you intended.
From demonstrations to preferences
The pipeline in the InstructGPT paper (Ouyang et al., arXiv 2203.02155, March 2022) has three steps: fine-tune on labeler demonstrations (SFT), train a reward model on human rankings of model outputs, then optimise the model against that reward with reinforcement learning. The paper reports that labelers preferred outputs from its 1.3-billion-parameter model over those of the 175-billion-parameter GPT-3. That is one paper’s result, on its own tasks and labelers.
RLHF and the KL penalty
Step two trains a reward modelReward modelA model that scores outputs by how well they match preferences. It is used in RLHF and to pick the best of several answers.Open the glossary entry that gives a prompt-and-answer pair one number. Labelers rank several answers to a prompt (InstructGPT used 4 to 9), and the rankings become pairwise comparisons. The goal is that the preferred answer scores higher:
Here is the reward model’s score and sigmoid () squashes any number into 0 to 1. The loss is small when the preferred answer outscores the rejected one clearly, and large when the order is wrong.
| Reward gap: preferred − rejected | Reading | |
|---|---|---|
| +2 | 0.127 | Preferred clearly ahead: small loss |
| 0 | 0.693 | Nothing learned yet |
| −2 | 2.127 | The order is wrong: large loss |
Step three optimises the model with reinforcement learning (PPO in the paper), rewarded by the reward model minus a penalty for moving away from the SFT model:
That subtracted term is a KL penalty. Why have it? Ouyang et al. say it mitigates over-optimisation of the reward model. The DPO paper adds the reasoning: the constraint keeps the model near the distribution where the reward model is accurate, keeps its answers varied, and stops it collapsing onto a single high-scoring answer. The reward model only saw answers from near the SFT model, so its scores far from there are guesses.
The trade-off sits in beta: small lets the model chase reward and risks exploiting the scorer; large keeps it close and gains little.
What the pipeline costs, from the papers’ own descriptions: a policy being trained, a frozen reference copy to measure the KL against, a reward model, and (in PPO) a value model, which the DeepSeekMath paper describes as typically another model of comparable size to the policy. The RL step also samples from the model during training, which the DPO abstract lists among the things DPO removes. InstructGPT also reports an alignment tax, lower performance on some public benchmarks, and a variant (PPO-ptx) that mixes in pretraining updates and greatly reduces those regressions.
DPO: the loss and beta
The DPO paper (Rafailov et al., arXiv 2305.18290, May 2023) starts from the RLHF objective above and shows that its best solution can be written in closed form. The reward can then be expressed through the model itself, so the reward model and the reinforcement-learning loop drop out. What remains is a classification-style loss on pairs. With the prompt, the preferred and the rejected answer:
Each log-ratio says “how much has training changed this answer’s likelihood” ( is the model being trained, the frozen reference). The loss rewards raising the preferred answer’s ratio above the rejected one’s. Each log-probability covers the whole answer, so it is the sum over its tokens.
What the pieces do
- The reference model. It anchors the ratios. Without it there is no “how far has it moved”. The paper sets to the SFT model when one exists, because the pairs were sampled from it. Without an SFT model it fits the reference to the preferred answers, to reduce the mismatch with the data.
- Beta. The paper describes it as the parameter controlling deviation from the reference. It multiplies the log-ratios, so the same movement counts for more when beta is large. The loss saturates sooner, so a model needs to move less to look good on the loss and stays closer to the reference.
- The weighting. The paper’s gradient raises the preferred answer’s likelihood and lowers the rejected one’s, and weights each pair by how wrongly the implicit reward orders them, scaled by beta.
Worked example (illustrative numbers)
Suppose . For one pair, the log-ratio for the preferred answer is +1.0 (the model made it more likely than the reference did) and for the rejected answer is -2.0.
- Margin inside the sigmoid: .
- , so the loss is .
- At the start of training the model equals the reference, both log-ratios are 0, the margin is 0 and the loss is .
Now keep the same log-ratios and raise beta to 0.5. The margin becomes 1.5, , the loss falls to about 0.201. The same movement now counts as nearly solved, so training stops pushing sooner.
| Aspect | |||
|---|---|---|---|
| Start of training (both log-ratios 0) | 0 | 0.500 | 0.693 |
| beta = 0.1, log-ratios +1.0 and −2.0 | 0.3 | 0.574 | 0.554 |
| beta = 0.5, same log-ratios | 1.5 | 0.818 | 0.201 |
One consequence of the formula is worth seeing. The loss depends only on the difference between the two log-ratios. A pair with log-ratios of −1.0 (preferred) and −3.0 (rejected) has the same margin as one at +1.0 and −1.0. The preferred answer can become less likely than under the reference while the loss still improves, as long as the rejected one falls faster. Watch the absolute likelihoods, not just the loss.
Because the reference is frozen and the pairs are fixed, its log-probabilities for each pair can be computed once and reused.
The DPO family
Follow-ups each change one thing about DPO. Read this as “what changed and why”, not a leaderboard.
| Method | What it changes | Data it needs | Reference model | Paper (date) |
|---|---|---|---|---|
| DPO | Baseline: log-ratio margin through a sigmoid | Pairs | Yes | Rafailov et al., May 2023 |
| IPO | Replaces the sigmoid loss with a squared loss to a fixed target gap | Pairs | Yes | Azar et al., Oct 2023 |
| KTO | Learns from one answer at a time, labelled desirable or not | Single answers with a binary label | Yes | Ethayarajh et al., Feb 2024 |
| ORPO | Adds an odds-ratio term to the SFT loss, in one stage | Pairs | No | Hong et al., Mar 2024 |
| SimPO | Uses average per-token log-probability as the reward, plus a margin | Pairs | No | Meng et al., May 2024 |
What each one changes
- IPO (Azar et al.). They argue that when preferences are one-sided, DPO’s KL control weakens, and a few pairs can look 100 percent one-sided by chance, so overfitting is a real risk. IPO regresses the log-ratio gap to a finite target, , so the model stops pushing even when every label agrees. Their examples are theoretical and illustrative.
- KTO (Ethayarajh et al.). Many products log only a thumbs-up or thumbs-down on a single answer. KTO needs just that binary label per example. It reports matching or exceeding preference-based methods at 1B to 30B parameters, and matching DPO with up to 90 percent fewer desirable examples. Its abstract concludes that no single loss of this kind is universally best.
- ORPO (Hong et al.). One stage and no reference: , where is minus log-sigmoid of the log odds ratio of the preferred over the rejected answer, , and uses length-normalised likelihood. It argues SFT stays essential for convergence.
- SimPO (Meng et al.). The reward is the average per-token log-probability, , with a target margin , so no reference is needed. Its ablation says removing the length normalisation hurts most, giving long, repetitive output. Any reward that grows with answer length can be gamed by length.
How to read these claims
Each paper tests its method on its own models, datasets and automatic judges, against baselines the authors chose. SimPO’s paper reports beating DPO and its variants; ORPO’s reports results above some larger models; KTO’s reports matches. They are not run against each other under one setup. Choose by the data you have and the memory you can spend, then test two candidates on your own evaluation, with a length check.
GRPO and verifiable rewards
When the answer can be checked, a learned reward model is not the only option. Two ideas get mixed up here.
GRPO is an optimiser. The DeepSeekMath paper (Shao et al., arXiv 2402.03300, February 2024) introduced Group Relative Policy Optimization as a variant of PPO that drops the critic. For each prompt it samples a group of answers from the old policy, scores them, and normalises the scores inside the group:
An answer’s advantage says “how much better than its siblings was this one”. PPO needs a value model for this baseline, which the paper notes is typically as large as the policy. GRPO estimates the baseline from the group’s scores instead, and adds the KL term to the loss directly.
Worked example (illustrative numbers)
Five sampled answers to one maths question, scored 1 if correct and 0 if not: [1, 1, 1, 0, 1]. The mean is 0.8. Taking the population standard deviation (implementations may differ), it is .
- Each correct answer: .
- The wrong answer: .
| Answer | Score | |
|---|---|---|
| 1 | 1 | +0.5 |
| 2 | 1 | +0.5 |
| 3 | 1 | +0.5 |
| 4 | 0 | −2.0 |
| 5 | 1 | +0.5 |
A rare failure is pushed down hard, a common success nudged up. If all five scored the same, every numerator would be zero and the group would teach nothing.
Verifiable rewards are a source of scores. In DeepSeekMath, GRPO’s scores came from a reward model. The DeepSeek-R1 paper (arXiv 2501.12948, January 2025) used GRPO with rule-based rewards instead: an accuracy reward (for maths, a final answer in a set format that can be checked; for code problems, a compiler running predefined test cases) and a format reward. The authors avoided a neural reward model for their first model because it may suffer from reward hacking in large-scale RL. Call this idea reinforcement learning with verifiable rewards.
Limits that follow from how it works:
- Rollouts. Every update needs G fresh samples per prompt, so generation, not gradient steps, tends to be the larger bill. (Derived from the algorithm, not measured.)
- The checker is a proxy too. A test suite that checks few cases can be satisfied without solving the problem. Verifiers need the same adversarial review as any metric.
- Only checkable tasks. Tone, helpfulness and safety have no unit test, which is why preference methods remain.
Reward hacking and over-optimisation
Goodhart’s law, quoted in the Gao et al. paper (arXiv 2210.10760, 2022), says: “When a measure becomes a target, it ceases to be a good measure.” In RLHF the measure is the reward model’s score, and it is an imperfect proxy for what people want. Gao et al. studied it with a fixed “gold” reward model standing in for humans and a proxy trained on its labels. They report that optimising the proxy too far hinders the gold score, with a relationship that depends on the optimisation method (reinforcement learning or best-of-n sampling) and scales smoothly with the size of the proxy reward model. The story’s passengers show the human version: a preference for confidence is a real preference, but optimising it past the point of being right is the failure.
Common forms in practice, as general patterns rather than findings of one paper: longer answers, flattery, confident wording, formatting that judges like. Defences:
- A KL leash or larger beta. Limits drift; costs some of the gain.
- Early stopping on a held-out measure, not the training reward. Needs an evaluation you trust (lesson 6).
- Fresh preference data on the current model’s outputs. Costs more labelling.
- Checkable rewards where available. Removes the learned proxy, not the verifier’s gaps.
- Length and style checks on every win-rate.
DPO has no separate reward model to exploit, but that does not make it immune. IPO’s analysis describes overfitting to one-sided pairs, and SimPO’s ablation shows length being exploited when it is not normalised. Treat “no reward model” as one less moving part, not as safety.
Choosing a method
Choose by what you have and what a failure would cost. This table is judgment, not data.
| You have | Likely choice | Main cost |
|---|---|---|
| A format, tone or skill, and good demonstrations | SFT, with LoRA first | Writing demonstrations |
| Chosen and rejected pairs, and a quality gap SFT cannot close | SFT, then DPO | Pairs on near-policy outputs; keep the reference loaded |
| Pairs, but memory is tight | Test ORPO or SimPO against DPO | Less established tooling and tuning; you must validate yourself |
| Only thumbs-up or thumbs-down logs | KTO | A noisy binary signal |
| A task with a checkable answer and a budget for sampling | GRPO with verifiable rewards | Rollouts and verifier design |
| A reward you must steer a large model with, and a specialist team | PPO-based RLHF | Several models, sampling, tuning |
The order from lesson 1 still holds: prompting and retrieval first, and any tune must beat that baseline. Preference methods come after SFT, and only if the evaluation shows a gap they can close. Preference tuning also carries the alignment tax: run the regression and safety tests from lesson 6 before shipping.
Real-World Application
Illustrative scenario: a team’s support assistant is accurate but wordy, and reviewers prefer the shorter answers. Suppose they have 4,000 reviewer comparisons of two answers each. A good plan: confirm that a better prompt does not close the gap; SFT on the best short answers; then DPO with the SFT model as the reference, using pairs sampled from that model. They try a few values of beta and evaluate on a held-out set with a length check and a factual-accuracy check, so brevity is not bought with errors.
Interview Perspective
Expect: “Compare RLHF, DPO and GRPO.”, “Write the DPO loss and explain beta.”, “How do you defend against reward hacking?”, “You only have thumbs-up and thumbs-down data. What do you do?”
A strong answer gives the data each method needs, the models held in memory, the failure mode, and a choice rule. It separates the optimiser from the reward source, and it says the papers’ gains are not a ranking. Common mistakes: “DPO is strictly better than RLHF”, “DPO cannot be reward-hacked because it has no reward model”, and describing GRPO as needing verifiable rewards.
Provenance: Common industry pattern. These are questions this topic tends to draw; none is verified for a named company.
Practice Questions
Provenance: generated practice.
- Basic: What problem does the KL penalty solve in RLHF?
- Intermediate: Write the DPO loss. What does beta do, and why does a reference model appear?
- Advanced: After DPO, win-rate against the SFT model rises, but answers are 40 percent longer and factual accuracy fell. Diagnose it and propose three fixes.
- Product: A teammate wants to start with reinforcement learning because it is more powerful. What do you ask first?
Activity
Do, notice, apply.
- Do. With , compute the DPO loss for a pair whose preferred log-ratio is +0.5 and rejected log-ratio is −1.5. Then compute it again with .
- Notice. Which loss is lower, and what does that say about how far the model must move before training stops pushing?
- Apply. Write a five-answer reward list for a question you can check. Compute each group-relative advantage, then change the list so every answer is correct and see what happens.
Homework
Write a one-page method memo for a behaviour you want from a model. State the data you have, the method you choose and the one you reject with a reason, the reference model and beta (or equivalent) you would start with, the held-out measure and length check you would use to stop, and the hacking you expect.
Quick Revision
- SFT imitates one answer; preference methods learn from “A is better than B”.
- RLHF: SFT, reward model, then RL against the reward minus a KL penalty to the SFT model.
- The KL penalty keeps the model where the reward model is accurate; it costs some gain.
- DPO: against a frozen reference. Higher beta keeps the model closer.
- IPO bounds the target gap; KTO needs only single labelled answers; ORPO and SimPO drop the reference.
- Reported gains are each paper’s own setup, not a ranking. Test on your evaluation.
- GRPO: ; no critic.
- Verifiable rewards are a reward source. Any scorer, learned or checked, can be gamed.
Check yourself
- Checkpoint (answer aloud, no notes): Compare RLHF with PPO, DPO and GRPO: the data each needs, the models held in memory, the failure modes, and when you would pick each.
- Re-test (nearby variant): You only have thumbs-up and thumbs-down feedback from production. What do you do, and what would you check before shipping?
- Misconception to avoid: “DPO is strictly better than RLHF.”
Related
Resources & Further Reading
Checked sources to go deeper. The essential ones come first in each group.
Research papers
LIMA: Less Is More for Alignment (opens in a new tab)
A study of how far supervised fine-tuning on a small curated set goes without any preference stage, which sharpens the question of when preference methods are worth their cost.
More for this module: Fine-tuning resources
Practice
Test what you just read. Quizzes and cards are grouped by module: Fine-tuning.
Check yourself18 questions on what this lesson set out to teach
Checking answers needs JavaScript. You can still read every question and option below.
Keyboard: arrow keys move between options. Space or Enter selects the focused option.