DEV Community

Cover image for DPO vs RLHF explained: the same objective, without the reward model (and when PPO still wins)
M.T.Ramkrushna
M.T.Ramkrushna

Posted on

DPO vs RLHF explained: the same objective, without the reward model (and when PPO still wins)

Tuesday Weekly AI Post. This week: DPO vs RLHF, the two main ways to teach a model "this answer is better than that one" after supervised fine-tuning. I want to cover what each pipeline actually trains, the one equation that makes DPO work, the code, and the part the "DPO replaced RLHF" posts leave out.

Short version: DPO doesn't skip the reward model by being a different objective. It optimizes the same objective as RLHF, it just hides the reward model inside the policy. That's where both its simplicity and its limits come from.

Why preference tuning exists at all

Supervised fine-tuning (SFT) teaches a model to imitate demonstrations. But a lot of what we want is easier to judge than to write: which of two summaries is better, which answer is more helpful, which refusal is appropriate. Preference tuning trains on those comparisons.

The classic evidence it matters is InstructGPT (Ouyang et al., 2022). On OpenAI's API prompt distribution, human labelers preferred outputs from the 1.3B InstructGPT model over the 175B GPT-3, a model with over 100× more parameters, with the same architecture. The difference was fine-tuning on human data.

RLHF: three stages, four models

The InstructGPT recipe has three steps:

  1. SFT: labelers write demonstrations; fine-tune the pretrained model on them.
  2. Reward model (RM): labelers rank model outputs (they were shown between K = 4 and K = 9 responses per prompt), and a model learns to output a scalar reward predicting the human-preferred output. The paper used 6B reward models, noting 175B RM training could be unstable.
  3. RL with PPO: sample responses, score them with the RM, and update the policy. A per-token KL penalty against the SFT model keeps the policy from over-optimizing the reward model.

The objective behind step 3 is the one everything else in this post is about:

maximize   E[ r(x, y) ]  -  β · KL( π(y|x) || π_ref(y|x) )
Enter fullscreen mode Exit fullscreen mode

Get high reward, but don't drift far from the reference model (the SFT model), because the reward model is only accurate near the data it was trained on. β controls how strongly you're held back.

Count the models (my reading of the InstructGPT setup): during PPO you have the policy being trained, the frozen SFT model for the KL term, the reward model, and a value function (initialized from the RM). That's four large networks, plus online sampling from the policy inside the training loop. This is why RLHF has a reputation for being expensive and finicky.

The paper also documents an "alignment tax": RLHF caused regressions on some public benchmarks (SQuAD, DROP, HellaSwag, WMT 2015 French→English). Mixing pretraining gradients into PPO (their "PPO-ptx" variant) greatly reduced it.

DPO: the same objective, solved as a classification loss

DPO (Rafailov et al., 2023, "Your Language Model is Secretly a Reward Model") starts from that exact KL-constrained objective. The key observation: it has a known closed-form optimal policy. Rearrange it and you can express the reward in terms of the policy itself:

r(x, y) = β · log( π(y|x) / π_ref(y|x) )  +  (a term that depends only on x)
Enter fullscreen mode Exit fullscreen mode

Human preferences are usually modeled with Bradley-Terry, which only depends on the difference in reward between two answers to the same prompt. So that awkward x-only term cancels, and you get a loss on preference pairs (prompt, chosen, rejected) that needs no reward model and no sampling:

L_DPO = -log σ( β · [ log π(y_w|x)/π_ref(y_w|x)  -  log π(y_l|x)/π_ref(y_l|x) ] )
Enter fullscreen mode Exit fullscreen mode

In words: raise the chosen answer's likelihood (relative to the reference model) more than the rejected answer's. It's a binary cross-entropy loss. You need two models: the policy being trained and a frozen reference, usually the SFT model.

What the paper reports:

  • DPO is "stable, performant, and computationally lightweight", with no sampling from the LM during fine-tuning and no significant hyperparameter tuning.
  • Sentiment control (IMDb): DPO gave the best reward-vs-KL frontier, beating PPO, the core metric for this objective.
  • TL;DR summarization (GPT-J SFT base, GPT-4 as judge): DPO hit about 61% win rate vs reference summaries at temperature 0, versus 57% for PPO at its best temperature. DPO was also far more robust to sampling temperature.
  • In a human head-to-head, DPO samples were preferred 58% of the time over PPO's.
  • Single-turn dialogue (Anthropic HH, Pythia-2.8B): DPO matched or beat the baselines, and was the only computationally efficient method in their study that improved over the dataset's preferred completions.

And a detail I like: the authors say they "did not meaningfully tune DPO's β", so those numbers may underestimate it.

The implicit reward

Because the policy is the reward model, you can read rewards straight off it: β · log(π/π_ref) for each answer. Hugging Face TRL logs exactly this during training as rewards/chosen, rewards/rejected, rewards/margins and rewards/accuracies (the share of pairs where chosen beats rejected). Those are the first curves I'd watch.

What it looks like in code

TRL's DPOTrainer expects a preference dataset. The recommended format has an explicit prompt:

{"prompt": "The sky is", "chosen": " blue.", "rejected": " green."}
Enter fullscreen mode Exit fullscreen mode

(Conversational message lists work too; the trainer applies the chat template.) A minimal run with a LoRA adapter, adapted from the TRL docs:

from datasets import load_dataset
from peft import LoraConfig
from trl import DPOConfig, DPOTrainer

dataset = load_dataset("trl-lib/ultrafeedback_binarized", split="train")

args = DPOConfig(
    output_dir="dpo-out",
    beta=0.1,            # TRL default; higher = stay closer to the reference
    loss_type="sigmoid", # TRL default: the original DPO loss
)

trainer = DPOTrainer(
    model="Qwen/Qwen3-0.6B",   # start from your SFT model in practice
    args=args,
    train_dataset=dataset,
    peft_config=LoraConfig(),  # train an adapter instead of the full model
)
trainer.train()
Enter fullscreen mode Exit fullscreen mode

Two things worth knowing from the docs:

  • If you don't pass ref_model, TRL uses the model's state before DPO training starts as the reference.
  • DPOConfig sets its own learning_rate default of 1e-6 (vs 5e-5 in TrainingArguments). The docs note adapters typically use a higher rate (around 1e-5).

loss_type also covers the variants that grew out of DPO, including "ipo" (IPO, aimed at the logit transform overfitting) and "sigmoid_norm" (SimPO-style length normalization against length bias).

The part the hype skips: DPO can be worse than a well-tuned PPO

"Is DPO Superior to PPO for LLM Alignment?" (Xu et al., 2024) pushed back hard:

  • Theory: DPO can find biased solutions that favor out-of-distribution responses, answers that weren't in the preference data. Avoiding an explicit reward model doesn't avoid reward misspecification; it shows up differently.
  • Distribution shift matters a lot. Starting DPO from an SFT model trained on a different dataset (Alpaca) than the preference data (SafeRLHF) gave only a 55.4% safety rate. Extra SFT on in-distribution data, filtering noisy pairs, and iterative DPO (generate fresh responses, label them, retrain) all helped.
  • PPO done right: they found three key factors, advantage normalization, large batch size, and an exponential moving average update of the reference model, and reported PPO surpassing the other alignment methods across their testbeds, from dialogue to competitive code (APPS, CodeContests).

So the honest picture:

You want to... Fit
Tune tone, format, refusals, helpfulness from a fixed pairs dataset DPO: one loss, two models, cheap and stable
Your preference data came from a different model than yours DPO risk: SFT on in-distribution data first, or generate and label your own pairs
Optimize against a verifiable signal (tests pass, answer correct) Online RL (PPO-style) is where the strongest code results above came from
Limited GPUs and RL experience Start with DPO (+ LoRA); move to online RL only with a measured gap

How I'd approach it

  1. SFT first. Both methods assume a reference model that already speaks your format.
  2. Make preference pairs from your own model's outputs when you can. That's the distribution-shift lesson.
  3. Clean the pairs. Ties and noisy labels hurt; filter them.
  4. Start with TRL defaults (beta=0.1, sigmoid loss) and watch rewards/margins and rewards/accuracies, not just the loss.
  5. Evaluate outside the target. RLHF has a documented alignment tax; check you didn't lose general skills.
  6. Iterate. Several rounds of fresh pairs often beat one big offline pass.

References

What's your experience: has offline DPO been enough for your preference tuning, or did you need online RL to close the gap?

Top comments (0)