RLHF maximizes expected reward while staying close to the reference model:
maxπθEx,y∼πθ[r(x,y)]−βKL(πθ(y∣x)∥πref(y∣x))
Why this step? The reward term pushes toward high-quality answers; the KL term is a leash preventing the model from producing gibberish that games the reward (reward hacking).
This objective has a known closed-form optimum (a standard result in KL-regularized reward maximization):
π∗(y∣x)=Z(x)1πref(y∣x)exp(β1r(x,y))
where Z(x)=∑yπref(y∣x)exp(β1r(x,y)) is the partition function (normalizer).
Why this step? To turn "given reward, best policy" into "given policy, implied reward." Z(x) is intractable (sums over all sequences) — that's the villain we must eliminate.
Why this step?This is the magic. Because we take a difference of rewards for the same prompt x, the intractable logZ(x)cancels. No reward model, no partition function.
What loss value occurs at initialization (πθ=πref)?
Which four models does PPO-RLHF need that DPO replaces with two?
Answers: 1) It only depends on x; taking a difference of rewards for the same x cancels it. 2) r^θ=βlog(πθ/πref). 3) Reduces deviation (tighter KL leash). 4) log2≈0.693. 5) PPO needs policy+reference+reward+value; DPO needs only policy+reference.
Recall Feynman: explain to a 12-year-old
Imagine teaching a robot to answer nicely. The old way: hire a judge robot to score every answer, then train the answerer to chase high scores — clumsy and the answerer learns to trick the judge. DPO says: skip the judge! Just show the robot pairs — "this answer is good, this one is bad" — and nudge it to make the good one more likely and the bad one less likely, but only compared to how it used to talk, so it doesn't go crazy. The robot ends up being its own judge. Simple, and no cheating.
Dekho, RLHF ka purana tareeka thoda painful hai: pehle ek reward model train karo jo har answer ko score de, phir PPO (ek RL algorithm) se policy ko us score ke peeche bhagao, aur saath mein KL penalty lagao taaki model gibberish na banane lage. Iske liye ek saath 4 models memory mein chahiye aur PPO tuning karna sar-dard hai. DPO bolta hai — yeh sab drama chhodo!
DPO ka core insight yeh hai: KL-regularized reward maximization ka ek closed-form optimal solution hota hai. Us formula ko ulta karke reward ko policy ke terms mein likh lo: r^=βlog(πθ/πref). Ab jab hum Bradley-Terry preference model mein winner aur loser ke reward ka difference lete hain, toh woh dushman jaisa partition function Z(x) automatically cancel ho jaata hai (kyunki dono same prompt x ke hain). Result: ek simple logistic (sigmoid) loss — bas winner yw ki likelihood badhao aur loser yl ki ghatao, reference model ke comparison mein.
β ko galat mat samjho — yeh brake hai, accelerator nahi. Bada β matlab model reference se kam hatega (tight leash); chhota β matlab zyada freedom. Aur ek cheez yaad rakhna: reference model ko mat hatao — uska ratio hi model ko degenerate hone se rokta hai aur Z(x) ko cancel karne mein help karta hai.
Kyun important hai? Kyunki DPO ne alignment ko itna simple aur stable bana diya — bas preference pairs ka data lo aur ek supervised loss chala do, koi reward model nahi, koi RL nahi. Isiliye aaj-kal open-source models (jaise Zephyr, Llama variants) DPO se align hote hain. 80/20 rule: yeh derivation (Z cancel + implicit reward) samajh gaye toh poora DPO samajh gaye.