Comparing RLHF with Reward Models against Direct Preference Optimization
Machine LearningModel answerLast updated
Analyze the architecture, loss functions, training complexity, and theoretical connections between traditional PPO-based RLHF and Direct Preference Optimization (DPO).
In modern alignment pipelines for large language models, adjusting model outputs to align with human preferences typically begins with a Supervised Fine-Tuned (SFT) base model. Two primary techniques exist for preference-based fine-tuning: two-stage Reward Model RLHF (such as PPO-based alignment) and single-stage direct optimization methods like Direct Preference Optimization (DPO).
Provide a comprehensive comparison between standard reward-model-based RLHF (PPO) and Direct Preference Optimization (DPO).
In your answer, make sure to address:
- Pipeline Architecture & Stages: Outline the workflow and required models for both approaches starting from a preference dataset $D = {(x, y_w, y_l)}$.
- Mathematical Formulation & Reference Policy: Write out the core optimization targets for both methods. Explain the explicit purpose of the reference policy $\pi_{ref}$ (and its associated KL divergence constraint) in both frameworks.
- Implicit Reward Mapping: Show how DPO analytically eliminates the need for an explicit reward model by expressing the implicit reward function in terms of policy probabilities.
- Trade-offs & Practical Considerations: Compare computational requirements, training stability, memory overhead (e.g., active model instances required in GPU memory), and failure modes such as length bias or reward hacking.
Hints
Hint 1
Recall the Bradley-Terry preference model, which expresses preference probabilities via the logistic sigmoid of reward differences: $P(y_w \succ y_l | x) = \sigma(r(x, y_w) - r(x, y_l))$.
Hint 2
Think about how the closed-form solution of the KL-constrained RL objective lets you rearrange the optimal policy formula $\pi^*(y|x) \propto \pi_{ref}(y|x) \exp(\frac{1}{\beta} r(x, y))$ to express $r(x, y)$ directly using policy ratios.
Hint 3
Count the total number of large language model instances that must be held in VRAM concurrently during a PPO training run versus a DPO training run.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Overview of Aligning LLMs via Preference Data
Aligning large language models (LLMs) with human intent uses pairwise preference data $D = {(x, y_w, y_l)}$, where $x$ is a prompt, $y_w$ is the preferred response ("winning"), and $y_l$ is the dispreferred response ("losing").
The conventional paradigm relies on Reinforcement Learning from Human Feedback (RLHF) using Proximal Policy Optimization (PPO), which first trains an explicit Reward Model (RM) and then uses RL to optimize the policy. Direct Preference Optimization (DPO) bypasses explicit reward modeling and RL entirely, optimizing the policy directly on preference pairs.
2. Pipeline Architecture & Training Stages
Reward-Model RLHF (PPO Pipeline)
The traditional RLHF pipeline consists of three distinct training phases:
- Supervised Fine-Tuning (SFT): Train a base model on high-quality instruction-response pairs to obtain policy $\pi_{SFT}$.
- Reward Model Training: Train a separate model $r_\psi(x, y)$ initialized from $\pi_{SFT}$ using a binary cross-entropy loss based on the Bradley-Terry preference model: $$\mathcal{L}{RM}(\psi) = -\mathbb{E}{(x, y_w, y_l) \sim D} \left[ \log \sigma \left( r_\psi(x, y_w) - r_\psi(x, y_l) \right) \right]$$
- Reinforcement Learning (PPO): Optimize the active policy $\pi_\theta$ using PPO against the fixed reward model $r_\psi$, constrained by a KL divergence penalty relative to the reference policy $\pi_{ref} = \pi_{SFT}$: $$\max_\theta \mathbb{E}{x \sim D, y \sim \pi\theta(\cdot|x)} \left[ r_\psi(x, y) - \beta D_{KL}\left(\pi_\theta(y|x) ,||, \pi_{ref}(y|x)\right) \right]$$
Direct Preference Optimization (DPO Pipeline)
DPO simplifies this to two stages by merging reward modeling and policy optimization into a single step:
- Supervised Fine-Tuning (SFT): Obtain $\pi_{SFT}$ identical to step 1 above.
- Direct Preference Tuning: Initialize both the active policy $\pi_\theta$ and frozen reference policy $\pi_{ref}$ from $\pi_{SFT}$. Train $\pi_\theta$ directly using the DPO loss: $$\mathcal{L}{DPO}(\theta) = -\mathbb{E}{(x, y_w, y_l) \sim D} \left[ \log \sigma \left( \beta \log \frac{\pi_\theta(y_w|x)}{\pi_{ref}(y_w|x)} - \beta \log \frac{\pi_\theta(y_l|x)}{\pi_{ref}(y_l|x)} \right) \right]$$
3. Mathematical Derivation: Implicit Reward Formulation
The key mathematical insight behind DPO (Rafailov et al., 2023) is that the optimal policy under the KL-constrained RL objective can be expressed analytically.
Start with the token-level KL-constrained reward maximization objective: $$\max_{\pi} \mathbb{E}{x \sim D} \left[ \mathbb{E}{y \sim \pi(y|x)} [r(x, y)] - \beta D_{KL}(\pi(y|x) ,||, \pi_{ref}(y|x)) \right]$$
Expanding the KL divergence term: $$= \max_{\pi} \mathbb{E}{x \sim D} \sum_y \pi(y|x) \left[ r(x, y) - \beta \log \frac{\pi(y|x)}{\pi{ref}(y|x)} \right]$$ $$= \min_{\pi} \mathbb{E}{x \sim D} \sum_y \pi(y|x) \left[ \beta \log \frac{\pi(y|x)}{\pi{ref}(y|x)} - r(x, y) \right]$$ $$= \min_{\pi} \mathbb{E}{x \sim D} \beta \sum_y \pi(y|x) \log \frac{\pi(y|x)}{\pi{ref}(y|x) \exp\left(\frac{1}{\beta} r(x,y)\right)}$$
Let $Z(x) = \sum_y \pi_{ref}(y|x) \exp\left(\frac{1}{\beta} r(x,y)\right)$ be the partition function. We rewrite the term inside the log: $$= \min_{\pi} \mathbb{E}{x \sim D} \beta \left[ D{KL}\left( \pi(y|x) ,,||,, \frac{\pi_{ref}(y|x) \exp\left(\frac{1}{\beta} r(x,y)\right)}{Z(x)} \right) - \log Z(x) \right]$$
Since $Z(x)$ does not depend on $\pi$, the KL divergence is minimized (equals zero) when: $$\pi^*(y|x) = \frac{\pi_{ref}(y|x) \exp\left(\frac{1}{\beta} r(x,y)\right)}{Z(x)}$$
Rearranging this optimal policy equation yields an exact expression for the reward function $r(x, y)$ in terms of the optimal policy $\pi^$ and reference policy $\pi_{ref}$: $$\frac{\pi^(y|x)}{\pi_{ref}(y|x)} = \frac{\exp\left(\frac{1}{\beta} r(x,y)\right)}{Z(x)}$$ $$\log \frac{\pi^(y|x)}{\pi_{ref}(y|x)} = \frac{1}{\beta} r(x,y) - \log Z(x)$$ $$r(x, y) = \beta \log \frac{\pi^(y|x)}{\pi_{ref}(y|x)} + \beta \log Z(x)$$
Substituting this implicit reward definition into the original Bradley-Terry preference model: $$P(y_w \succ y_l | x) = \sigma(r(x, y_w) - r(x, y_l))$$
Notice that the normalization constants $\beta \log Z(x)$ cancel out completely: $$r(x, y_w) - r(x, y_l) = \beta \log \frac{\pi_\theta(y_w|x)}{\pi_{ref}(y_w|x)} - \beta \log \frac{\pi_\theta(y_l|x)}{\pi_{ref}(y_l|x)}$$
Plugging this directly into the negative log-likelihood loss gives the DPO objective, avoiding the need to train or store an explicit reward model $r_\psi(x, y)$.
4. Role of the Reference Policy ($\pi_{ref}$) and $\beta$
In both paradigms:
- Prevents Mode Collapse & Drift: The reference policy $\pi_{ref}$ (frozen copy of $\pi_{SFT}$) keeps the trained model from drifting into degenerate output distributions where language fluency degrades.
- $\beta$ Hyperparameter: Acts as an implicit temperature control:
- Higher $\beta$: Enforces strong penalization for straying from $\pi_{ref}$, maintaining conservative updates.
- Lower $\beta$: Allows aggressive policy shifts to maximize preference alignment, increasing the risk of over-fitting or degraded language generation.
5. Systematic Comparison
| Dimension | Reward-Model RLHF (PPO) | Direct Preference Optimization (DPO) |
|---|---|---|
| Pipeline Complexity | 3-stage process (SFT $\rightarrow$ RM $\rightarrow$ PPO) | 2-stage process (SFT $\rightarrow$ DPO) |
| Concurrent Models in VRAM | Up to 4 models: Policy ($\pi_\theta$), Reference ($\pi_{ref}$), Reward Model ($r_\psi$), Value Function ($V_\phi$) | 2 models: Active Policy ($\pi_\theta$) and Frozen Reference ($\pi_{ref}$) |
| Data Requirements | Can perform online exploration (generating completions dynamically during training) | Offline preference dataset (static pairs) |
| Training Stability | Sensitive to hyperparameter choices (PPO clip ratio, GAE parameters, value loss scaling) | Highly stable, equivalent to supervised binary classification |
| Computational Cost | High GPU memory footprint and compute wall-clock time due to online sampling step | Considerably lower GPU requirements; fast iteration times |
6. Practical Trade-offs and Failure Modes
-
Memory Footprint & Compute: PPO requires generating generations online during training, evaluating them against the reward and value models, and updating policy parameters via dynamic PPO steps. DPO treats preference pairs as fixed sequences, requiring only standard forward/backward passes on pre-existing tokens.
-
Likelihood Displacement & Length Bias in DPO: Because DPO scales gradients inversely with how high the probability of $y_w$ already is, it can suffer from likelihood displacement where the overall log-likelihood of valid text drops. Additionally, DPO is prone to severe length bias (preferring longer responses simply because total log-likelihood sums across tokens), often requiring explicit length-normalization modifications in practice.
-
Distribution Shift & Online vs. Offline Optimization:
- PPO explores out-of-distribution generations during training because $y \sim \pi_\theta(\cdot|x)$ is sampled live. This makes PPO more resilient when deployed in production settings where users prompt the model out-of-distribution.
- DPO operates offline on fixed datasets. If $\pi_\theta$ shifts significantly away from $\pi_{SFT}$, the log-ratio implicit reward can yield over-confident or corrupted policy behavior for unobserved completion paths. (Frameworks like Iterative DPO/Online DPO address this by periodically re-sampling preference pairs).