RLHF vs DPO: how language models learn what people prefer
This is the long version of a post on LinkedIn.
Ask a raw pretrained language model "How do I boil an egg?" and it may reply with three more questions about eggs. It is not being unhelpful on purpose. It learned to continue internet text, and on the internet a question is often followed by more questions. Turning that text predictor into an assistant that answers is the job of preference tuning: teaching the model which of several possible answers people actually prefer.
This post is the long version of a short LinkedIn post. It covers the classic recipe, RLHF (reinforcement learning from human feedback), and the simpler method that has largely replaced its hardest part, DPO (direct preference optimisation).
Why next-token training is not enough
Pretraining teaches a model one thing: given some text, predict the next token. That builds grammar, facts and style, but it does not encode a goal such as "be helpful, be truthful, follow the instruction". Many continuations are plausible; only some are useful.
The obvious fix is to show the model good answers and fine-tune on them. That is supervised fine-tuning (SFT), and it helps a lot. Its limit is cost: someone has to write every ideal answer by hand. Judging answers is much cheaper than writing them. Given two replies, most people can say which is better in seconds. Preference tuning is built on that asymmetry.
The idea of learning a reward from human comparisons predates language models. Christiano and colleagues used it in 2017 to teach agents in games and simulated robots tasks that were hard to score with a formula. Stiennon and colleagues applied it to summarisation in 2020. OpenAI's InstructGPT paper (2022) turned it into the recipe most chat models followed.
The RLHF recipe, step by step
InstructGPT has three stages. The paper lists the data used for each: about 13k prompts for SFT, 33k for the reward model and 31k for the reinforcement learning stage, with labels from about 40 contractors.
Stage 1: supervised fine-tuning. Labellers write good answers to real prompts, and the pretrained model is fine-tuned on them. The result already follows instructions reasonably well and becomes the starting point for everything after.
Stage 2: the reward model. For each prompt the SFT model writes several answers, between 4 and 9 in InstructGPT, and a labeller ranks them. A ranking of K answers gives "K choose 2" pairwise comparisons: 6 pairs for 4 answers, 36 for 9. A reward model (InstructGPT used a 6-billion-parameter one) reads a prompt and an answer and outputs a single number, the reward. It is trained so that the preferred answer in each pair gets the higher score.
The training rule is the Bradley–Terry model: the probability that answer A beats answer B is the sigmoid of the difference in their rewards. A worked example makes it concrete. Suppose the reward model gives the preferred answer 2.0 and the rejected one 0.5. The difference is 1.5, and sigmoid(1.5) ≈ 0.82, so the model thinks there is an 82% chance the right answer wins. The loss is −ln(0.82) ≈ 0.20, small because the model is already right. If the scores were the other way round, the probability would be about 0.18 and the loss about 1.70. Confident wrong orderings are punished hard, exactly as in ordinary classification.
Stage 3: reinforcement learning. Now the language model (called the policy in RL language) writes answers to new prompts, the reward model scores them, and an algorithm called PPO (proximal policy optimisation) nudges the policy towards answers with higher reward. PPO limits how far each update can move the model, which keeps training stable.
There is a catch. The reward model is only reliable on answers that look like its training data. Push hard enough and the policy finds odd text that scores well but reads badly, a failure known as reward hacking. So the objective subtracts a KL penalty: a measure of how far the policy's word probabilities have drifted from the SFT model's, scaled by a coefficient called beta. InstructGPT also mixed in some ordinary pretraining updates (a variant it calls PPO-ptx) to limit the drop in performance on standard benchmarks, which the paper calls an "alignment tax".
Reading is half of it. RLHF and preference tuning shows this step by step in about 3 minutes. Sign up free to track what you’ve learned.
What RLHF achieved
The InstructGPT results are why the field adopted the recipe. In OpenAI's human evaluations, people preferred answers from the 1.3-billion-parameter InstructGPT model to those of the 175-billion-parameter GPT-3, despite the 100-fold difference in size. The 175B InstructGPT model's outputs were preferred to GPT-3's 85 ± 3% of the time, and to a few-shot-prompted GPT-3 71 ± 4% of the time.
The lesson is that a lot of what users experience as "quality" is not raw knowledge. It is whether the model uses what it knows in the shape people want.
The cost is complexity. Full RLHF keeps several large models in play at once: the policy being trained, the frozen SFT reference for the KL penalty, the reward model, and in PPO usually a value model as well. It also needs fresh samples from the policy during training, and it has many settings that interact. Getting it to train stably is real engineering work.
DPO: the same goal with one loss
Rafailov and colleagues (NeurIPS 2023) noticed something about the RLHF objective. If you maximise reward minus a KL penalty, the best possible policy has a known mathematical form in terms of the reward and the reference model. Turn that relationship around and the reward can be written in terms of the policy itself:
reward(answer) = beta × log( policy probability of the answer ÷ reference probability of the answer ) + a term that depends only on the prompt.
In words: an answer counts as high-reward exactly when the tuned model has made it more likely than the reference model did. The prompt-only term cancels when you compare two answers to the same prompt, so you can plug this "implicit reward" straight into the Bradley–Terry loss from stage 2. That is the whole of DPO. The loss is the negative log-sigmoid of beta times the difference between the chosen answer's log-ratio and the rejected answer's log-ratio. The paper describes it as a simple binary cross-entropy objective.
A worked example. Take beta = 0.1. After some training, the policy has raised the log-probability of the chosen answer by 2 relative to the reference and lowered the rejected one by 1. The margin is 0.1 × (2 − (−1)) = 0.3. Sigmoid(0.3) ≈ 0.57, so the loss is about 0.55. Before any training both log-ratios are 0, the margin is 0, sigmoid gives 0.5 and the loss is ln 2 ≈ 0.69. Every gradient step widens the gap between chosen and rejected.
The gradient has a sensible shape too. It raises the probability of the chosen answer, lowers the rejected one, and weights each pair by how badly the implicit reward currently orders it. Pairs the model already gets right contribute little; pairs it gets wrong contribute a lot. The authors report that dropping this weighting can make the model degenerate.
What disappears: no separate reward model, no sampling from the policy during training, no PPO. You need the model being trained, a frozen copy of the SFT model, and a file of preference pairs.
How DPO compared in the paper
The DPO paper tested three tasks with models of up to 6 billion parameters: steering IMDb movie-review continuations towards positive sentiment, summarising Reddit posts (TL;DR), and single-turn dialogue on Anthropic's Helpful and Harmless data.
On summarisation, with GPT-4 judging each summary against the human-written reference, DPO won about 61% of the time at sampling temperature 0, against 57% for PPO at its best temperature. DPO was also much more robust to the sampling temperature: PPO's quality could fall to the level of the untuned base model at high temperatures. On the sentiment task DPO gave a better trade-off between reward and drift from the reference model. On dialogue it was the only computationally efficient method tested that improved on the preferred answers in the dataset.
These are results on specific tasks and model sizes, not a universal verdict. But they made DPO the natural first choice for teams tuning their own models.
Reading is half of it. Episode 3: Which version is better? shows this step by step in about 3 minutes. Sign up free to track what you’ve learned.
Pitfalls that apply to both
- The model learns your raters, not the truth. If raters tend to prefer long, confident answers, preference tuning produces long, confident answers. Write down what "better" means before labelling starts, and check that raters agree with each other.
- Beta matters. Too small and the model drifts far from the reference and may get worse in ways the preferences never covered. Too large and it barely moves.
- Start from a good SFT model. Both methods are refinements. They cannot rescue a model that cannot follow the format of the task in the first place.
- Evaluate separately. Measure the tuned model on held-out prompts and on your normal benchmarks, so you see any alignment tax.
A practical order of work: collect demonstrations and run SFT, collect preference pairs, try DPO, and reach for full RLHF only if you need what it adds, such as a reusable reward model or training on fresh samples.
Questions people ask
What is the difference between RLHF and DPO?
RLHF trains a separate reward model on human rankings and then uses reinforcement learning (usually PPO) to push the language model towards high reward. DPO skips both the reward model and the reinforcement learning loop and trains the language model directly on pairs of preferred and rejected answers.
Why does RLHF need a KL penalty?
The reward model is only accurate on answers that look like the ones it was trained on. The KL penalty keeps the tuned model close to the starting model, so it cannot drift into strange text that happens to fool the reward model.
Is DPO always better than RLHF?
No. In the DPO paper it matched or beat PPO-based RLHF on the tasks tested, with far less machinery. But results depend on the data and the task, and both methods learn only what the preference data rewards.
See it move. Learn the ideas behind this post with animated lessons:
Start the lessonSources
- Ouyang et al. (2022), Training language models to follow instructions with human feedback (InstructGPT)
- Rafailov et al. (2023), Direct Preference Optimization: Your Language Model is Secretly a Reward Model
- Christiano et al. (2017), Deep Reinforcement Learning from Human Preferences
- Stiennon et al. (2020), Learning to summarize from human feedback
- Schulman et al. (2017), Proximal Policy Optimization Algorithms