Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Sample a (prompt, chosen, rejected) triple, run four forwards (two policy, two frozen reference), form the log-ratio gap on chosen minus the same gap on rejected, then backprop the sigmoid loss into the policy only.
Imagine grading two essays a student wrote on the same prompt, one good, one bad. You also keep last week's version of the student to use as a reference baseline. You ask both students to score each essay and write down four scores. Then you check: did the new student get more excited about the good essay relative to the old student than they did about the bad essay relative to the old student? If yes, great, keep nudging in that direction. If not, push harder so the gap grows. DPO is just that comparison made math: four scores, one preference signal, gentle updates only to the new student so they do not forget who they were.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: four forwards (two policy, two frozen reference) + sequence log-prob sum + log-ratio gap difference + sigmoid loss with β + policy-only backprop + memory trade-off.
| Step | Model | Input | Gradient? |
|---|---|---|---|
| 1 | n/a | Sample (prompt, chosen, rejected) triple | n/a |
| 2 | Policy θ | prompt + chosen | yes |
| 3 | Policy θ | prompt + rejected | yes |
| 4 | Reference (frozen) | prompt + chosen | no |
| 5 | Reference (frozen) | prompt + rejected | no |
| 6 | n/a | Form log-ratio gap difference | n/a |
| 7 | Policy θ only | Backprop sigmoid loss | yes |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Forgetting that the reference model needs both a chosen and a rejected forward, not one shared call. Without both reference log-probs you cannot form the gap difference DPO is built on.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.