Preference tuning with DPO and its variants
SFT teaches a model to imitate good answers. Preference tuning teaches it to tell a better answer from a worse one. Direct Preference Optimization (DPO) made this practical for ordinary teams: no reward model, no reinforcement learning loop, just pairs of responses where one is preferred. If your model is mostly right but has habits you want to push out (verbosity, hedging, a tone your users dislike), this is usually the tool.
Why it matters
A lot of quality is relative rather than absolute. It is hard to write the perfect support reply, but easy for a reviewer to say "A is better than B". Preference data captures that judgement directly. The original RLHF recipe (InstructGPT) turned preferences into a reward model and then optimised a policy with PPO, which is powerful but fiddly and expensive. DPO showed that the same objective can be solved with a simple classification-style loss on the policy itself.
DPO is now a standard stage in open post-training recipes, and it is supported in TRL, Axolotl, Unsloth and hosted platforms such as Together's preference fine-tuning. OpenAI's fine-tuning API also exposed DPO as a method, though that platform is being wound down for most customers in 2026.
How it works
Each training example has a prompt, a chosen response and a rejected response. DPO keeps a frozen copy of the starting model as a reference. The loss pushes up the policy's log-probability of the chosen response relative to the reference, and pushes down the rejected one, with a temperature-like parameter beta controlling how far the policy may drift from the reference.
Rendering diagram…
In TRL, beta defaults to 0.1; a higher beta keeps the model closer to the reference. TRL's docs note that in practice DPO often works by suppressing the likelihood of rejected completions more than by raising chosen ones, which is worth knowing when you inspect logged metrics like rewards/chosen and rewards/margins.
The variants you will meet:
- IPO replaces the log-sigmoid with an identity-style objective to reduce overfitting on deterministic preferences (
loss_type="ipo"in TRL). - SimPO normalises by response length and drops the reference model, countering DPO's tendency to favour longer answers (TRL exposes a length-normalised form as
sigmoid_norm). - KTO learns from unpaired thumbs-up or thumbs-down labels, which is handy when you have feedback buttons rather than side-by-side comparisons.
- ORPO folds a preference term into SFT, skipping the separate reference model and stage.
- Robust DPO models label noise, useful when annotators disagree.
Reference architecture
Where do the pairs come from? The best source is on-policy: sample several responses from your current model, have a judge or human pick the best and worst, and train on those. Off-policy pairs from some other model work but teach less.
Rendering diagram…
Running two or three rounds of this loop (often called iterative or online DPO) typically beats one big offline run, because each round's pairs reflect the model's current mistakes.
Code
DPO with TRL on a conversational preference dataset, training a LoRA adapter on top of an SFT checkpoint.
from datasets import load_dataset
from peft import LoraConfig
from trl import DPOConfig, DPOTrainer
# rows: {"prompt": [...messages], "chosen": [...], "rejected": [...]}
pairs = load_dataset("json", data_files="support_prefs.jsonl", split="train")
pairs = pairs.train_test_split(test_size=0.05, seed=0)
args = DPOConfig(
output_dir="support-dpo",
beta=0.1,
loss_type=["sigmoid"], # try ["ipo"] or ["sigmoid_norm"] if length bias appears
learning_rate=1e-5, # TRL suggests ~1e-5 for adapters
num_train_epochs=1,
per_device_train_batch_size=2,
gradient_accumulation_steps=8,
max_length=2048,
)
trainer = DPOTrainer(
model="my-org/qwen3-4b-support-sft",
args=args,
train_dataset=pairs["train"],
eval_dataset=pairs["test"],
peft_config=LoraConfig(r=16, lora_alpha=32, target_modules="all-linear"),
)
trainer.train()
Track rewards/accuracies on the eval split. If it climbs to near 1.0 quickly while your real win-rate eval stays flat, the model is learning a shortcut (often length) rather than quality.
Trade-offs and pitfalls
- Length hacking. Judges and humans often prefer longer answers, so DPO learns verbosity. Control for length when building pairs, or use a length-normalised loss.
- Start from SFT. DPO on a model that cannot already produce decent answers in your format tends to be unstable.
- Pair quality. If chosen and rejected are both bad, or nearly identical, the signal is noise. Prefer clear but realistic gaps.
- Overfitting with high learning rates. DPO is sensitive; the default learning rates in TRL are low for a reason.
- Judge bias. An LLM judge has positional and self-preference biases. Randomise order and calibrate against human labels on a sample.
- DPO is not RL. It cannot discover new behaviours the model never samples. For checkable tasks where you want the model to get better at solving, look at reinforcement learning.
Checklist
- Run SFT first so the model already produces the right format.
- Build pairs on-policy from your current model where possible.
- Randomise response order for judges and audit judge agreement with humans.
- Monitor length of chosen versus rejected responses.
- Use a low learning rate and one epoch to start.
- Evaluate with head-to-head win rate on held-out prompts, not just DPO loss.
Further reading
- Direct Preference Optimization: Your Language Model is Secretly a Reward Model (arXiv 2305.18290)
- TRL DPO Trainer documentation
- SimPO: Simple Preference Optimization with a Reference-Free Reward (arXiv 2405.14734)
- KTO: Model Alignment as Prospect Theoretic Optimization (arXiv 2402.01306)
- Together AI fine-tuning overview (preference fine-tuning)