Overview
Direct Preference Optimization (DPO) is described in the paper Direct Preference Optimization: Your Language Model is Secretly a Reward Model. It aligns a language model to human preferences using pairs of preferred and rejected completions, without requiring a separate reward model or RL training loop. DPO directly optimizes the model to widen the log-likelihood margin between preferred and rejected completions relative to a reference model. In practice, this is achieved by suppressing the likelihood of rejected completions rather than increasing the likelihood of preferred ones.Quick start
Dataset format
DPO requires a preference dataset withchosen and rejected fields. An explicit prompt field is recommended. Both standard and conversational formats are supported.
The beta parameter and reference model
The DPO loss is:beta parameter (default 0.1) controls how much the trained model is allowed to deviate from the reference model:
- Higher
beta: the model stays closer to the reference — less aggressive alignment. - Lower
beta: the model can deviate more — stronger preference signal but risk of over-optimization.
Loss types
DPOTrainer supports multiple loss formulations via the loss_type parameter. You can also combine multiple losses:
Available loss types
Available loss types
Key configuration parameters
Core DPO parameters
Core DPO parameters
float
default:"0.1"
Controls deviation from the reference model. Higher values mean less deviation. For IPO (
loss_type="ipo"), this is the regularization parameter τ.list[str]
default:"sigmoid"
Loss type(s) to use. Pass a list to combine multiple losses weighted by
loss_weights.list[float] | None
Weights for each loss type when using multiple losses. Defaults to equal weights if not specified.
float
default:"0.0"
Label smoothing used in Robust DPO (probability of preference label flip, range
[0.0, 0.5)) and EXO (ε parameter).Reference model
Reference model
bool
default:"false"
Precompute reference model log probabilities over the entire dataset before training starts, then discard the reference model. Saves memory during training.
int | None
Batch size to use when precomputing reference log probabilities. Can be set higher than the training batch size to speed up preprocessing.
bool
default:"false"
Periodically synchronize the reference model with the active model using a mixup (TR-DPO). Not compatible with PEFT or
precompute_ref_log_probs=True.Data preprocessing
Data preprocessing
int | None
default:"1024"
Maximum total sequence length (prompt + chosen/rejected). Sequences exceeding this are truncated.
str
default:"keep_start"
Which end to truncate when a sequence exceeds
max_length. Options: "keep_start" or "keep_end".bool
default:"false"
Perform forward passes without padding. Requires FlashAttention 2 or 3.
DPOConfig overrides some TrainingArguments defaults: logging_steps=10, gradient_checkpointing=True, bf16=True, and learning_rate=1e-6.Training with PEFT/LoRA
Training Vision-Language Models
SFT before DPO
DPO works best when the model is already capable of generating reasonable responses. A common pipeline is:1
SFT on preferred responses
Fine-tune the model on the
chosen completions from your preference dataset using SFTTrainer. This ensures the model can generate outputs in the expected format before DPO training.2
DPO alignment
Train the SFT-initialized model with
DPOTrainer on the full preference dataset containing prompt, chosen, and rejected columns.