The DPO loss trains a language-model policy directly from preference pairs. It increases the chosen completion’s relative likelihood over the rejected completion while constraining movement from a frozen reference policy through β, avoiding an explicit reward-model training stage. section 8.1.1
Equation 8.2
\[\label{eq:dpo_core} \mathcal{L}_{\text{DPO}}(\pi_\theta; \pi_{\text{ref}}) = -\mathbb{E}_{(x, y_c, y_r) \sim \mathcal{D}}\left[ \log \sigma\left( \beta \log \frac{\pi_{\theta}(y_c \mid x)}{\pi_{\text{ref}}(y_c \mid x)} - \beta \log \frac{\pi_{\theta}(y_r \mid x)}{\pi_{\text{ref}}(y_r \mid x)} \right) \right].\]The objective applies a negative log-sigmoid to the difference between chosen and rejected log-likelihood shifts relative to the reference model. The loss falls when the chosen shift exceeds the rejected shift. section 8.1.1
Operationally, calculate the loss as a sequence-level preference comparison:
- Run policy and reference forward passes on the chosen and rejected completions to obtain sequence log-probabilities. section 8.3
- Subtract rejected log-probabilities from chosen log-probabilities for each model, then subtract the reference ratio from the policy ratio. section 8.3
- Apply negative log-sigmoid to β times that difference; β controls the preference pull and effective KL constraint. section 8.1.1 section 8.3
- Detach implicit chosen and rejected rewards for logging, and cache reference log-probabilities when reducing peak memory matters. section 8.3
Preference-pair behavior
For one prompt, compare a winning completion with a losing completion. If policy training raises the winner’s log-ratio over the reference more than the loser’s, the margin grows and the DPO loss decreases. A DPO+NLL variant additionally penalizes low absolute likelihood on the winning completion. section 8.1.1 section 15.3.1
