# Direct Preference Optimization: Your Language Model is Secretly a Reward Model

> Shows the RLHF objective can be optimized directly on preference pairs with a single log-sigmoid loss. No reward model, no PPO sampling, and it matches or beats PPO on sentiment control, summarization and dialogue.

- arXiv: https://arxiv.org/abs/2305.18290
- Authors: Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, Chelsea Finn
- Published: 2023-05-29
- Topic: Alignment
- Visual carousel: https://instaxiv.com/p/2305.18290
- Explanation by InstaXiv, a secondary educational summary. Cite the original paper for exact results. InstaXiv is not affiliated with or endorsed by arXiv or Cornell University.

## Skip the reward model and RL. Align language models with one loss.

**61%** TL;DR win rate, against 57% for PPO

## RLHF works, but the pipeline is fragile

**RLHF with PPO:** Fit a reward model on preference pairs, then run PPO against it while sampling from the policy. Four models in memory, unstable training, heavy tuning.

**DPO:** A change of variables shows the optimal policy defines its own reward. Train directly on preference pairs with a classification-style loss. No sampling, no reward model.

Your language model is secretly a reward model.

## The whole method is one log-sigmoid loss

$$
\mathcal{L}_{\mathrm{DPO}} = -\,\mathbb{E}\left[\log \sigma\!\left(\beta \log \frac{\pi_\theta(y_w\mid x)}{\amber{\pi_{\mathrm{ref}}}(y_w\mid x)} - \beta \log \frac{\pi_\theta(y_l\mid x)}{\amber{\pi_{\mathrm{ref}}}(y_l\mid x)}\right)\right]
$$

Raise the likelihood of the preferred answer and lower the rejected one, both measured against a frozen reference so the policy cannot drift far.

- $y_w$: Preferred, winning completion
- $y_l$: Rejected, losing completion
- $\pi_{\mathrm{ref}}$: Frozen SFT model that anchors the policy
- $\beta$: Strength of the implicit KL penalty

## From preference pairs to an aligned model

1. **Start from an SFT model**: Fine-tune on demonstrations first; a frozen copy becomes the reference $\pi_{\mathrm{ref}}$.
2. **Collect preference pairs**: For each prompt, one chosen and one rejected completion. Existing RLHF datasets work as they are.
3. **Minimize the DPO loss**: Ordinary supervised training. The gradient upweights pairs the implicit reward currently ranks wrongly.

## Better reward per unit of KL, and higher win rates

![Figure 2](https://cdn.instaxiv.com/figures/2305.18290/figure2.webp)

Left: on IMDb sentiment, DPO traces the best reward-versus-KL frontier. Right: on TL;DR summarization, DPO beats PPO across sampling temperatures and degrades far less as temperature rises. (Figure 2)

## Open questions the paper flags itself

- **Out-of-distribution behavior**: How DPO policies generalize beyond the preference data, compared with policies trained on an explicit reward, was untested.
- **Reward over-optimization**: Whether DPO over-fits its implicit reward the way PPO over-fits a learned one remained open.
- **Tested up to 6B parameters**: Experiments stopped at 6B; behavior on frontier-scale models was left for future work.

Best used when: You have offline preference pairs and want alignment without running an RL loop.

## Key takeaways

- The KL-regularized RLHF objective has a closed-form optimum, so a classification loss can replace RL.
- Two models in memory instead of four: the policy and a frozen reference.
- DPO and its variants became a standard recipe for aligning open-weight chat models.

## Links

- arXiv: https://arxiv.org/abs/2305.18290
- PDF: https://arxiv.org/pdf/2305.18290
- Code: https://github.com/eric-mitchell/direct-preference-optimization

## Citation

```bibtex
@article{rafailov2023direct,
  title   = {Direct Preference Optimization: Your Language Model is Secretly a Reward Model},
  author  = {Rafailov, Rafael and Sharma, Archit and Mitchell, Eric and Ermon, Stefano and Manning, Christopher D. and Finn, Chelsea},
  journal = {arXiv preprint arXiv:2305.18290},
  year    = {2023},
  url     = {https://arxiv.org/abs/2305.18290}
}
```
