How does Direct Preference Optimization (DPO) differ from RLHF?
Intermediate · 2 min read · Fine-Tuning & Adaptation
Open in study mode to save this question and track progressShort answer: Reinforcement Learning from Human Feedback (RLHF) trains a separate reward model on pairwise preferences and uses PPO to optimize the policy model; Direct Preference Optimization (DPO) mathematically reparameterizes the reward function, directly optimizing policy model weights on preference pairs using a binary cross-entropy loss without training a separate reward model or running complex PPO reinforcement learning.
Detail
Aligning LLMs with human preferences (Helpful, Harmless, Honest) traditionally required standard RLHF (e.g. InstructGPT):
Traditional RLHF Pipeline
- SFT (Supervised Fine-Tuning): Train baseline policy .
- Reward Model Training: Train reward model on preferred () vs dispreferred () completions.
- PPO Optimization: Optimize policy using PPO against with a KL divergence penalty to avoid drifting from .
DPO Simplification
DPO proves that the optimal policy solution can be expressed directly as a function of the log ratio of policy probabilities:
Where:
- is the winning (preferred) response, is the losing (dispreferred) response.
- is the policy model being trained; is the frozen reference SFT model.
- is a hyperparameter scaling KL divergence penalty.
| Feature | RLHF (PPO) | DPO |
|---|---|---|
| Reward Model Required | Yes (Separate model in VRAM) | No |
| Training Stability | Unstable (Sensitive to PPO hyperparameters) | Extremely Stable (Supervised cross-entropy loss) |
| GPU Memory Footprint | Very High (Policy, Reference, Reward, Critic) | Moderate (Policy + Reference) |
Example
PyTorch implementation of DPO loss function:
import torch
import torch.nn.functional as F
def dpo_loss(policy_win_logps, policy_lose_logps, ref_win_logps, ref_lose_logps, beta=0.1):
policy_logratios = policy_win_logps - policy_lose_logps
ref_logratios = ref_win_logps - ref_lose_logps
logits = policy_logratios - ref_logratios
losses = -F.logsigmoid(beta * logits)
return losses.mean()Interview tips
- Highlight that DPO eliminated PPO instability, making preference alignment dramatically easier and accessible on smaller GPU clusters.
- Mention variations like KTO (Kahneman-Tversky Optimization) and ORPO (Odds Ratio Preference Optimization).