TAI BUI
Back to curriculum
BuildPython

Reward Modeling & RLHF

Humans cannot write a reward function for "good assistant response," but they can compare two responses and pick the better one. Fit a reward model to those comparisons, then RL the language model against it. Christiano 2017. InstructGPT 2022. The recipe that turned GPT-3 into ChatGPT. In 2026 it's mostly being replaced by DPO, but the mental model stays.

TIME: ~45 minutesPREREQUISITES: Phase 5 · 05 (Sentiment), Phase 9 · 08 (PPO)

Learning Objectives

  • Explain why a hand-written reward function for 'good response' doesn't work, and how pairwise human preference comparisons fix that by training a reward model.
  • Walk through the three-stage SFT then reward-model then PPO pipeline, including the Bradley-Terry pairwise loss that fits the reward model and the KL-penalized objective that optimizes the policy against it.
  • Diagnose the core RLHF failure modes, reward hacking, length hacking, an undersized reward model, noisy preference labels, and explain why the KL-to-reference term is the primary safeguard against over-optimization.
  • Place RLHF in the 2026 alignment landscape relative to DPO, GRPO, process reward models, and RLAIF/Constitutional AI, and state what each replaces or extends.

The Problem

You trained a language model on next-token prediction. It writes grammatical English. It also lies, rambles, and refuses to refuse. More pretraining won't fix that: web text is the problem, not the cure.

What you actually want is a scalar reward: a number that says "response A is better than response B for instruction X." Writing that function by hand is impossible, since "helpfulness" has no closed-form expression over tokens. But humans can compare two outputs and mark a preference, and that's cheap to collect at scale.

RLHF (Christiano et al. 2017; Ouyang et al. 2022) turns those preferences into a reward model, then optimizes the LM with PPO against it, in three steps: SFT → RM → PPO. It's the recipe that shipped ChatGPT, Claude, Gemini, and every other aligned LLM between 2023 and 2025.

By 2026 the PPO step is mostly replaced by DPO (Phase 10 · 08), which is cheaper and nearly as good for alignment tuning. The reward model piece hasn't gone anywhere, though: it still underlies every Best-of-N sampler, every RL-from-verifiable-rewards pipeline, and every reasoning model built on a process reward model. Understand RLHF and you understand the whole alignment stack.

Warm-up0/3
1. The sigmoid function σ(z) = 1 / (1 + e^(-z)) accepts any real number. What range of values can it output?Warm-up
The formula for the sigmoid, a plotted S-shaped curve over z from -6 to 6 with the vertical axis left unlabelled, and a table of σ(z) for z = -4, -2, 0, 2, 4.
Curve and table computed in Python from the formula.
2. What does the KL divergence KL(P || Q) measure for two probability distributions P and Q?Warm-up
Paired bar charts of P (0.5, 0.25, 0.125, 0.125) and Q (0.25 for each) over four outcomes a to d, with the KL(P || Q) sum formula written below.
Example distributions chosen for this picture.
3. In PPO, what is the clipped surrogate objective for?Warm-up
A flow: policy π_old collects a batch of rollouts, then the policy π_θ takes several gradient steps on that batch, with the ratio r = π_θ/π_old and the clipped surrogate objective with ε = 0.2 written below.
Check: The Problem0/1
1. Why can't a reward function for 'good assistant response' be written by hand?Explain
A prompt asking for help writing a message to a landlord about a broken heater, two described responses A and B, a code stub def reward(response) returning ???, and a note that a person can say which of A or B is better.
Responses are described, not quoted. Illustrative.

The Concept

Three-stage RLHF: SFT, RM training on pairwise prefs, PPO with KL penalty

Stage 1: Supervised Fine-Tuning (SFT). Start from a pretrained base model and fine-tune it on human-written demonstrations of the target behavior: instruction-following responses, helpful replies, and so on. The result is a model π_SFT that's biased toward good behavior but still has an unbounded action space.

Stage 2: Reward Model training.

  • Collect pairs of responses (y_+, y_-) to prompts x, labeled by humans as "y_+ is preferred over y_-."

  • Train a reward model R_φ(x, y) to assign higher scores to y_+.

  • Loss: the Bradley-Terry pairwise logistic:

    L(φ) = -E[ log σ(R_φ(x, y_+) - R_φ(x, y_-)) ]

    σ is the sigmoid, so the reward gap maps directly to a log-odds of preference. Bradley-Terry has been the standard since 1952 and is still the dominant choice in modern RLHF.

  • R_φ is usually initialized from the SFT model with a scalar head bolted on: same transformer backbone, one linear layer producing the reward.

Stage 3: PPO against the RM with KL penalty.

  • Initialize the trainable policy π_θ from π_SFT, and keep a frozen reference π_ref = π_SFT.

  • Reward at the end of a response y:

    r_total(x, y) = R_φ(x, y) - β · KL(π_θ(·|x) || π_ref(·|x))

    The KL penalty stops π_θ from drifting arbitrarily far from π_SFT. It's a regularizer, not a hard trust region, and β typically sits around 0.01-0.05.

  • Run PPO (Lesson 08) with this reward. Advantages get computed on the token-level trajectory, but the RM only scores the full response.

Why the KL? Without it, PPO will happily find reward-hacking strategies, since the RM was only trained on in-distribution completions. An out-of-distribution response can score higher than anything a human ever wrote. The KL keeps π_θ near the manifold where the RM was actually trained: it's the single most important knob in RLHF.

2026 status. The three-stage pipeline above is the classic recipe, but most of it has since been streamlined or replaced:

  • DPO (Rafailov 2023): closed-form algebra collapses Stage 2+3 into a single supervised loss over preference data. No RM, no PPO. Same quality on alignment benchmarks for a fraction of the compute. Covered in Phase 10 · 08.
  • GRPO (DeepSeek 2024–2025): PPO with a group-relative baseline instead of a critic, reward from a verifier (code runs / math answer matches) instead of a human-trained RM. Dominant for reasoning models. Covered in Phase 9 · 12.
  • Process reward models (PRMs): score partial solutions (each reasoning step), used in both RLHF and GRPO variants for reasoning.
  • Constitutional AI / RLAIF: use an aligned LLM to generate preferences instead of humans. Scales the preference budget.
Check: The Concept0/17
1. What are the three stages of RLHF, in order?Define
A base language model on the left and an aligned assistant on the right, joined by three empty dashed boxes labelled stage 1, 2, 3, with three unordered cards below: PPO, Reward model, and SFT, each with a short description.
2. What is a reward model in RLHF?Define
A preference-data card with the prompt help me, a preferred response clear kind and a rejected response rude vague, an arrow to a box for the reward model R_φ(x, y) whose output is marked with a question mark, and a note asking what R_φ is.
3. Which loss trains the reward model on pairs of preferred and rejected responses?Define
A table of three comparison rows with prompt, preferred response and rejected response (help me: clear kind over rude vague, and two more), a note that each row is one human comparison, and a line loss(φ) = ?.
Rows taken from the lesson's toy vocabulary.
4. What does the β · KL(π_θ || π_ref) term do inside the RLHF reward?Define
A trainable policy π_θ and a frozen reference policy π_ref = π_SFT joined by a KL link, with the formula r_total = R_φ - β · KL(π_θ || π_ref) and a note that β typically sits around 0.01 to 0.05.
5. What is RLAIF?Define
A flow from a prompt with response A and response B to a dashed box labelled who labels with a question mark, then to a preference pair (y+, y-), with a note asking what RLAIF is.
6. What is a process reward model (PRM)?Define
A three-line solution to 3x + 5 = 20 (subtract 5 to get 3x = 15, divide by 3 to get x = 5, final answer x = 5) next to a box for a process reward model that reads the chain, with its scores marked by a question mark.
7. What is Constitutional AI?Define
A card of three written rules marked illustrative, a prompt with response A and response B, and a dashed box for the preference label whose producer is marked with a question mark, and a note asking what Constitutional AI is.
The rules shown are examples written for this picture.
8. What is GRPO?Define
A prompt 7 × 8 = ? fanning out to four sampled responses (56, 54, 56, 63), each with its advantage marked as a question mark.
Sampled answers are illustrative.
9. What does Stage 1 (SFT) produce in the RLHF pipeline?Define
A pretrained base model and a card of human demonstrations (prompts with human-written replies) feeding Stage 1, with the output of Stage 1 marked by a question mark.
10. You're running PPO-RLHF and drop the β·KL(π_θ||π_ref) term from the reward to speed up training. What's the most likely outcome?Explain
Two stage 3 reward formulas: the current r_total = R_φ - β · KL(π_θ || π_ref), and the version after dropping the KL term, r_total = R_φ, with a note that PPO then runs on r_total for many updates.
11. By 2026, what has largely replaced the PPO step of RLHF for alignment tuning, and why?Explain
The three classic RLHF stages in a row (SFT, RM, PPO with KL) and below them a dashed box with a question mark for what mostly replaces the PPO step by 2026.
12. Why does the Bradley-Terry loss apply a sigmoid to the reward difference R(y_+) - R(y_-)?Explain
Two reward-model scores for one comparison, R(y+) = +2.1 and R(y-) = -0.4, their gap of 2.5, and the Bradley-Terry loss L = -log σ(gap), with the question why the gap goes through σ.
Scores are illustrative.
13. How is the reward model usually built for Stage 2?Explain
A row of boxes for the SFT model (embeddings, a transformer backbone, an LM head producing vocabulary logits) and below it a dashed box asking how the Stage 2 reward model R_φ(x, y) is built from those pieces.
14. How does DPO differ structurally from the three-stage RLHF pipeline?Explain
A classic RLHF flow of SFT, reward model and PPO with KL, and below it a DPO flow that starts with SFT and continues into a dashed box marked with a question mark.
15. Where does GRPO get its reward, compared with classic RLHF?Explain
Two rows scoring the response 51 to 17 × 3 = ?: classic RLHF passes it through a reward model trained on human preference pairs to get a reward, while the GRPO row has a dashed reward source box marked with a question mark.
16. In Stage 3, what does the reward model score, and over what trajectory are PPO advantages computed?Explain
A prompt help me and an 8-token response (Sure , here is a clear answer .) laid out as boxes labelled t=1 to t=8, with two lines below: RM scores marked with a question mark and advantages computed marked with a question mark.
Tokenization is illustrative.
17. A teammate says: "The RM is trained, so its score is ground truth and the KL term only slows PPO." What is wrong with this?Analyze
A teammate's quote saying the trained reward model's score is ground truth and the KL term only slows PPO, above the Stage 3 reward formula r_total = R_φ - β · KL(π_θ || π_ref) with a note that the teammate would drop the second term.

Build It

This lesson uses tiny synthetic "prompts" and "responses" represented as strings. The RM is a linear scorer over a bag-of-tokens representation. There's no real LLM here: what matters is the shape of the pipeline, not the scale. See code/main.py.

Step 1: synthetic preference data

python
PROMPTS = ["help me", "answer me", "explain this"]
GOOD_WORDS = {"clear", "specific", "kind", "thorough"}
BAD_WORDS = {"vague", "rude", "wrong", "short"}
 
def make_pair(rng):
    x = rng.choice(PROMPTS)
    y_good = rng.choice(list(GOOD_WORDS)) + " " + rng.choice(list(GOOD_WORDS))
    y_bad = rng.choice(list(BAD_WORDS)) + " " + rng.choice(list(BAD_WORDS))
    return (x, y_good, y_bad)

In real RLHF this is replaced by human labelers, but the shape, (prompt, preferred_response, rejected_response), stays identical.

Step 2: Bradley-Terry reward model

Linear score: R(x, y) = w · bag(y). Train to minimize the BT pairwise log-loss:

python
def rm_train_step(w, x, y_pos, y_neg, lr):
    r_pos = dot(w, bag(y_pos))
    r_neg = dot(w, bag(y_neg))
    p = sigmoid(r_pos - r_neg)
    for tok, cnt in bag(y_pos).items():
        w[tok] += lr * (1 - p) * cnt
    for tok, cnt in bag(y_neg).items():
        w[tok] -= lr * (1 - p) * cnt

After a few hundred updates, w assigns positive weights to good-word tokens and negative to bad.

Step 3: PPO-like policy on top of RM

Our toy policy produces a single token from a vocabulary. We score the token under the RM, compute log π_θ(token | prompt), add a KL-to-reference penalty, and apply the clipped PPO surrogate.

python
def rlhf_step(theta, ref, w, prompt, rng, eps=0.2, beta=0.1, lr=0.05):
    logits_theta = policy_logits(theta, prompt)
    probs = softmax(logits_theta)
    token = sample(probs, rng)
    logits_ref = policy_logits(ref, prompt)
    probs_ref = softmax(logits_ref)
    reward = dot(w, bag([token])) - beta * kl(probs, probs_ref)
    # ppo-style update on theta, treating reward as the return
    ...

Step 4: monitor the KL

Track mean KL(π_θ || π_ref) every update. If it creeps past ~5-10, the policy has drifted far from π_SFT: either β is too low, or reward hacking is starting. This is the top diagnostic in real RLHF.

Step 5: the production recipe with TRL

Once you understand the toy pipeline, here's the same loop the way a real library user writes it. Hugging Face's TRL is the reference implementation: RewardTrainer handles Stage 2, and PPOTrainer (with a KL-to-reference built in) handles Stage 3.

python
# Stage 2: reward model from pairwise preferences
from trl import RewardTrainer, RewardConfig
from transformers import AutoModelForSequenceClassification, AutoTokenizer
 
tok = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B-Instruct")
rm = AutoModelForSequenceClassification.from_pretrained(
    "meta-llama/Llama-3.1-8B-Instruct", num_labels=1
)
 
# dataset rows: {"prompt", "chosen", "rejected"} — Bradley-Terry format
trainer = RewardTrainer(
    model=rm,
    tokenizer=tok,
    train_dataset=preference_data,
    args=RewardConfig(output_dir="./rm", num_train_epochs=1, learning_rate=1e-5),
)
trainer.train()
python
# Stage 3: PPO against the RM with KL penalty to the SFT reference
from trl import PPOTrainer, PPOConfig, AutoModelForCausalLMWithValueHead
 
policy = AutoModelForCausalLMWithValueHead.from_pretrained("./sft-checkpoint")
ref    = AutoModelForCausalLMWithValueHead.from_pretrained("./sft-checkpoint")  # frozen
 
ppo = PPOTrainer(
    config=PPOConfig(learning_rate=1.41e-5, batch_size=64, init_kl_coef=0.05,
                     target_kl=6.0, adap_kl_ctrl=True),
    model=policy, ref_model=ref, tokenizer=tok,
)
 
for batch in dataloader:
    responses = ppo.generate(batch["query_ids"], max_new_tokens=128)
    rewards   = rm(torch.cat([batch["query_ids"], responses], dim=-1)).logits[:, 0]
    stats     = ppo.step(batch["query_ids"], responses, rewards)
    # stats includes: mean_kl, clip_frac, value_loss — the three PPO diagnostics

Three things the library does for you. adap_kl_ctrl=True implements the adaptive-β schedule: if observed KL exceeds target_kl, β doubles; if below half, β halves. The reference model is frozen by convention, so make sure you don't accidentally share parameters with policy. And the value head lives on the same backbone as the policy (AutoModelForCausalLMWithValueHead attaches a scalar MLP head), which is why TRL reports policy/kl and value/loss separately.

Check: Build It0/8
1. In the production TRL example, what does setting adap_kl_ctrl=True do?Define
The lesson's PPOConfig lines with learning_rate 1.41e-5, batch_size 64, init_kl_coef 0.05, target_kl 6.0 and adap_kl_ctrl=True, with notes that β starts at 0.05 and the observed KL is logged each step.
2. In rm_train_step, w starts at all zeros and lr = 0.1. For y_pos = "clear kind" and y_neg = "rude vague", what are w["clear"] and w["rude"] after one step?Apply
The lesson's rm_train_step code, with the inputs w all zeros, lr 0.1, y_pos clear kind and y_neg rude vague, and a line asking for w[clear] and w[rude].
3. In rm_train_step, a pair arrives with r_pos - r_neg = +6. What happens to the weights?Apply
The lesson's rm_train_step code with a note that a pair arrives with r_pos - r_neg = +6, lr is 0.1, and the weight update is marked with a question mark.
4. Given PROMPTS, GOOD_WORDS and BAD_WORDS in make_pair, which tuple can the function return?Apply
The lesson's make_pair code with the three PROMPTS, four GOOD_WORDS and four BAD_WORDS, and a note asking which tuples the function can return.
5. In rlhf_step with beta = 0.1, the sampled token has RM score 1.0 and KL(probs, probs_ref) = 4.0. What reward does the PPO update use?Apply
The reward line of the lesson's rlhf_step, reward = dot(w, bag([token])) - beta * kl(probs, probs_ref), with beta 0.1, RM score 1.0 and KL 4.0 listed, and the resulting reward marked with a question mark.
6. In the TRL PPOConfig, init_kl_coef = 0.05, target_kl = 6.0 and adap_kl_ctrl = True. A step observes a KL of 15. What happens to β?Apply
The TRL settings init_kl_coef 0.05, target_kl 6.0 and adap_kl_ctrl True above a number line from 0 to 15 with marks at 3.0 (target_kl / 2) and 6.0 (target_kl) and a dot for the observed KL of 15, and a line asking for β after the step.
7. Same TRL setup (init_kl_coef = 0.05, target_kl = 6.0, adap_kl_ctrl = True). A step observes a KL of 2.0, below half of target_kl. What happens to β?Apply
The TRL settings init_kl_coef 0.05, target_kl 6.0 and adap_kl_ctrl True above a number line from 0 to 15 with marks at 3.0 (target_kl / 2) and 6.0 (target_kl) and a dot for the observed KL of 2, and a line asking for β after the step.
8. While running the toy RLHF loop you see mean KL(π_θ || π_ref) climb past 8 and keep rising. How should you read it?Apply
A line chart of mean KL between policy and reference over 40 PPO updates that rises steadily and passes 8 near the end without levelling off.
Illustrative curve, not a measured run.

Pitfalls

  • Over-optimization / reward hacking. The RM is imperfect; π_θ finds adversarial completions that score high but are bad. Symptoms: reward climbs indefinitely while human eval score plateaus or drops. Fix: stop early, raise β, broaden RM training data.
  • Length hacking. RMs trained on helpful responses often implicitly reward length. The policy learns to pad responses. Remediation: length-normalized reward, or RLAIF with a length-aware RM.
  • Too-small RM. The RM needs to be at least as large as the policy. A tiny RM cannot faithfully score the policy's outputs.
  • KL tuning. Too low β → drift and reward hacking. Too high β → policy barely changes. The standard trick is an adaptive β that targets a fixed KL per step.
  • Preference-data noise. ~30% of human labels are noisy or ambiguous. Calibrate by training the RM on agreement-filtered data or use a temperature on BT.
  • Off-policy problems. PPO data is slightly off-policy after the first epoch. Monitor clip fraction as in Lesson 08.
Check: Pitfalls0/9
1. What is reward hacking in RLHF?Define
A loop of policy π_θ producing a response, a frozen reward model scoring it, and the score feeding a PPO update, a note that PPO updates the policy to raise the RM score, and a dashed box for reward hacking in this loop marked with a question mark.
2. How large should the reward model be relative to the policy it scores?Explain
A policy of N parameters generating responses that a reward model of unknown size scores, with notes that the RM starts from an SFT-style checkpoint with a scalar head and its scores steer every PPO update.
3. Reward models trained on helpful responses often favor length. What does this cause, and what is the remedy?Explain
A prompt about a wifi outage with a short response A of 7 words and a longer response B of 31 words that repeats the same two actions, and a line asking for the reward model's scores for A and B marked with question marks.
Responses are illustrative.
4. Many human preference labels are noisy or ambiguous. Which mitigation does the lesson give for training the reward model?Explain
Two small tables listing ten comparison pairs with the preferred side chosen by each of three labelers; three of the ten pairs have labelers who disagree.
Votes are illustrative, chosen so 3 of 10 pairs disagree.
5. What happens to the policy when β is set too high?Explain
The Stage 3 reward formula r_total = R_φ - β · KL(π_θ || π_ref), three boxes for β = 0, 0.1 and 1, and a note asking what happens to the policy when β is set too high.
6. During RLHF fine-tuning, the RM-measured reward keeps climbing every epoch, but a held-out human evaluation of the same outputs is flat or getting worse. What should you suspect?Analyze
A line chart over 8 epochs: the RM-measured reward climbs every epoch while the held-out human evaluation score of the same outputs stays roughly flat and drifts slightly down.
Illustrative curves, not a measured run.
7. A run's reward keeps climbing while its outputs get worse. Before retuning the reward model, what should you check first?Analyze
A line chart of RM reward rising over 40 PPO updates beside two sample outputs for the same prompt, a clear on-topic one at update 5 and a repetitive, padded, off-topic one at update 40.
Illustrative curve and samples.
8. After training, outputs are nearly identical to the SFT model's and the KL to the reference stayed near zero. Which setting is the likely cause?Analyze
A line chart of the KL to the reference staying near zero over 40 PPO updates, beside a card showing the SFT model and the trained model giving nearly identical replies to the same prompt.
Illustrative curve.
9. A team scores a policy with a reward model that is much smaller than the policy, and the scores look unreliable on the policy's outputs. Which pitfall explains this?Analyze
A large policy box beside a much smaller reward model box, and a table of RM scores (0.8, 0.2, 0.9, 0.3, 0.5) against human ranks (1, 4, 5, 2, 3) for five policy outputs that do not line up.
Scores and ranks are illustrative; human rank 1 is best.

Use It

RLHF in 2026 is layered:

LayerTargetMethod
Instruction following, helpfulness, harmlessnessAlignmentDPO (Phase 10 · 08) preferred over RLHF-PPO.
Reasoning correctness (math, code)CapabilityGRPO with verifier reward (Phase 9 · 12).
Long-horizon multi-step tasksAgenticPPO / GRPO with process reward models over steps.
Safety / refusal behaviorSafetyRLHF-PPO with separate safety RM, or Constitutional AI.
Best-of-N at inferenceFast alignmentUse RM at decode time; no policy training needed.
Reward distillationInference computeTrain a small "reward head" on top of a frozen LM.

RLHF was the method in 2022–2024, but by 2026 production alignment pipelines run DPO-first, reaching for PPO only on RM-intensive or safety-critical steps.

Check: Use It0/4
1. What does the Use It table recommend for Best-of-N sampling at inference?Explain
A one-row table from the Use It section with layer Best-of-N at inference, target Fast alignment, and method marked with a question mark, plus notes that a policy and a reward model exist and N candidate responses are sampled for one prompt.
2. You must train a model to solve math problems whose final answers can be checked automatically, and you have no preference labelers. Which approach fits best?Design
Three math problems with known answers (17 × 3 is 51, 144 / 12 is 12, 9² - 4 is 77), a note that a script can check any model answer against the key, and a note that there are zero human preference labelers.
3. A team needs a safety-refusal model but cannot afford enough human labelers for a large preference set. Which approach fits?Design
An example unsafe prompt with the desired behavior of refusing politely, and two bars: a short one for the human labeler budget and a long one for the preference pairs needed.
Prompt and bar lengths are illustrative.
4. You must align a chat model quickly with an existing preference dataset and limited compute, and you do not need a standalone reward model. Which approach fits best?Design
A small table of existing preference pairs (prompt, chosen, rejected) plus three notes: limited compute budget, a standalone reward model is not needed, and the goal is to align a chat model quickly.

Ship It

Save as outputs/skill-rlhf-architect.md:

markdown
---
name: rlhf-architect
description: Design an RLHF / DPO / GRPO alignment pipeline for a language model, including RM, KL, and data strategy.
version: 1.0.0
phase: 9
lesson: 9
tags: [rl, rlhf, alignment, llm]
---
 
Given a base LM, a target behavior (alignment / reasoning / refusal / agent), and a preference or verifier budget, output:
 
1. Stage. SFT? RM? DPO? GRPO? With justification.
2. Preference or verifier source. Humans, AI feedback, rule-based, unit-test-pass, or reward distillation.
3. KL strategy. Fixed β, adaptive β, or DPO (implicit KL).
4. Diagnostics. Mean KL, reward stability, over-optimization guard (holdout human eval).
5. Safety gate. Red-team set, refusal rate, safety RM separate from helpfulness RM.
 
Refuse to ship RLHF-PPO without a KL monitor. Refuse to use an RM smaller than the target policy. Refuse length-only rewards. Flag any pipeline that does not hold back a blind human-eval set as lacking over-optimization protection.
Author's Note

The trap in this lesson is treating the reward model as ground truth once it's trained. It isn't. It's a frozen snapshot of what a few hundred or a few thousand human comparisons implied about quality, on the completions those humans happened to see. Every PPO step afterward is a small adversarial search against that snapshot, whether anyone intends it that way or not.

That's why the KL term is the whole ballgame, not a tuning afterthought. It's the only thing standing between you and a policy that has fully overfit to the RM's blind spots. If you're staring at a run where reward keeps climbing while the outputs keep getting worse, don't go tune the RM first. Check the KL. Nine times out of ten it already blew past the range where the RM's judgments mean anything.

Exercises

  1. Easy. Train the Bradley-Terry reward model in code/main.py on 500 synthetic preference pairs. Measure pairwise accuracy on a held-out 100 pairs. Should exceed 90%.
  2. Medium. Run the toy PPO-RLHF loop with β ∈ {0.0, 0.1, 1.0}. For each, plot RM score vs KL-to-reference over updates. Which runs reward-hack?
  3. Hard. Implement DPO (closed-form preference-likelihood loss) on the same preference data and compare to the RLHF-PPO pipeline in compute used and final RM score achieved.

Key Terms

TermWhat people sayWhat it actually means
RLHF"Alignment RL"Three-stage SFT + RM + PPO pipeline (Christiano 2017, Ouyang 2022).
Reward Model (RM)"The scoring net"Learned scalar function fit to pairwise preferences via Bradley-Terry.
Bradley-Terry"Pairwise logistic loss"P(y_+ ≻ y_-) = σ(R(y_+) - R(y_-)); the standard RM objective.
KL penalty"Stay near the reference"β · KL(π_θ || π_ref) in the reward; the anti-reward-hacking regularizer.
Reward hacking"Goodhart's law"Policy exploits RM flaws; symptoms: reward up, human eval flat.
RLAIF"AI-labeled preferences"RLHF where labels come from another LM instead of humans.
PRM"Process Reward Model"Scores partial reasoning steps; used in reasoning pipelines.
Constitutional AI"Anthropic's method"AI-generated preferences guided by explicit rules.

Further Reading

Code

Ships With