DPO Variants › Worked Example: Computing Losses Step by Step
Language AI HandbookAll chapters DPO Variants › Worked Example: Computing Losses Step by StepOne section · Sections in this chapter6 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To make the differences between these methods concrete, let's walk through a specific numerical example using a single preference pair. This will illustrate how each loss function responds to the same underlying data and why their behaviors diverge.
Suppose we are training a language model to answer questions more helpfully. For the prompt "What is the boiling point of water?" we have two candidate responses:
- (chosen): "Water boils at 100 degrees Celsius (212 degrees Fahrenheit) at standard atmospheric pressure."
- (rejected): "Water boils at a really high temperature."
Our reference model assigns log-probabilities:
- (moderately likely under the base model)
- (also reasonably likely, since it is short and plausible)
After some training steps, our current policy assigns:
- (the policy has learned to prefer the specific response)
- (the policy has learned to penalize the vague response)
Let's set .
Step 1: Compute the implicit rewards.
The implicit reward for each response is the log-ratio relative to the reference:
The chosen response has a positive implicit reward (the policy has moved toward it relative to the reference), while the rejected response has a negative implicit reward (the policy has moved away from it).
Step 2: Compute .
The log-ratio difference is:
Step 3: Compute the DPO loss.
This loss is still substantial. DPO would continue pushing higher, even though the model already clearly prefers the chosen response.
Step 4: Compute the IPO loss with , giving target .
IPO reports a large loss because the current is far below the target of 5.0. The gradient is:
This gradient is negative, meaning IPO is pushing upward toward the target, just as DPO does in this case. If instead , the IPO gradient would be , pushing back down. DPO would never push downward.
Step 5: Compute the cDPO loss with .
The cDPO loss is slightly higher than DPO here (0.635 vs. 0.594). More importantly, the equilibrium for cDPO with and is:
This is a finite target, far smaller than DPO's implicit infinite target.
Step 6: Compute the KTO value for the chosen response, assuming a reference point .
The KTO loss contribution for this desirable example (with ) is:
Since the implicit reward just barely exceeds the reference point, the model has done only slightly better than average for this example. The loss is close to 0.5, the maximum possible, suggesting the model should continue improving this response.
This worked example illustrates a key pattern: DPO, IPO, and cDPO all respond to the same value but with different equilibria, while KTO operates on individual implicit rewards rather than their difference.