Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

LABS · 21  /  ALIGNMENT

The Taste Trainer.

A base model can write, but it doesn't know what people prefer. So we teach it taste: show humans two answers, let them pick the better one, thousands of times. Train a reward model on those picks, then push the model to chase that reward — and watch it start to cheat. Then see how DPO skips the whole detour.

Act 1 · Preferences → reward model
Pick the better answer
You are the human labeler. For each prompt, choose the response you prefer. Every pick is a data point; a reward model learns to predict which answer people like — turning fuzzy human taste into a number the machine can optimize.
Prompt: "Explain photosynthesis to a 10-year-old."
0
Comparisons labeled
—
Reward model accuracy
predicting your taste
—
Your revealed preference
Each comparison sharpens the reward model's picture of what you value. After enough picks it can score a brand-new answer the way you would — that score is the training signal for the next stage.
Act 2 · Policy optimization (and its trap)
The model chases the reward — too hard
Now the model (the policy) is optimized to maximize the reward model's score. Turn up the optimization pressure and watch reward climb — but the reward model is only a proxy. Push too far and the policy finds cheap tricks that score high but humans hate: reward hacking. A KL penalty anchors it back.
Optimization pressure50%
KL penalty (stay close to base)medium
—
Reward-model score
the proxy
—
True human quality
—
Hacking gap
Watch the two curves diverge: proxy reward keeps rising while true quality peaks then falls. The gap is reward hacking — sycophancy, length-padding, confident filler. The KL penalty is what keeps the policy honest.
Act 3 · The shortcut
DPO: skip the reward model entirely
RLHF is a three-stage pipeline: label → train reward model → RL loop. DPO proved you can train straight from the preference pairs with a simple classification loss — the model implicitly is its own reward model. Same goal, far less machinery. Toggle between them.
Method:
3
Pipeline stages
2
Models to train
reward + policy
medium
Training stability
DPO collapses three stages into one and one loss, targeting the same objective RLHF does — which is why it became the common default for preference tuning. RLHF still wins where you need an explicit, reusable reward model or online RL.

Teaching a model what "good" means

A pretrained model has read the internet; a fine-tuned one can follow instructions. Neither knows what people actually prefer — helpful over evasive, honest over confident-sounding, concise over padded. Those are relative judgments, hard to demonstrate directly. So instead of showing the model answers to copy, we show it comparisons: this response is better than that one. That's the raw material of alignment.

The RLHF pipeline

Step 1 — collect preferences: humans pick the better of two model responses, thousands of times. Step 2 — train a reward model: a model learns to predict those picks, outputting a scalar "how much would a human like this?" score. Step 3 — optimize the policy: reinforcement learning (classically PPO) pushes the language model to produce responses the reward model scores highly.

The reward-hacking trap

The reward model is a proxy, not the real thing — and optimizers exploit proxies. Push too hard and the policy discovers tricks that inflate the score without genuinely being better: sycophancy, verbosity, confident filler. The fix is a KL penalty that keeps the policy close to the original model, trading a little reward for staying grounded. It's Goodhart's law in a training loop: when a measure becomes a target, it stops measuring well.

DPO: the elegant shortcut

Direct Preference Optimization asked: do we even need the separate reward model and RL loop? Its derivation shows the language model can implicitly act as its own reward model, so you can train directly on preference pairs with a simple classification-style loss — no reward model, no PPO, no sampling loop. Same underlying objective as RLHF, dramatically simpler and more stable, which is why it became the common default for preference tuning.

And beyond

The family keeps growing: Constitutional AI replaces human preference labels with AI judgments against written principles (RLAIF); reasoning models like DeepSeek-R1 use RL against verifiable rewards (is the answer correct?) rather than learned preference. But the core idea traces to InstructGPT: turn human judgment into a signal, and optimize toward it — carefully.

The picture: two roads from the same preference pairs

RLHF: three stages, sampling inside the loop pairsw ≻ l reward modelσ(r_w − r_l) PPO loopmax r − β·KL policy πtuned reference π_reffrozen copy KL penaltylog-probs pairsw ≻ l DPO loss−log σ(β·margin) policy πtuned DPO: one stage, offline on fixed pairs, no reward model
Both roads start from the same comparisons and both lean on a frozen copy of the starting model. RLHF turns the pairs into a separate reward model, then has to generate fresh answers and score them while it trains. DPO feeds the pairs and the reference’s log-probabilities into one loss and never generates anything during training. The reward model in the top row is the proxy that Act 2 lets the policy cheat.

Cost and trade-offs: what each method makes you run

Here Time is the work per training step and Space is the models held in memory. Generating text is the slow part of any training loop, so the first question for each method is whether it has to.

CaseTimeSpaceWhy
Reward model trainingTwo forward passes per pair, one for each answerOne modelPlain supervised learning on the labels. Cheap, and the result can be reused to score anything later.
RLHF with PPOGenerate a fresh answer, score it, update: sampling in every stepFour: policy, reference, reward model and a value model (the critic)Online, so it can keep exploring past the labeled data. Also the most moving parts and the most hyperparameters to get wrong.
DPOForward passes on the winner and loser; no generationPolicy plus frozen reference (its log-probs can be computed once, before training)Offline on a fixed dataset. Stable and cheap, but it only ever sees the answers someone already wrote.
GRPO-style RLSeveral answers per prompt, each scored against the group’s averageNo value modelDrops the critic by using the group mean as the baseline. Popular with verifiable rewards, where a checker gives the score.
Best-of-n (no training)n generations per request at serving timeReward model kept in productionSample n answers, return the one the reward model likes best. Zero training risk; n times the inference bill.

The trade is reach against simplicity. Online RL can find answers better than anything in the dataset, and it can also find the hacks Act 2 shows. DPO cannot hack a reward model it does not have, but it is capped by the pairs you collected. A sensible order is to start with DPO and reach for online RL only when the offline pairs stop helping.

Common mistakes

  • Grading the policy with the reward model it chased

    The policy was optimized to please that exact model, so its score rises almost by definition. Judge progress with fresh human ratings, or a different judge, on prompts the reward model never trained on.

  • Assuming DPO makes the winner more likely

    The loss only cares about the gap. If the winner drops from −13.0 to −13.5 and the loser from −14.5 to −16.5, the margin is still 1.5 and the loss is the same 0.621 as the page’s example. Track the chosen answer’s log-probability, not just the loss.

  • Training on pairs the reference would never write

    DPO measures every answer against the reference’s log-probability. Pairs written by a very different model sit far from it, and the signal gets noisy. Fine-tune the reference on in-domain answers first, or generate the pairs from it.

  • Forcing a pick between two equal answers

    A coin-flip label teaches the model a preference that does not exist. Let labelers mark a tie, then drop those pairs or treat them separately.

  • Showing the answers in a fixed order

    Labelers drift toward one side when they are tired or unsure. Shuffle which answer appears first, or a habit about position becomes a learned “taste”.

Where this shows up in production and interviews

  • Chat assistants

    InstructGPT set the pattern: supervised fine-tuning, a reward model, then PPO. Its paper reports labelers preferring a 1.3B-parameter tuned model over the 175B base GPT-3, which is why preference tuning became a standard stage after pretraining.

  • Open-weight recipes

    Llama 2’s chat models used reward models with rejection sampling and PPO. Zephyr used DPO on AI-ranked pairs, showing a small team could do preference tuning with no RL loop at all.

  • Reward models outside training

    A trained reward model is useful on its own: to rerank n candidate answers at serving time, to filter synthetic training data, or as a cheap first-pass judge in evals before humans look.

  • Interview angle

    Expect “why not just fine-tune on the winners?” Supervised fine-tuning never sees the loser, so it learns what good looks like but not what is worse. Preference losses learn from the contrast. Follow-ups: why the KL term exists, and what β trades.

RLHF and DPO, step by step

The preference model and the two objectives

Both methods start from the same model of a human choice, the Bradley-Terry model: the chance that people prefer response A over B is σ(r_A − r_B), where r is a scalar reward and σ the logistic function. With r_A = 1.5 and r_B = 0.5 the chance is σ(1.0) = 73.1%.

  1. Train the reward model on each labeled pair (winner w, loser l) to minimize −log σ(r_w − r_l). A gap of +1 costs 0.313; a gap of +3 costs 0.049; a gap of −1, a wrong order, costs 1.313.
  2. Optimize the policy to maximize r(y) − β · KL(policy ‖ reference). The best policy has a closed form, the reference model reweighted by er/β.
  3. Or skip both. DPO minimizes −log σ(β · [(log π(w) − log ref(w)) − (log π(l) − log ref(l))]), using only log-probabilities from the policy and the frozen reference.

Worked example. Take two responses with equal reference probability and rewards 1 and 0. At β = 1 the optimal policy picks the better one e/(1 + e) = 73.1% of the time; at β = 0.5 it picks it 88.1% of the time, and at β = 0.1 essentially always. A larger β keeps the policy close to the reference, which is the KL slider in Act 2. Now a DPO pair: the policy's log-probability for the winner is −12.0 against the reference's −13.0 (up 1.0), and for the loser −15.0 against −14.5 (down 0.5), a gap of 1.5. With β = 0.1 the margin is 0.15 and the loss is 0.621, just below the starting 0.693 (ln 2). With β = 0.5 the margin is 0.75 and the loss is 0.387. Training raises the margin until it is large, and the loss approaches zero.

Knobs and pitfalls. Typical DPO values of β run from 0.1 to 0.5; lower values let the policy drift further from the reference. Reward models and DPO both learn to prefer longer answers if labelers do, so control for length. Label noise caps what any method can learn, so measure agreement between your labelers first. For RLHF, watch the KL term and hold out a separate evaluation, since rising reward alone does not mean the model is improving.

Check yourself

Four questions. No sycophancy, please.

See every answer, with the reasoning
  1. What are the three stages of classic RLHF?

    Answer: Collect preferences, train a reward model, optimize the policy with RL — Human picks → reward model → RL against that reward, with a KL penalty.

  2. What is reward hacking?

    Answer: The policy scores high on the proxy reward in ways humans don’t actually like — The reward model is an imperfect proxy; over-optimizing it exploits its gaps — sycophancy, padding.

  3. What does the KL penalty do?

    Answer: Keeps the policy close to the base model, trading a little reward to avoid drifting into hacks — It anchors the optimized model to the original, the main defense against reward hacking.

  4. How does DPO simplify RLHF?

    Answer: It trains directly on preference pairs with one loss — no separate reward model, no RL loop — The model implicitly serves as its own reward model; same objective, far less machinery.

Finished this one? 0 / 61 Labs done
NextGradient Descent: The Descent Closest lab to this one

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Labs