Skip to main content

DPO Training

Direct Preference Optimization aligns models with human preferences without reward modeling.

What is DPO?

DPO (Direct Preference Optimization) is a simpler alternative to RLHF. Instead of training a separate reward model, DPO directly optimizes the model to prefer chosen responses over rejected ones.

Quick Start

DPO requires --prompt-text-column and --rejected-text-column. The --text-column defaults to "text", so only specify it if your chosen column has a different name.

Python API

Data Format

DPO requires preference pairs: a prompt with chosen and rejected responses.

Multiple Turns

For multi-turn preference data, provide the prompt as a messages list. The prompt marks where the shared context ends — everything after is the diverging chosen/rejected trajectory.

Parameters

Beta

The beta parameter controls how much the model can deviate from the reference:
  • 0.01-0.05: Aggressive optimization (may overfit)
  • 0.1: Standard (recommended)
  • 0.5-1.0: Conservative (stays close to reference)

Reference Model

When model_ref is None (the default), DPO uses the initial model as the reference. You can specify a different one:

Training Tips

Use LoRA

DPO works well with LoRA:

Lower Learning Rate

DPO is sensitive to learning rate:

Fewer Epochs

DPO typically needs fewer epochs:

Example: Helpful Assistant

Create a more helpful assistant:

DPO vs ORPO

Collecting Preference Data

Human Annotation

  1. Generate multiple responses per prompt
  2. Have annotators rank responses
  3. Create chosen/rejected pairs

LLM-as-Judge

Next Steps

ORPO Training

Combined SFT + alignment

Reward Modeling

Train reward models