Skip to content

The RLHF Book (Lambert)

optionalcorefundamentalbookrubric 11/122025 · arXiv; Manning print edition (2026) · ~600 min

Nathan Lambert

Status

TL;DR. Nathan Lambert’s book on RLHF and post-training for language models. It is free online at rlhfbook.com, on arXiv (2504.12501) and in print. Its 17 chapters and three appendices cover instruction tuning, reward models, policy gradients for LMs (REINFORCE, RLOO, PPO, GRPO and newer variants), reasoning RL, direct alignment (DPO), rejection sampling, preferences, synthetic data, tools, over-optimization, regularization, evaluation and model character. On this site it is the reference text for stages 4–8 of the course map.

Why it matters now. Most LLM-RL papers assume details that are written down nowhere else: how to aggregate token losses, where to put the KL term, why γ = 1, how ORMs differ from value functions. Chapter 6 alone answers many of the questions the site’s reasoning pages raise.

  • Editions: web version at rlhfbook.com (the changelog says it was last built 30 October 2026); arXiv 2504.12501; the changelog records print, ePub and liveBook editions from Manning in July 2026 and the accompanying course finished in August 2026. A list of errata tracks differences between the web and print versions.
  • Repository: natolambert/rlhf-book. The chapter text is CC-BY-NC-SA-4.0 and the code is MIT (per the README). code/ has reference implementations of instruction tuning, policy gradients (PPO, REINFORCE, GRPO, RLOO), reward models (preference RM, ORM, PRM), DPO, rejection sampling and on-policy distillation.
  • Course: each chapter has a matching lecture in the Lambert course.
RLHF book chapters arranged as the post-training pipeline Top row, left to right: Ch 4 instruction tuning, Ch 10 to 11 preference data, Ch 5 reward models, Ch 6 RL with PPO and GRPO, Ch 7 reasoning with RLVR. Second row: Ch 12 synthetic data feeding instruction tuning, Ch 8 DPO going from preference data straight to the policy, Ch 9 rejection sampling using the reward model, Ch 13 tool use extending reasoning. Bottom row: Ch 14 to 15 over-optimization and KL regularization, and Ch 16 evaluation with Appendix C practical issues, which apply to every stage. Ch 4 IFT / SFT Ch 10–11 Preference data Ch 5 Reward models Ch 6 RL: PPO, GRPO Ch 7 Reasoning, RLVR Ch 12 Synthetic data Ch 8 DPO (no RM) Ch 9 Best-of-N + SFT Ch 13 Tool use Ch 14–15 (+ App B) over-optimization; KL regularization Ch 16 (+ App C) evaluation; variance; practical issues apply to every stage above
Original sketch. The book's chapters arranged as the post-training pipeline, with the cross-cutting chapters on over-optimization, regularization and evaluation.
ChapterKey sectionsPrepares you forLecturePriority
1 Introduction, 2 A Tiny History of RLHF, 3 Training OverviewRLHF in three steps; history from preference RL to the ChatGPT era; problem formulation; canonical recipesChristiano et al., InstructGPTL1Core (Ch 3)
4 Instruction Fine-Tuningchat templates, best practicesThe SFT step before RLL2Skim
5 Reward ModelingBradley–Terry RMs; outcome RMs; process RMs; comparison with value functions; generative RMs (LLM-as-a-judge)Reward modeling, Rewards map, Outcome vs process, Generative RMsL2Core
6 Reinforcement Learningpolicy gradient algorithms (REINFORCE, RLOO, PPO, GRPO and later variants such as GSPO and CISPO); implementation; loss aggregation; asynchronous RL; GAE; double regularizationREINFORCE, PPO, RLOO, GRPO, Dr. GRPO, DAPO, GSPO, Async RLHFL3–L4Core: most important
7 Reasoning and Inference-Time Scalingthe role of RLVR; origins of reasoning models; common training methods; looking aheadDeepSeek-R1, Kimi k1.5, Tülu 3, VAPOL5Core
8 Direct-Alignment AlgorithmsDPO derivation; numerical concerns and weaknesses; DAAs with synthetic data; online vs offline dataDPO, DPO familyL6Core
9 Rejection Samplinggenerate, score, fine-tune; relation to best-of-NSTaR, Evaluating reasoning RL (best-of-N)L2Recommended
10 The Nature of Preferences, 11 Preference Datafrom utility to reward functions; collecting preference data; biases; open questionsReward modeling, Summarize from feedbackL8Recommended (Ch 11)
12 Synthetic Data and Distillationdistillation; on-policy teacher-student distillation; AI feedback; Constitutional AI; rubricsOn-policy distillation, GKD, Constitutional AI, Rubrics as rewardsL7Recommended
13 Tool Use and Function Callinginterleaving tool calls; multistep tool reasoning; MCP; implementationLong-horizon tool agents, RAGENL11Core for search agents
14 Over-Optimizationqualitative and quantitative over-optimization; proxy objectives; over-refusalReward hacking, RM over-optimizationL9Core
15 RegularizationKL divergence in RL optimization; other tools; implicit regularizationPPO (KL term), On-policy distillationL10Core
16 Evaluationprompting formats; reasoning-era prompts; agentic evaluation; unreliable comparisons; contaminationEvaluating reasoning RL, RewardBenchL12Core
17 Crafting Model Character and Productscharacter training; model specsConstitutional AIL13Optional
Appendix A DefinitionsLM, ML, NLP and RL glossaryLook-up while reading—Reference
Appendix B Beyond “Just Style”the chattiness balanceLength correlationsL9Recommended
Appendix C Practical Issuescompute costs; evaluation variance; training variance; spotting bad training jobsEvaluating reasoning RL, RL infra—Recommended
  • Advantages per token. Critic-free methods (REINFORCE with a baseline, RLOO, GRPO) give every token in a completion the same sequence-level advantage. PPO learns a per-token value and uses GAE, so the advantage varies along the sequence.
  • Where the KL goes. RLOO folds the KL into the sequence reward; PPO subtracts a per-token KL from the reward; GRPO adds the KL as a separate term in the loss.
  • γ = 1 is standard in RLHF. The reward scores the whole response, so discounting would down-weight early tokens with no principled reason. The book notes this may change for multi-step agentic settings.
  • Length normalisation is a choice, not a derivation. The book notes that GRPO’s 1/|a| average comes from implementation practice. It compares per-sequence (GRPO), per-token (DAPO) and fixed-length (Dr. GRPO) aggregation with a worked example.
  • Unstable token ratios. GSPO uses sequence-level, length-normalised ratios, and CISPO clips the importance weights themselves (with a stop-gradient) while keeping gradients for all tokens; both target unstable per-token importance ratios in large mixture-of-experts models.
  • Reasoning RL often drops the KL. Chapter 7 notes that as reasoning RL runs grew and verifiable rewards proved less prone to over-optimization, many recipes removed the KL penalty to let the model explore further.

Worked example: the search toy through Chapters 5, 6 and 14

Section titled “Worked example: the search toy through Chapters 5, 6 and 14”

Toy (as on the course map): from s₀ (“no evidence”) the agent can search (−0.1, go to s₁) or answer (right with probability 0.2); from s₁, answer is right with probability 0.9.

  1. Chapter 5 (reward models). A Bradley–Terry RM that scores “search then answer” at 1.5 and “answer immediately” at 0.5 predicts the human preference with probability σ(1) ≈ 0.73. An ORM at s₁ should predict correctness ≈ 0.9; a value function with γ = 1 predicts the same 0.9 there, but is trained by regression on returns instead.
  2. Chapter 6 (aggregation). Suppose a correct rollout is 5 tokens and a wrong one, with extra searches, is 10 tokens, and the group advantages are +1 and −1. Per-sequence normalisation gives each token of the correct rollout weight 0.1 and each token of the wrong rollout 0.05, so the long wrong rollout is penalised half as much per token. Per-token or fixed-length normalisation weights them equally.
  3. Chapter 14 (over-optimization). If the RM also rewards confident-sounding text, the policy can raise its RM score by answering immediately in a confident style. The RM score rises while true correctness stays at 0.2. The KL penalty (Chapter 15) and held-out correctness checks (Chapter 16) are the guards.
  • RL fundamentals are covered only as needed. Read Sutton & Barto or Spinning Up for MDPs, Bellman equations and the policy gradient theorem.
  • It is a practitioner’s synthesis with a focus on open models; some claims about industry practice rest on the author’s experience and cited blog posts rather than controlled studies.
  • The web version keeps changing. Cite the arXiv version or a dated build, and check the errata.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Chapter 6 compares three ways to aggregate per-token losses. Take two sequences with per-token losses [1, 1, 1, 1, 10] and [1, 1, 1, 1, 1, 1, 1, 1, 1, 10]. Compute the batch loss under per-sequence normalisation, per-token normalisation and fixed-length normalisation with L_max = 10, and give the gradient weight on one token of each sequence in each case.

    What a strong answer covers
    • Per-sequence (GRPO): means 14/5 = 2.8 and 19/10 = 1.9, batch loss 2.35. Token weight 1/(2·5) = 0.1 in the short sequence and 1/(2·10) = 0.05 in the long one.
    • Per-token (DAPO): 33/15 = 2.2, every token weighted 1/15 ≈ 0.067.
    • Fixed length (Dr. GRPO): contributions 14/10 = 1.4 and 19/10 = 1.9, batch loss 1.65, every token weighted 1/(2·10) = 0.05.
    • Per-sequence normalisation gives short sequences larger per-token gradients, which creates a length bias: wrong long answers are penalised less per token, and right short answers rewarded more.
  2. Mechanism

    Chapter 6 describes RLOO, PPO and GRPO as placing the KL-to-reference penalty in different places. Say where each puts it, and explain how that placement interacts with how each method assigns advantages to tokens.

    What a strong answer covers
    • RLOO folds the KL into the sequence-level reward before computing the leave-one-out baseline, so the KL shapes the single advantage every token shares.
    • PPO subtracts a per-token KL from the per-token reward, and its value function and GAE then propagate that into a different advantage for each token.
    • Standard GRPO keeps the reward clean and adds a per-token KL as a separate loss term, so it does not enter the group-normalised advantage; the book notes both conventions exist in practice.
    • Critic-free methods (RLOO, GRPO) give every token of a completion the same sequence-level advantage; only PPO's critic gives per-token credit.
  3. Critique

    A paper says GRPO's 1/|a| average over tokens follows from the policy gradient derivation. Use Chapter 6 to critique this, and say what follows for a search agent whose wrong answers tend to be longer.

    What a strong answer covers
    • Chapter 6 says the 1/|a| averaging comes from common implementation practice and is not part of a formal derivation; the policy gradient sums over tokens.
    • Dividing by length changes the effective weight per token, so the gradient is not the plain policy gradient; it is biased towards favouring short correct and long incorrect answers.
    • For a search agent, long wrong answers (for example, many searches then a wrong answer) are penalised less per token, so wrong trajectories can grow longer.
    • Fixes discussed in the book: per-token normalisation (DAPO) or a fixed constant (Dr. GRPO); check by tracking answer length separately for correct and incorrect rollouts.
  4. Connect

    Chapter 5's comparison table lists Bradley–Terry reward models, outcome reward models, process reward models and value functions. Connect these four to the search toy (s₀ no evidence, s₁ evidence in context) and to the site's GAE and outcome-vs-process pages.

    What a strong answer covers
    • BT RM: one score per whole completion, trained on pairs; it can say "search then answer" beats "answer immediately" but gives no per-step signal.
    • ORM: probability that the final answer is correct, trained per token on independent outcome labels; at s₁ a good ORM predicts about 0.9.
    • PRM: scores each step (−1, 0, 1), trained on step labels; it could mark the search step as good before the answer arrives.
    • Value function: expected return from each state, trained by regression (as PPO's critic for GAE); the book notes that with discount 1 it is close to an ORM but trained with a different loss.
  5. What if…

    Chapter 9 presents rejection sampling (generate N completions, score them with a reward model, fine-tune on the best) as a simple baseline for RL. Design an ablation that tells you which parts of a full RL run your search-agent gains really come from.

    What a strong answer covers
    • Arms: SFT only; rejection sampling with best-of-N; the same followed by a second round; online RL (GRPO) from the SFT model; best-of-N at inference without training.
    • Hold fixed the reward model or verifier, prompts, N and total samples generated.
    • Measure held-out accuracy, pass@k, search calls per question and reward-model score versus true correctness (to catch over-optimization).
    • If inference-time best-of-N matches the trained models, the gain is selection rather than learning; if rejection sampling matches RL, the extra online machinery is not paying off.
  6. Design

    Using Chapters 10–11 (preferences and preference data) and Chapter 14 (over-optimization), design a preference-data collection for a search assistant whose answers cite retrieved documents. Cover what is compared, who labels, which biases to control, and how you would know the reward model trained on it is being over-optimized.

    What a strong answer covers
    • Compare two answers to the same query that differ in content, such as citation correctness and completeness, with length and style controlled as far as possible.
    • Labellers with access to the retrieved documents, written guidelines, and some double-labelled items to measure agreement.
    • Biases (Chapter 11): position, length and style preferences, and labeller fatigue; randomise order and record length.
    • Over-optimization (Chapter 14): RM score keeps rising while held-out human preference or citation accuracy plateaus or falls; watch length and refusal rate.

Done with this page?

Status