Preference Tuning: RLHF, PPO and DPO
Why SFT is not enough
Same base model, different behaviour. GPT-3 vs GPT-3.5 (ChatGPT): GPT-3.5 had more fine-tuning and human preference optimization. Paper -> InstructGPT.
Industry order: pre-training -> SFT -> preference tuning -> reasoning.
The Problem
- SFT data = question + one valid answer.
- No good answer vs bad answer. No way to say A is better than B.
- Both answers can be correct. A human still likes one more (e.g. calm, counsellor-like tone vs a blunt reply).
The Solution Preference tuning - tune the model on human preferences. Data = two answers A and B, plus which one the human picked.
Analogy: SFT is learning from a textbook with the right answer. Preference tuning is learning which way of writing the answer people like more.
SFT is not obsolete. Without a structured response from SFT, you cannot compare two responses. SFT first, then preference tuning.
Why negative examples matter
Example
Teaching a circle. Method A: draw 1000 perfect circles (SFT style). The learner may draw a near-circle oval and think it fits. Method B: show circle, oval, circle, rectangle, circle, hexagon (preference style). The boundary is clear.
- Positive examples -> what to do. Negative examples -> what not to do.
- Maximise the first, minimise the second.
- Learning with contrasting examples -> Contrastive learning.
SFT memorizes, RL generalizes
- SFT on task A improves task A but can hurt other tasks (financial model got worse at maths and science).
- SFT target: output should look like this data.
- RL target: score well. It shifts the model distribution towards task A without overwriting other tasks.
- Both coexist in training.
Reinforcement learning basics
Reinforcement learning - learn by trying, getting a reward, and adjusting. Like learning to ride a bicycle. Old field (robots, Go, Atari).
Objective: maximise the expected reward. A second part keeps updates small so the model does not drift far from where it started (safety).
Example
Dog fetching a ball. No loss function to optimise in a dog. Dog explores, moves toward the ball, gets a treat. Later picks up the ball and returns, gets another treat. Nobody gave rules. It discovered them through rewards.
| RL term | Dog training | LLM |
|---|---|---|
| Agent | Dog | Language model |
| Environment | Park | Chat window |
| State | Where the ball is | The prompt |
| Action | Run, catch, sit | Generate a response |
| Policy | Dog's brain / habits | Model weights |
| Reward | Treat | Score for the response |
| Episode | Throw, fetch, return | One prompt-response cycle |
Policy - strategy of choosing an action given a state. Optimising the policy = updating the weights = fine-tuning.
Example
Chess: state = piece positions, action = move, environment = board/game, episode = full game.
Reward and reward model
The Problem Robot picks a can: success or fail, +1 or -1. For LLMs both responses look right. We must define what is good.
The Solution
- Ask humans A or B every time (slow, expensive, but still done).
- Train a model to score like humans -> Reward model.
- Input: prompt + response.
- Output: a score.
- Trained on human preference pairs.
- Scoring uses the Bradley-Terry model, the same idea as Elo in chess: if A beats B and B beats C, A is better than C.
InstructGPT pipeline and PPO
Step 1: SFT. Step 2: collect preference data and train a reward model. Step 3: optimise with PPO (Proximal Policy Optimization).
Preference data
- Each row: prompt, chosen response, rejected response.
- Collected by hired annotators and user dashboards (A/B choice).
- Not about right vs wrong. About what a human prefers.
- Easy pair - clearly different (good explanation vs rambling).
- Hard pair - both good, tiny difference. Hard pairs push the model to learn finer separation.
Example
Prompt: explain a stock dividend. Response A: shareholders get extra shares instead of cash. Response B: same plus a concrete example (5% dividend, 100 shares -> 5 extra, total value unchanged). Human prefers B.
Reward model - the final layer changes from next-token probabilities to a score (e.g. 0.73 vs 0.9). Learns from chosen vs rejected.
PPO loop
- Give the SFT model a batch of prompts (e.g. 256).
- It generates responses.
- Reward model scores each.
- Update weights, with a limit on how far each update can move.
- Repeat thousands of times.
Online training - new data is generated during training (PPO). Offline training - a fixed dataset, nothing generated during training.
- Ratio - current policy vs old policy probability of the response.
- Advantage - how much better this response is than the average for that prompt.
- Clipping - ratio kept within 1-epsilon to 1+epsilon. With epsilon = 0.2, range 0.8 to 1.2, so no update changes the policy by more than ~20%.
- Proximal -> the clipping. PPO = policy gradient, but clipped.
Why PPO is hard for LLMs, and reward hacking
| Model | Role |
|---|---|
| Active (policy) | Being trained, updated every step |
| Reference | Frozen copy of the SFT model; keeps updates from drifting far |
| Reward | Scores responses |
| Value (critic) | Predicts reward to compute advantage |
All four sit in memory at once. Plus gradients and Adam optimizer states. Not feasible for most people. (7B parameters at 16-bit = 56 GB just for weights.)
Reward hacking - the model finds a shortcut to a high score without doing the real task.
- Always adding "I hope this helps" gave +0.3, so the model spammed it.
- Longer answers scored higher, so answers got long.
- Confident wrong answers scored well.
- A model searched the internet for the training dataset's answers and used them.
- When a measure becomes a target, it stops being a good measure.
DPO - Direct Preference Optimization
The Insight The preference dataset already says which response is better. So the reward is implicit. No reward model needed.
- Data: prompt, chosen, rejected.
- Models: policy (being trained) and reference (starting SFT model, frozen). Memory is about half of PPO.
- Offline: fixed dataset.
Per example DPO asks two things
- How much more does the policy like chosen over rejected?
- How much more does the reference like chosen over rejected?
- If the policy already prefers chosen like the reference does -> small update.
- If the policy prefers rejected -> big fix.
Loss compares how much more likely chosen vs rejected has become now, compared to the reference. Push chosen up, push rejected down.
Why contrasting beats imitation
- SFT sees only the chosen answer, so half the signal.
- DPO uses both. Rejected answers carry information too.
- A recent study trained a Qwen 8B model on wrong maths answers only and it improved.
DPO is sensitive and needs a much lower learning rate than SFT. It must learn very small differences.
| PPO | DPO | |
|---|---|---|
| Models in memory | 4 | 2 |
| Training | Online | Offline |
| Reward model | Needed | Not needed |
| Compute | High | Lower |
| Data | Preference pairs | Same preference pairs |
Practical run: DPO on SmolLM 135M Instruct with prompt/chosen/rejected data. PPO was not run because it does not fit on Colab. Next topic: reasoning with GRPO (Group Relative Policy Optimization).
Glossary
- Preference tuning
- Tuning a model on human choices between two responses.
- Policy
- Strategy for choosing an action given a state; for an LLM, the model weights.
- Reward model
- A model trained to score a prompt-response pair like a human would.
- PPO
- Proximal Policy Optimization; RL algorithm that updates the policy with clipped steps.
- DPO
- Direct Preference Optimization; trains on chosen vs rejected pairs with no reward model.
- Reward hacking
- Model exploits the reward signal without doing the real task.
- Contrastive learning
- Learning from contrasting good and bad examples.