---
title: "DPO Explained: Direct Preference Optimization for LLMs"
description: "DPO trains an LLM on chosen-vs-rejected answer pairs with one classification loss, with no reward model and no RL loop. How it works, results, and TRL code."
url: https://launchkudos.com/news/llm-fine-tuning-dpo
section: AI
author: "Arnab Gupta"
published: 2026-12-05T02:20:43.163Z
updated: 2026-12-05T02:20:43.163Z
tags: [llm-fine-tuning, dpo, alignment, preference-optimization, rlhf]
---

# DPO Explained: Direct Preference Optimization for LLMs

*DPO trains an LLM on chosen-vs-rejected answer pairs with one classification loss, with no reward model and no RL loop. How it works, results, and TRL code.*

*Part 13 of 15 in [LLM fine-tuning techniques](https://launchkudos.com/news/llm-fine-tuning-techniques)*

Direct Preference Optimization (DPO) aligns a language model with human preferences by training it directly on pairs of answers, one preferred and one rejected. Stanford researchers introduced it in May 2023 as a way to get the result of RLHF with "only a simple classification loss" and no reinforcement learning loop ([arXiv](https://arxiv.org/abs/2305.18290)).

- ~61% · TL;DR summarization win rate vs reference summaries (PPO: 57%) · DPO paper, Sec. 6.2
- 58% · Human raters preferred DPO summaries over PPO's · DPO paper, Sec. 6.4, Table 2
- 0 · Separate reward models trained · DPO paper, Sec. 4
## What is DPO?

DPO is a preference fine-tuning method that skips the two hardest parts of RLHF: training a separate reward model and running reinforcement learning. The paper's authors call it "a simple RL-free algorithm for training language models from preferences", optimized "using a simple binary cross entropy objective" on preference pairs ([Rafailov et al., 2023](https://arxiv.org/abs/2305.18290)).

The input is a dataset of prompts, each with a **chosen** (preferred) and a **rejected** answer. The output is the same model, now more likely to produce answers like the chosen ones. The title's claim, "Your Language Model is Secretly a Reward Model", refers to the fact that the trained model itself defines a reward, so no second model is needed.

## How does DPO work?

DPO rewrites the RLHF objective so it can be solved with a single loss on the language model. RLHF maximizes a reward while a KL penalty keeps the model close to a reference model. The paper shows the best policy for that objective has a closed form, so the reward can be expressed through the policy itself ([DPO paper, Sec. 4](https://arxiv.org/abs/2305.18290)).

![Diagram comparing the RLHF pipeline (preference pairs, reward model, PPO sampling loop, policy) with DPO (preference pairs, one classification loss against a frozen reference model, policy), with the DPO loss from Equation 7](https://launchkudos.com/media/6ab2bb7c8f6f8efac16e.webp)

In plain terms, the steps are:

1. **Start from a reference model**, usually the supervised fine-tuned (SFT) model. It stays frozen.
2. **For each preference pair**, measure how much more likely the model being trained makes the chosen answer than the reference does, and the same for the rejected answer.
3. **Push the gap up**: raise the chosen answer's relative likelihood and lower the rejected one's. The loss is the logistic (sigmoid) loss on that difference, scaled by a coefficient **β** (Equation 7 in the paper).

The paper's gradient analysis (Sec. 4) shows each example is weighted by how wrongly the model's implicit reward currently orders the pair. The authors report that "a naïve version of this method without the weighting coefficient can cause the language model to degenerate" (Appendix Table 3). β "controls the strength of the KL penalty"; the paper's default was **β = 0.1**, with **0.5** for TL;DR summarization (Appendix B).

Because the loss only needs the policy's and the reference model's log-probabilities on fixed answers, DPO eliminates "the need for sampling from the LM during fine-tuning", according to the abstract.

### Worked example: the DPO loss for one pair

Here is Equation 7 computed by hand for a single preference pair. The log-probabilities are made-up illustrative values; the arithmetic is ours.

| Quantity | Chosen answer y_w | Rejected answer y_l |
|---|---|---|
| log-prob under the model being trained | −12.0 | −15.0 |
| log-prob under the frozen reference | −14.0 | −14.0 |
| Log ratio (trained − reference) | **+2.0** | **−1.0** |

1. **Margin.** With β = 0.1: 0.1 × (2.0 − (−1.0)) = **0.3**. This is the gap between the two implicit rewards.
2. **Loss.** −log σ(0.3) = log(1 + e^−0.3) ≈ **0.554**.
3. **Starting point.** At step 0 the trained model equals the reference, both log ratios are 0, the margin is 0 and the loss is log 2 ≈ **0.693**. Training pushes the loss below that by widening the margin.
4. **Example weight.** The paper's gradient weights this pair by σ(−margin) = σ(−0.3) ≈ **0.43**. A pair the model already orders strongly gets a weight near 0; a pair it orders wrongly gets a weight near 1.

TRL logs the same quantities during training as `rewards/chosen`, `rewards/rejected` and `rewards/margins` (β times the log ratios), plus `rewards/accuracies`, the share of pairs where the chosen answer's implicit reward is higher ([TRL docs](https://huggingface.co/docs/trl/dpo_trainer)).

## When was DPO introduced, and by whom?

DPO was introduced in "Direct Preference Optimization: Your Language Model is Secretly a Reward Model" by Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning and Chelsea Finn of Stanford University (Ermon also CZ Biohub). It was posted to arXiv on May 29, 2023 and appeared at NeurIPS 2023 ([arXiv 2305.18290](https://arxiv.org/abs/2305.18290)).

The paper lists the first three authors as equal contributors. The latest arXiv version, v3, is dated July 29, 2024.

## What results did the DPO paper report?

The paper tested DPO on three tasks with models up to 6 billion parameters and found it matched or beat PPO-based RLHF. On TL;DR summarization, DPO reached about a 61% win rate against reference summaries versus 57% for PPO, judged by GPT-4 ([DPO paper, Sec. 6.2](https://arxiv.org/abs/2305.18290)).

| Task (model) | Result reported | Where |
|---|---|---|
| IMDb sentiment (GPT-2-large) | DPO's reward/KL trade-off "strictly dominates PPO", including PPO with ground-truth rewards | Sec. 6.1, Fig. 2 |
| Reddit TL;DR summarization (GPT-J 6B SFT) | ~61% win rate at temperature 0 vs 57% for PPO at its best temperature | Sec. 6.2, Fig. 2 |
| Human study, TL;DR | DPO (temp. 0.25) preferred over PPO (temp. 0) 58% of the time | Sec. 6.4, Table 2 |
| CNN/DailyMail, out of distribution | Win rate vs ground truth 0.36 (DPO) vs 0.26 (PPO) at temp. 0 | Sec. 6.3, Table 1 |
| Anthropic HH dialogue (Pythia-2.8B) | "the only computationally efficient method that improves over the preferred completions" | Sec. 6.2, Fig. 3 |

The authors list limits themselves (Sec. 7): they evaluated models only "up to 6B parameters", and they found GPT-4 win rates "are impacted by the prompt". They also note they "did not meaningfully tune DPO's β", so the results "may underestimate DPO's potential" (Sec. 6.2).

## How is DPO different from RLHF, GRPO and RLVR?

DPO learns offline from a fixed set of preference pairs; [RLHF](https://launchkudos.com/news/llm-fine-tuning-rlhf) with PPO trains a reward model, then samples new answers from the model and scores them during training. The DPO paper describes the RLHF pipeline as "involving training multiple LMs and sampling from the LM policy in the loop of training" ([DPO paper, Sec. 1](https://arxiv.org/abs/2305.18290)).

| | DPO | RLHF (PPO) | GRPO | RLVR |
|---|---|---|---|---|
| Training signal | Chosen/rejected pairs | Learned reward model | Reward model or function | Verifier: correct or not |
| Samples from model during training | No | Yes | Yes | Yes |
| Extra trained models | None (frozen reference) | Reward model + value model | Reward model optional, no value model | None for the reward |

Later papers compared the two in practice. The Tülu 3 report used a length-normalized DPO variant for preference tuning and found PPO reached "a comparable level of performance to DPO (albeit slightly lower)". It reported PPO took roughly 28 hours on two nodes versus about 4 hours on one node for DPO ([Tülu 3, Sec. 5.4.1](https://arxiv.org/abs/2411.15124)).

DeepSeekMath's authors classify DPO as an offline method, because its training data comes from the initial SFT model, while [GRPO](https://launchkudos.com/news/llm-fine-tuning-grpo) samples from the model being trained ([DeepSeekMath, Sec. 5.2.1](https://arxiv.org/abs/2402.03300)). [RLAIF](https://launchkudos.com/news/llm-fine-tuning-rlaif) concerns where preference labels come from (an AI model), which can feed either DPO or RLHF. [RLVR](https://launchkudos.com/news/llm-fine-tuning-rlvr) replaces preferences with a checker for tasks that have verifiable answers.

## Which libraries support DPO?

Hugging Face TRL implements DPO as `DPOTrainer` with a `DPOConfig`, citing the original paper ([TRL docs](https://huggingface.co/docs/trl/dpo_trainer)). It accepts standard and conversational preference datasets with `prompt`, `chosen` and `rejected` fields, and supports PEFT adapters such as LoRA through a `peft_config` argument.

TRL's `loss_type` option also covers later variants, including `"ipo"`, `"hinge"`, `"robust"` and `"sigmoid_norm"` (the default is `"sigmoid"`, the original DPO loss). Ai2's [Open Instruct](https://allenai.github.io/open-instruct/) research codebase, used for Tülu 3, includes DPO training as well. For low-memory training, DPO can be combined with [LoRA](https://launchkudos.com/news/llm-fine-tuning-lora) or [QLoRA](https://launchkudos.com/news/llm-fine-tuning-qlora) adapters.

## How do you use DPO in code?

With TRL, you pass a model name, a preference dataset and a `DPOConfig` to `DPOTrainer`, then call `train()`. The example below follows TRL's documented quick start; `beta` defaults to 0.1, the same value the DPO paper used by default ([TRL DPO Trainer docs](https://huggingface.co/docs/trl/dpo_trainer), v1.19.0).

```python
from datasets import load_dataset
from trl import DPOConfig, DPOTrainer

# Each row has "prompt", "chosen" and "rejected"
dataset = load_dataset("trl-lib/ultrafeedback_binarized", split="train")

training_args = DPOConfig(output_dir="Qwen3-0.6B-DPO", beta=0.1)

trainer = DPOTrainer(
    model="Qwen/Qwen3-0.6B",
    args=training_args,
    train_dataset=dataset,
)
trainer.train()
```

If no `ref_model` is passed, TRL uses the model's state before training as the reference, per the `DPOTrainer` API docs. To train a LoRA adapter instead of all weights, add `peft_config=LoraConfig()` from the `peft` package.

## Common pitfalls with DPO

- **Reference model that doesn't match the data.** Preference datasets are usually sampled from some SFT model. When that model is not available, the paper first fine-tunes on the chosen answers to build the reference, which "helps mitigate the distribution shift" ([DPO paper, Sec. 4](https://arxiv.org/abs/2305.18290)).
- **Chosen answers can get less likely too.** TRL's docs note that the margin is "typically achieved by suppressing the likelihood of dispreferred completions rather than by increasing the likelihood of preferred ones" ([TRL docs](https://huggingface.co/docs/trl/dpo_trainer)). Watch `logps/chosen` alongside the margin.
- **Length bias.** Tülu 3 chose length-normalized DPO, which divides each log ratio by answer length, to help with "the length bias common in human and model preferences" ([Tülu 3, Sec. 5](https://arxiv.org/abs/2411.15124)). TRL exposes length normalization as `loss_type="sigmoid_norm"`.
- **Dropping the per-example weighting.** The paper reports that a naive objective without the weighting term "can cause the language model to degenerate" (Sec. 4, Appendix Table 3).
- **Judging with a single LLM prompt.** The authors found GPT-4 win rates changed with the judging prompt and that GPT-4 preferred "longer, more repetitive summaries than humans do" with their simple prompt (Sec. 6.4).
- **Truncating image tokens.** For vision-language models, TRL recommends `max_length=None` in `DPOConfig` so truncation does not remove image tokens.

> **> We read the full DPO paper (arXiv 2305.18290v3, PDF) and the arXiv abstract page on December 4, 2026, and took every number from its Sections 4–7, Tables 1–2 and Appendix B. Comparisons with PPO in practice come from the Tülu 3 report (arXiv 2411.15124v5, Sec. 5.4.1) and DeepSeekMath (arXiv 2402.03300v3, Sec. 5.2.1), also read in full that day. Class and argument names were checked against the TRL DPO Trainer documentation (v1.19.0) the same day.**

## FAQ

### Does DPO need a reward model?
No. DPO trains the language model directly on preference pairs. The paper shows the model itself defines an "implicit reward", the β-scaled log ratio of its probability to the reference model's, so no separate reward model is trained.

### Is DPO reinforcement learning?
The authors describe DPO as "RL-free": it optimizes the same KL-constrained objective as RLHF but with a classification loss, and it does not sample from the model during training.

### What data does DPO need?
A preference dataset: for each prompt, a chosen answer and a rejected answer. TRL accepts this as `prompt`, `chosen` and `rejected` fields, in plain-text or chat format.

### What does beta do in DPO?
β sets how strongly the model is held close to the reference model. The paper used β = 0.1 by default and 0.5 for summarization. TRL's `DPOConfig` also defaults `beta` to 0.1.

### Is DPO better than PPO?
In the DPO paper, DPO matched or beat PPO on sentiment, summarization and dialogue tasks with models up to 6B parameters. In Tülu 3, PPO scored comparably but slightly lower than DPO, and its run took roughly 28 hours on two nodes against about 4 hours on one node for DPO.

### Can you use DPO with LoRA?
Yes. TRL's `DPOTrainer` takes a `peft_config` such as `LoraConfig()` and then trains only the adapter. TRL's docs say adapters typically use a higher learning rate (about 1e-5) than full fine-tuning.

### What is a reference model in DPO?
A frozen copy of the starting model, usually the SFT model. DPO measures each answer's likelihood relative to it. TRL creates it automatically from the initial model if you do not pass one.

## Related techniques

- [RLHF](https://launchkudos.com/news/llm-fine-tuning-rlhf): reward model plus PPO, the pipeline DPO simplifies
- [RLAIF](https://launchkudos.com/news/llm-fine-tuning-rlaif): preference labels from an AI model instead of people
- [GRPO](https://launchkudos.com/news/llm-fine-tuning-grpo): online RL without a value model, from DeepSeek
- [RLVR](https://launchkudos.com/news/llm-fine-tuning-rlvr): RL with a verifier instead of a reward model
- [Distillation, LoRA and GRPO explained](https://launchkudos.com/news/distillation-lora-grpo-explained): how small models learn one job
- [All 15 LLM fine-tuning techniques](https://launchkudos.com/news/llm-fine-tuning-techniques)

## Sources

1. Rafailov, R., Sharma, A., Mitchell, E., Ermon, S., Manning, C. D., Finn, C. "[Direct Preference Optimization: Your Language Model is Secretly a Reward Model](https://arxiv.org/abs/2305.18290)." NeurIPS 2023. arXiv 2305.18290, May 29, 2023 (v3 July 29, 2024). Read Dec. 4, 2026.
2. Hugging Face. "[DPO Trainer](https://huggingface.co/docs/trl/dpo_trainer)." TRL documentation, v1.19.0. Read Dec. 4, 2026.
3. Ai2. "[Open Instruct documentation](https://allenai.github.io/open-instruct/)." Read Dec. 4, 2026.
4. Lambert, N., et al. "[Tülu 3: Pushing Frontiers in Open Language Model Post-Training](https://arxiv.org/abs/2411.15124)." arXiv 2411.15124, Nov. 22, 2024 (v5 Apr. 14, 2025). Read Dec. 4, 2026.
5. Shao, Z., et al. "[DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models](https://arxiv.org/abs/2402.03300)." arXiv 2402.03300, Feb. 5, 2024 (v3 Apr. 27, 2024). Read Dec. 4, 2026.

**Series:** [← Prev: RLAIF](https://launchkudos.com/news/llm-fine-tuning-rlaif) · [All 15 techniques](https://launchkudos.com/news/llm-fine-tuning-techniques) · [Next: GRPO →](https://launchkudos.com/news/llm-fine-tuning-grpo)
