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

Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, Chelsea Finn · arXiv · 2023-5-29

- **Problem** Standard RLHF fits a reward model to human preference pairs and then runs reinforcement learning against it, a pipeline that is costly and often unstable.
- **Method** Reparameterizes the reward through the log-ratio of the policy to a reference model, so a binary cross-entropy loss on preference pairs trains the policy directly.
- **Results** Reached a GPT-4 win rate of 61% against reference summaries on TL;DR summarization at sampling temperature 0.0, versus 57% for PPO at its best temperature.

![Figure 1: DPO optimizes for human preferences while avoiding reinforcement learning. Existing methods for fine-tuning language models with human feedback first…](https://refivu.com/papers/b96eaaaa-8c14-4a06-93bf-d13e70a14b14/figures/figure-874b00bb9a49af224ba781c398997970.png?thumb=512)

**Figure 1** : DPO optimizes for human preferences while avoiding reinforcement learning. Existing methods for fine-tuning language models with human feedback first fit a reward model to a dataset of prompts and human preferences over pairs of responses, and then use RL to find a policy that maximizes the learned reward. In contrast, DPO directly optimizes for the policy best satisfying the preferences with a simple classification objective, fitting an implicit reward model whose corresponding optimal policy can be extracted in closed form.

[Original paper](https://arxiv.org/abs/2305.18290v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, Chelsea Finn · Direct Preference Optimization: Your Language Model is Secretly a Reward Model · Original paper figure · Extracted the figure area from page 2 of the original PDF.

## Why RLHF is costly to run

Standard RLHF first fits a reward model to pairs of human preferences, then optimizes the language model against that learned reward with reinforcement learning. The RL stage usually runs PPO with a KL penalty against the supervised starting model, which keeps the policy close to the region where the reward model is trusted. Figure 1 sets this two-stage pipeline beside DPO, which replaces both stages with one classification objective applied to the policy.

The pipeline trains several language models and samples from the policy during training, and the authors describe the result as complex and often unstable. DPO keeps the same goal, reward maximization with a KL-divergence constraint, but drops the separate reward model and the RL loop.

## Turning the reward into a function of the policy

The starting point is the KL-constrained reward maximization problem, where the policy is pushed toward high reward while a KL term against the reference policy is weighted by β. Its optimal solution has a closed form: the reference policy reweighted by the exponentiated reward, divided by a normalizer Z(x) that depends only on the prompt.

\\\[\\pi\_r(y\\mid x)=\\frac{1}{Z(x)}\\,\\pi\_{\\mathrm{ref}}(y\\mid x)\\exp\\!\\Big(\\tfrac{1}{\\beta}\\,r(x,y)\\Big)\\\] Taking logarithms and rearranging expresses the reward through the optimal policy and the reference policy, up to a term that depends only on the prompt. \\\[r(x,y)=\\beta\\log\\frac{\\pi\_r(y\\mid x)}{\\pi\_{\\mathrm{ref}}(y\\mid x)}+\\beta\\log Z(x)\\\]

The Bradley-Terry model depends only on the difference between the rewards of two completions for the same prompt, so the Z(x) term cancels. The preference probability then depends only on the optimal policy and the reference policy. \\\[p^\*(y\_1\\succ y\_2\\mid x)=\\frac{1}{1+\\exp\\!\\Big(\\beta\\log\\frac{\\pi^\*(y\_2\\mid x)}{\\pi\_{\\mathrm{ref}}(y\_2\\mid x)}-\\beta\\log\\frac{\\pi^\*(y\_1\\mid x)}{\\pi\_{\\mathrm{ref}}(y\_1\\mid x)}\\Big)}\\\]

A trainable policy π\_θ replaces the optimal policy, and maximum likelihood on the preference dataset gives a binary cross-entropy loss. \\\[L\_{\\mathrm{DPO}}(\\pi\_\\theta;\\pi\_{\\mathrm{ref}})=-\\mathbb{E}\_{(x,y\_w,y\_l)\\sim D}\\Big\[\\log\\sigma\\Big(\\beta\\log\\frac{\\pi\_\\theta(y\_w\\mid x)}{\\pi\_{\\mathrm{ref}}(y\_w\\mid x)}-\\beta\\log\\frac{\\pi\_\\theta(y\_l\\mid x)}{\\pi\_{\\mathrm{ref}}(y\_l\\mid x)}\\Big)\\Big\]\\\] The policy itself carries the reward: the implicit reward is β times the log-ratio of π\_θ to π\_ref, so no separate reward network is trained.

## What the gradient pushes on

The gradient of the loss raises the log-likelihood of the preferred completion and lowers the log-likelihood of the dispreferred one. \\\[\\nabla\_\\theta L\_{\\mathrm{DPO}}=-\\beta\\,\\mathbb{E}\\Big\[\\sigma\\big(\\hat r\_\\theta(x,y\_l)-\\hat r\_\\theta(x,y\_w)\\big)\\big(\\nabla\_\\theta\\log\\pi\_\\theta(y\_w\\mid x)-\\nabla\_\\theta\\log\\pi\_\\theta(y\_l\\mid x)\\big)\\Big\]\\\]

The sigmoid factor weights each example by how strongly the implicit reward ranks the dispreferred completion above the preferred one, so mis-ordered pairs get larger updates. The authors report that a naive version of the method without this weighting can make the language model degenerate, which they show in an appendix table.

## Running DPO on a preference dataset

Completions are sampled from the reference policy for each prompt, labeled with human preferences, and collected into an offline dataset. The language model is then optimized to minimize the DPO loss for the chosen reference policy and β. Public preference datasets can be reused in place of new sampling and labeling.

The reference policy is set to the SFT model whenever that model is available, because the preference data was sampled from it. Without an SFT model, the reference is obtained by maximizing the likelihood of the preferred completions, which reduces the mismatch between the true reference distribution and the one DPO uses. Implementation details and hyperparameters are in Appendix B.

## Why the reparameterization keeps every reward class

Two reward functions are equivalent when their difference depends only on the prompt x.

The Plackett-Luce family is under-specified, so identifiability constraints are usually needed before maximum likelihood estimates from the reward loss carry guarantees. The argument therefore selects one representative reward from each class rather than a unique reward.

Under mild assumptions, every reward class consistent with the Plackett-Luce models, and so with Bradley-Terry, can be written as β log π(y\|x)/π\_ref(y\|x) for some model π. The projection that achieves this subtracts a prompt-only term from the reward, so the projected reward stays in the same equivalence class. \\\[f(r;\\pi\_{\\mathrm{ref}},\\beta)(x,y)=r(x,y)-\\beta\\log\\sum\_y\\pi\_{\\mathrm{ref}}(y\\mid x)\\exp\\!\\Big(\\tfrac{1}{\\beta}r(x,y)\\Big)\\\]

The selected reward is the one for which the sum over completions of π\_ref(y\|x) exp((1/β) r(x,y)) equals 1, which makes the induced π a valid distribution. The key step is to constrain the under-determined preference family so that the optimal policy stays analytically tractable for every prompt while the set of representable rewards is unchanged.

## Why the PPO-style objective needs a normalizer

Viewing RL fine-tuning through control as inference, the objective maximizes expected reward minus a log-sum term over the reference policy, minus a KL term. \\\[\\max\_{\\pi\_\\theta}\\ \\mathbb{E}\_{\\pi\_\\theta(y\\mid x)}\\Big\[r\_\\phi(x,y)-\\beta\\log\\sum\_y\\pi\_{\\mathrm{ref}}(y\\mid x)\\exp\\!\\Big(\\tfrac{1}{\\beta}r\_\\phi(x,y)\\Big)-\\beta\\log\\frac{\\pi\_\\theta(y\\mid x)}{\\pi\_{\\mathrm{ref}}(y\\mid x)}\\Big\]\\\]

The log-sum term acts as a soft value function of the reference policy, and it does not change the optimal solution. Without it the policy gradient can have high variance, and a learned value function is hard to optimize, so prior work normalized rewards with a human completion baseline. The DPO reparameterization gives a reward that needs no baseline.

## Tasks, baselines and evaluation

In controlled sentiment generation, the prefix is a movie review from the IMDb dataset and the policy must generate positive text, with preference pairs labeled by a pre-trained sentiment classifier. The SFT model is GPT-2-large, fine-tuned until convergence on IMDb training reviews.

For summarization, the input is a Reddit forum post, the Reddit TL;DR dataset is used, and human preferences come from samples of a different but similarly trained SFT model. Single-turn dialogue uses the Anthropic Helpful and Harmless dataset of 170k dialogues, where no pre-trained SFT model exists, so an off-the-shelf model is fine-tuned on the preferred completions.

Sentiment is scored against the ground-truth classifier, while summarization and dialogue use GPT-4 win rates against a baseline, since the true reward is unknown. Baselines include zero-shot GPT-J for summarization, 2-shot Pythia-2.8B for dialogue, the SFT model, and Preferred-FT. Unlikelihood, PPO with a learned reward, PPO-GT, and Best of N, which samples N responses and returns the highest-scoring one, are also compared.

## Reward against KL in sentiment generation

Each method was run with a sweep of conservativeness settings: target KL in {3, 6, 9, 12} for PPO, β in {0.05, 0.1, 1, 5} for DPO, and α in {0.05, 0.1, 0.5, 1} for unlikelihood. The sweep covers 22 runs in total, and each policy was evaluated every 100 training steps until convergence.

DPO gives the highest expected reward at every KL value examined on the frontier. The authors describe DPO as producing by far the most efficient frontier, with the highest reward while keeping KL low.

DPO and PPO optimize the same objective, and the authors find DPO's reward and KL trade-off strictly better than PPO's. DPO also gives a better frontier than PPO even when PPO is given the ground-truth reward (PPO-GT).

## TL;DR summarization win rates

Samples were drawn at temperatures from 0.0 to 1.0 and judged by GPT-4 against the reference completions in the test split. DPO, PPO and Preferred-FT all fine-tune the same GPT-J SFT model.

DPO reached a win rate of about 61% at temperature 0.0, while PPO reached 57% at its optimal temperature of 0.0. DPO also reached a higher maximum win rate than the best of N baseline. The authors did not meaningfully tune DPO's β, so these numbers may understate what DPO can do.

Preferred-FT does not improve much over the SFT model.

In a human study, DPO samples at temperature 0.25 were preferred over PPO samples at temperature 0 in 58% of comparisons.

## Anthropic HH dialogue results

The base model is Pythia-2.8B, and Preferred-FT trains a reference model on the chosen completions so that DPO starts within the model's distribution. Win rates are judged by GPT-4 against the preferred completions in the test subset with one step of interaction.

DPO is compared with the best of 128 Preferred-FT completions and with a 2-shot prompted Pythia-2.8B model, and performs as well or better at each method's best-performing temperature. A PPO-trained model on the Anthropic HH dataset could not beat the base Pythia-2.8B model at any tried prompt or temperature. Because both methods optimize the same reward, the authors treat Best of 128 as a rough proxy for PPO-level performance.

DPO is the only computationally efficient method evaluated that improves over the preferred completions, and it is similar to or better than the computationally demanding Best of 128 baseline. DPO converges to its best performance relatively quickly.

The figure shows GPT-4 win rates across sampling temperatures on the left and win rates over fine-tuning steps on the right, where DPO is the only method reported to improve over the chosen responses.

## Shift to CNN/DailyMail news

The PPO and DPO summarization policies, trained on Reddit TL;DR, were evaluated on news articles from the CNN/DailyMail test split at temperatures 0 and 0.25. Win rates were computed against the ground-truth summaries with the GPT-4 (C) prompt, with the words forum post replaced by news article.

DPO does not use the unlabeled Reddit TL;DR prompts that PPO uses, so this is initial evidence of similar generalization, not a comparison of equal training data.

## Checking GPT-4 judgments against humans

Two GPT-4 prompts were used, the simple GPT-4 (S) prompt and the concise GPT-4 (C) prompt.

Only the DPO and PPO-1 comparisons received multiple human judgments because of limited human raters.

## Open questions and limits

The β hyperparameter was not meaningfully tuned in the summarization runs, so the reported DPO numbers may be conservative. The derivation assumes that human preferences follow the Bradley-Terry or Plackett-Luce model over latent rewards.

Models were evaluated only up to 6B parameters, and scaling DPO to much larger models is left to future work.

GPT-4 win rates depend on the wording of the prompt, and the authors note that future work should study how to elicit high-quality judgments. Reward over-optimization under DPO, including whether the slight drop in Figure 3 (right) is an instance of it, is an open question.

## Paper info

- **Authors**: Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, Chelsea Finn
- **Venue**: arXiv · Preprint
- **First published**: 2023-5-29
- **Added**: 2026-10-20
- **Updated**: 2024-7-29
- **Version**: v3
- **arXiv**: 2305.18290
- **Category**: cs.LG · cs.AI · cs.CL
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2305.18290v3) · [PDF ↗](https://arxiv.org/pdf/2305.18290v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

While large-scale unsupervised language models (LMs) learn broad world knowledge and some reasoning skills, achieving precise control of their behavior is difficult due to the completely unsupervised nature of their training. Existing methods for gaining such steerability collect human labels of the relative quality of model generations and fine-tune the unsupervised LM to align with these preferences, often with reinforcement learning from human feedback (RLHF). However, RLHF is a complex and often unstable procedure, first fitting a reward model that reflects the human preferences, and then fine-tuning the large unsupervised LM using reinforcement learning to maximize this estimated reward without drifting too far from the original model. In this paper we introduce a new parameterization of the reward model in RLHF that enables extraction of the corresponding optimal policy in closed form, allowing us to solve the standard RLHF problem with only a simple classification loss. The resulting algorithm, which we call Direct Preference Optimization (DPO), is stable, performant, and computationally lightweight, eliminating the need for sampling from the LM during fine-tuning or performing significant hyperparameter tuning. Our experiments show that DPO can fine-tune LMs to align with human preferences as well as or better than existing methods. Notably, fine-tuning with DPO exceeds PPO-based RLHF in ability to control sentiment of generations, and matches or improves response quality in summarization and single-turn dialogue while being substantially simpler to implement and train.

## Quote from the paper

Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, Chelsea Finn (2023). Direct Preference Optimization: Your Language Model is Secretly a Reward Model. arXiv:2305.18290v3. https://arxiv.org/abs/2305.18290v3

**BibTeX**

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

## Other paper commentary

- [Blending Neural Control Density Functions for Stabilization and Safety](https://refivu.com/en/papers/2b6e127e-d8b0-4e8d-b78b-426f1ca3ea83-blending-neural-control-density-functions-for-stabilization.md)
- [Enforcing Ellipsoidal Constraints in Neural Networks with a Polynomial Safety Layer](https://refivu.com/en/papers/8a56d4c9-6361-4734-9055-b7d7f681f127-enforcing-ellipsoidal-constraints-in-neural-networks-with-a.md)
- [Concrete Problems in AI Safety](https://refivu.com/en/papers/a0a18b13-f86b-4c61-807b-da6798f08495-concrete-problems-in-ai-safety.md)
- [WebGPT: Browser-assisted question-answering with human feedback](https://refivu.com/en/papers/b41258c0-ce1e-478c-ad2b-6bccd936ae34-webgpt-browser-assisted-question-answering-with-human.md)
- [Constitutional AI: Harmlessness from AI Feedback](https://refivu.com/en/papers/91e9437c-36ce-49cd-965c-18d9ca4664d6-constitutional-ai-harmlessness-from-ai-feedback.md)
- [GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding](https://refivu.com/en/papers/2481fdbe-b100-433d-877a-6976f982ccaa-gshard-scaling-giant-models-with-conditional-computation-and.md)
- [GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language Understanding](https://refivu.com/en/papers/a5e0caad-afbf-4fa4-b072-f6f5cab0c916-glue-a-multi-task-benchmark-and-analysis-platform.md)
- [Retentive Network: A Successor to Transformer for Large Language Models](https://refivu.com/en/papers/ca4ee5c6-87cf-427b-ae91-b593c10e0b48-retentive-network-a-successor-to-transformer-for-large.md)
- [Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks](https://refivu.com/en/papers/569bb9ab-8345-4766-a539-e7ffb7b1754e-retrieval-augmented-generation-for-knowledge-intensive-nlp.md)
- [Weight Normalization: A Simple Reparameterization to Accelerate Training of Deep Neural Networks](https://refivu.com/en/papers/c1050ccf-ffa6-4158-8fff-24b3a8223df6-weight-normalization-a-simple-reparameterization-to.md)
- [RWKV: Reinventing RNNs for the Transformer Era](https://refivu.com/en/papers/f86c302a-2e46-481a-b0a7-850579f6f3c8-rwkv-reinventing-rnns-for-the-transformer-era.md)
- [Spectral Normalization for Generative Adversarial Networks](https://refivu.com/en/papers/a69a23bf-3dd6-4b32-9fb1-444f7f67a6e8-spectral-normalization-for-generative-adversarial-networks.md)

## Terms in this paper

- [GPT-4](https://refivu.com/en/terms/1e2d0d2cdc44-gpt-4)
- [supervised fine-tuning](https://refivu.com/en/terms/1a2c1f079517-supervised-fine-tuning)
- [PPO](https://refivu.com/en/terms/21c34991d674-ppo)
- [Reward model](https://refivu.com/en/terms/76346da527c5-reward-model)
- [Direct Preference Optimization](https://refivu.com/en/terms/81ed2010f707-direct-preference-optimization)
- [win rate](https://refivu.com/en/terms/14de48f4526a-win-rate)
- [KL-divergence](https://refivu.com/en/terms/ec24ed6c4b84-kl-divergence)
- [summarization](https://refivu.com/en/terms/1e45700d5a1c-summarization)
- [Bradley-Terry model](https://refivu.com/en/terms/18d616a35daa-bradley-terry-model)
- [RLHF](https://refivu.com/en/terms/1e6d2905ced3-rlhf)
- [IMDB dataset](https://refivu.com/en/terms/2d33938220f9-imdb-dataset)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/b96eaaaa-8c14-4a06-93bf-d13e70a14b14-direct-preference-optimization-your-language-model-is)
