A pretrained model completes text. How do demonstrations and a reward model learned from comparisons start turning it into an assistant, how do reinforcement learning from human feedback (RLHF) and Direct Preference Optimization (DPO) optimize those preferences while staying near the fine-tuned model, and what does preference optimization not buy?
Deep Learning · CS 4715/5715 · University of Idaho
The second deck of today's class, after S20's.
S20 read the model's distribution; alignment changes it
S20 took the model's distribution as given and chose how to read it; alignment changes the distribution itself.
In S20, samplers chose tokens from the model's distribution and prompts conditioned it, with every weight fixed.
Alignment (in the engineering sense): tune the model so its default behavior is a helpful, harmless assistant, not a text predictor. InstructGPT (Ouyang et al., 2022) assembled the canonical pipeline: SFT, then a reward model and RL; DPO (2023) later became an alternative to its last two steps.
Today follows the pipeline's steps, then asks what they do not buy
Pretrained → SFT → reward model → RL with KL → aligned; DPO replaces the last two steps.
Part 1 · Demonstrations and comparisons
step 1, SFT, and step 2, the reward model
Part 2 · Optimizing the preferences
step 3, RL with a KL penalty, then DPO, which replaces steps 2 and 3
Part 3 · What it does not buy
reward hacking and evaluation
InstructGPT's method has three steps
Each step trains one model on its own data, with its own objective:
Christiano et al. (2017) learned a reward model from human comparisons and optimized it with RL, on Atari and simulated robots.
Stiennon et al. (2020) ran all three steps for summarization: SFT, a reward model from comparisons, then PPO (proximal policy optimization) with a KL penalty. InstructGPT (Ouyang et al., 2022) applied them to general instructions on GPT-3.
The reading groups steps 2 and 3 as its Stage 2.
Step 1, SFT, applies the next-token loss to the response tokens
Part 1 · Demonstrations and comparisons. Supervised fine-tuning (SFT): hire people to write good responses to prompts, and train on them with S18's loss, restricted to the response:
\(x\) is the prompt and \(y\) the response; \(\pi_\theta\), the model being tuned, is called the policy.
This alone turns a text predictor into an instruction follower. Limits: writing demonstrations is costly, and only demonstrated behavior is directly supervised.
Step 2 learns a reward model from comparisons
A reward model \(r_\phi(x,y)\) reads a prompt and a response and returns one number: how strongly people would prefer that response. Step 3 queries it in place of a person, since no one can rate every sampled response. It is trained on comparisons, because comparing two responses is easier than writing one.
The Bradley–Terry model: \(y_w\) is the preferred response, \(y_l\) the other, \(\sigma\) the sigmoid. Training minimizes \(-\log\) of this probability, a binary cross-entropy with the score difference as the logit.
Self-check on SFT targets, ranked pairs and preference probabilities
Three questions on Part 1.
(a) SFT on a 9-token prompt and a 5-token response: how many positions are in the loss?
(b) Labelers rank three responses B, A, C, best first. Which preference pairs follow?
(c) The score difference is 0: \(P(y_w\succ y_l\mid x)\), and the loss? For a difference of 2?
(a) 5: only the response tokens are targets.
(b) Three: B over A, B over C, A over C.
(c) \(\sigma(0)=0.5\), loss \(\log2\approx0.693\). For 2: \(\sigma(2)\approx0.881\), loss about 0.127.
That settles Part 1. Next comes Part 2, optimizing the model against the learned reward.
Step 3, RL, maximizes the reward minus a KL penalty
Part 2 · Optimizing the preferences. RLHF optimizes the SFT model against \(r_\phi\) with reinforcement learning (RL); InstructGPT used proximal policy optimization (PPO):
Reward term: pushes \(\pi\) toward responses the reward model scores high, that is, toward what labelers preferred.
KL term: \(\pi_{\text{ref}}\) is the SFT model, \(\beta\) its weight. The KL divergence (Kullback–Leibler), the expected log-ratio of the policy's probabilities to the SFT model's, is 0 only when they match; it keeps \(\pi\) near the SFT model, so the policy cannot drift into degenerate text that games the reward model.
One RL step samples, scores, compares with the SFT model and updates
PPO maximizes slide 8's objective one step at a time, and each step uses one sampled response \(y\) for both terms:
The reward pulls toward what labelers preferred, the log-ratio pulls back toward the SFT model, and \(\beta\) sets the balance.
InstructGPT's 1.3B model was preferred over a model 100× larger
Ouyang et al. (2022), in their human evaluations:
Outputs of the 1.3B InstructGPT model were preferred to outputs of the 175B GPT-3. Also reported: improvements in truthfulness and reductions in toxicity, on their measures.
On this evidence, alignment training changed perceived usefulness far more than scale did.
Reported costs: an "alignment tax" on some academic benchmarks (mitigated by mixing in pretraining data), and a dependency on a specific pool of labelers.
RLHF needs a separate reward model, an RL loop and careful stabilization; DPO needs neither.
DPO replaces steps 2 and 3
DPO uses the same preference pairs as step 2 and trains the policy on them directly:
DPO is an alternative to steps 2 and 3, not a step after them.
DPO starts from the optimum of slide 8's objective
DPO (Rafailov et al., 2023). RLHF fits a reward model, then searches for the policy. DPO asks what that policy would be, and trains it directly.
We use slide 8's objective \(J(\pi)\) for one prompt \(x\) and a given reward \(r\); \(\pi^*\) maximizes it.
One sum over \(y\): \(J(\pi)=\sum_y\pi(y\mid x)\big[r(x,y)-\beta\log\big(\pi(y\mid x)/\pi_{\text{ref}}(y\mid x)\big)\big]\).
Put \(r\) into the log as \(\beta\log e^{r/\beta}\). With \(Z(x)=\sum_y\pi_{\text{ref}}(y\mid x)\,e^{r(x,y)/\beta}\), \(\pi_{\text{ref}}\,e^{r/\beta}/Z(x)\) sums to 1, and \(J(\pi)=-\beta\,\mathrm{KL}\big(\pi\,\Vert\,\pi_{\text{ref}}\,e^{r/\beta}/Z(x)\big)+\beta\log Z(x)\).
\(\beta\log Z(x)\) does not depend on \(\pi\); the KL is \(\ge0\), and 0 only when the two match:
\[\pi^*(y\mid x)=\frac{1}{Z(x)}\,\pi_{\text{ref}}(y\mid x)\,e^{r(x,y)/\beta}\]
\(Z(x)\) depends only on \(x\) and sums over all responses: it cannot be computed.
The optimum reweights \(\pi_{\text{ref}}\), and the reward can be read back from it
Slide 12's optimum multiplies each response's probability under \(\pi_{\text{ref}}\) by \(e^{r/\beta}\), then divides by the sum \(Z(x)\): the higher the reward, the larger the weight. Three responses with rewards 0, 1 and 2:
\(\beta\) divides the reward as S20's temperature divides the logits: small \(\beta\) moves nearly all the probability to the highest reward, and large \(\beta\) keeps \(\pi^*\) near \(\pi_{\text{ref}}\).
Read back the reward: take logs and solve, \(r(x,y)=\beta\log\big(\pi^*(y\mid x)/\pi_{\text{ref}}(y\mid x)\big)+\beta\log Z(x)\).
Every reward corresponds to a policy, and back. The subtitle names the move: "Your Language Model Is Secretly a Reward Model".
Substituting into Bradley–Terry cancels \(\log Z\), leaving a loss on the policy
Slide 13's rewards for \(y_w\) and \(y_l\) share \(\beta\log Z(x)\), because both answer the same prompt \(x\):
Train a policy \(\pi_\theta\) in the place of \(\pi^*\): it becomes the optimal policy for a reward that agrees with the preference pairs. With slide 6's loss on the difference:
\(\log\pi_\theta(y\mid x)\) sums the log-probabilities at the response's positions. Each response goes once through the policy and once through the reference: no reward model, no sampling.
Under its assumptions (Bradley–Terry preferences, slide 8's objective), DPO's optimum is the policy RLHF aims for; the paper reports DPO matching or exceeding PPO-based RLHF.
Optimize a learned reward too hard, and true quality falls
Part 3 · What it does not buy. Preference optimization aligns to what labelers preferred, which is not identical to "true" or "good". Reward models can be over-optimized: reward hacking.
Classic failure: outputs get longer and more sycophantic but not better; length and agreeableness correlate with labeler preference in the training data. DPO has no separate reward model, but its implicit reward, \(\beta\log(\pi_\theta/\pi_{\text{ref}})\) (the reward read back from the policy), is fit to the same preference data and learns the same correlations.
Never optimize a proxy metric you have not stress-tested; inspect outputs directly. The KL penalty exists to limit this drift.
Aligned models are compared by preference, and judges are biased
Perplexity, the exponential of S18's next-token loss on held-out text, measures the pretraining objective, which post-training moves away from: an aligned model can have worse perplexity and be more useful.
Pairwise win rates: a judge picks the better of two models' responses, over many prompts. The judge is a person, as in Chatbot Arena's millions of crowd-sourced votes, or an LLM, which is cheap and fast.
Strong LLM judges agree with human majority preferences about as often as humans agree with each other, on Zheng et al.'s (2023) setup, with three biases:
bias
the judge favors
mitigation
position
whichever answer is shown first
swap the order and average
verbosity
longer answers
control for length
self-enhancement
outputs resembling its own style
use a judge from a different model family
Report win rates with their uncertainty, over seeds and prompts, decoding fixed (S20).
Self-check on win rates, perplexity and what preferences align to
Three questions on Part 3.
(a) After preference tuning, your model wins 70% of comparisons against the base under an LLM judge, and its answers are twice as long. What do you check first?
(b) Held-out perplexity rose after RLHF. Has the run failed?
(c) What does preference optimization align a model to, and what does that not guarantee?
(a) Length: the judge's verbosity bias, or a hacked reward. Control for length, swap the order, and read the outputs.
(b) Not by that measure: perplexity measures the pretraining objective, which post-training moves away from. Compare by preference and instruction following.
(c) To what its labelers preferred; that is no guarantee of "true" or "good".
That settles what it does not buy. Next come four mistakes, today's answer and next time.
Four mistakes with alignment, with their causes and fixes
Part 4 · Close. Reading 3.7's three pitfalls, and S20's lesson about settings:
symptom
cause
fix
after preference tuning, outputs get longer and more sycophantic but not better
the reward is gamed: length and agreeableness correlate with labeler preference
inspect outputs directly; never optimize a proxy you have not stress-tested
benchmark scores dip after RLHF, and the run is declared a failure
the alignment tax: helpfulness tuning can trade off narrow benchmark accuracy
evaluate what alignment targets (win rate, instruction following), not only what pretraining targets
DPO training looks stable, but answers drift toward terse, generic text
over-training on a narrow offline preference set collapses diversity
hold out preference pairs, stop early on win rate against the reference, and read samples
an alignment claim reported without its decoding settings
evaluation results depend on the sampler (S20)
fix and report the decoding settings with every alignment claim
Demonstrations, a KL penalty and preferences answer today's question
Back to the title page's question, clause by clause.
Demonstrations and comparisons: SFT trains S18's next-token loss on the response tokens of human-written demonstrations; the reward model, the LLM with a scalar output, learns ranked comparisons through Bradley–Terry.
Optimizing the preferences: RLHF maximizes \(r_\phi\) minus \(\beta\) times the KL divergence to the SFT model (PPO in InstructGPT). DPO solves that objective's optimum for the reward; \(\log Z\) cancels, and one classification-style loss on preference pairs trains the model directly, with no reward model and no RL.
What it does not buy: it aligns to what labelers preferred, not to truth; a learned reward can be hacked (length, sycophancy); aligned models are judged by preference, with the judge's biases controlled.
For next time
Next session (S22), Monday: Vision Transformers and multimodal models (ViT and CLIP), the final session of Module 3.