What Is DPO? Skipping RLHF's Reward Model and PPO
Direct preference optimization without a reward model
DPO (Direct Preference Optimization) drops RLHF's reward model and PPO and trains the model straight from "chosen / rejected" answer pairs. After this post you will know what the DPO loss actually pushes and pulls, how to read β and the loss number, and when DPO is a fine replacement for RLHF.
How it differs from RLHF
RLHF first builds a reward model from rankings, then raises that score with PPO. The 2023 DPO paper by Rafailov et al. at Stanford showed that, worked through the math, those two stages collapse into a single classification loss over the pairs. No reward model, and no need to sample fresh answers during training.
You also hold only two models while training: the one you are training and a frozen copy of it from before training (the reference model). PPO adds a reward model and a value model on top.
What the loss does
loss = -log σ( β × [ (log π(chosen) - log π_ref(chosen))
- (log π(rejected) - log π_ref(rejected)) ] )
In words: make the chosen answer more likely than the reference does, and the rejected one less likely. At the start the two models are identical, so the bracket is 0 and the loss starts at 0.693 (log 2).
I ran a toy
To get a feel for it I wrote a toy in Ruby with only three possible answers: one chosen, one rejected, and one that never appears in the data. All three start at probability 1/3. I trained on that single pair for 300 steps.
β step loss chosen rejected not in data KL to ref
0.1 10 0.646 0.503 0.189 0.308 0.075
0.1 300 0.172 1.000 0.000 0.000 1.096
0.5 10 0.192 0.796 0.036 0.169 0.497
0.5 300 0.007 0.993 0.000 0.007 1.058
I expected a larger β to keep the model closer to the reference. It didn't. Both runs ended up piling everything onto the chosen answer, and the answer that was never in the data got pushed to almost zero too. What β changed was how fast it got there and the scale of the loss number (0.172 vs 0.007).
The IPO paper (Azar et al., 2023) points out that when preferences always go one way, DPO can keep drifting away from the reference. The toy is the extreme version of that. Real data has many pairs pulling against each other, so it won't go this far, but the reading lessons carry over.
A lower loss is not a better model. Don't compare loss across runs with different β. Read the answers to your evaluation prompts.
Answers outside the data get pushed down too. If your pairs all come from one situation or one tone, everything else shrinks. Mix pairs from many situations.
When to use DPO instead of RLHF
The DPO paper reports beating PPO-based RLHF at controlling sentiment, and matching or beating it on summarization and single-turn dialogue. That is those three tasks, not "always better".
Situation Pick
You only need tone and format SFT
You have "this answer over that one" records DPO
You want to keep sampling and scoring with a reward model RLHF (PPO)
Zephyr-7B-β and Mixtral 8x7B Instruct are open models whose authors say they were tuned with DPO. If you are tuning an open model on your own data, DPO is usually the first thing to look at, and Hugging Face's TRL library ships a DPOTrainer, so getting started is easy.
Pair data is often closer than you think. Thumbs-up / thumbs-down on an answer screen, or support agents rewriting an AI draft (the rewrite is the chosen answer), are pairs as they stand.
If you want to tune a model's answers on your own data but are stuck on how to collect pairs, feel free to ask negabaro. We can look at what the logs you already have can do.
Key Concepts
Collect pairs: prompt + chosen answer + rejected answer
Freeze a reference: keep a frozen copy of the model from before training
DPO loss: chosen more likely than the reference, rejected less likely. First-step loss is 0.693
β changes speed and the loss scale. Don't compare loss across different β
Answers outside the data get pushed down too, so mix pairs from many situations
Done without a reward model or PPO. Evaluate by reading the answers
Pros
- ✓ No reward model to train, so the pipeline is short
- ✓ Two models during training (policy, reference) instead of PPO's four
- ✓ No sampling during training, so it is easier to run and more stable
- ✓ Matched or beat PPO-based RLHF on the paper's three tasks
Cons
- ✗ With one-sided preferences it can keep drifting from the reference (IPO paper)
- ✗ Even answers outside the data lose probability
- ✗ The loss number says little about quality (its scale depends on β)
- ✗ Collecting pair data costs effort