liveBook · Manning

Chapter 6: Reinforcement learning

What you will learn in chapter 6 of Reinforcement Learning from Human Feedback

Introduces the RLHF training loop in which a policy generates completions, a reward model scores them, and reinforcement learning repeatedly updates the policy.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces the RLHF training loop in which a policy generates completions, a reward model scores them, and reinforcement learning repeatedly updates the policy.

Key terms: policy, reward model, on-policy data, gradient updates

6.1 The role of reinforcement learning in RLHF

This section places RLHF’s reinforcement learning stage in the policy-gradient family, identifies the models it uses, and explains the main ways its algorithms differ.

Key terms: value-based methods, value functions, policy-gradient methods, policy, recently generated samples, reward model, reference model, Kullback–Leibler (KL) penalty, value function, PPO

6.2 Policy gradient algorithms

This section introduces the policy-gradient update, the expected-return objective it serves, and how RLHF estimates that objective from language-model rollouts.

Key terms: policy-gradient update, policy, action, Ψ_t, return, discount factor, γ, collective completion, expected return, value function

6.2.1 Deriving the policy gradient

This section derives the policy gradient from trajectory probabilities, connects it to language-model log probabilities, and introduces lower-variance per-timestep reward signals.

Key terms: trajectory probability, policy, environment transition dynamics, policy parameters, RL objective, log-derivative trick, expectation, Monte Carlo rollouts, language-model policy probabilities, tokens

6.2.2 Vanilla policy gradient

This section introduces vanilla policy gradient and explains why noisy return estimates motivate baselines and advantage-based updates.

Key terms: vanilla policy gradient, policy parameters, overall return, high variance, return, rollouts, sparse rewards, baselines, advantage, unbiased

6.2.3 REINFORCE

This section introduces the components of the REINFORCE update and expresses it as a Monte Carlo policy-gradient update using an advantage.

Key terms: nonnegative factor, offset reinforcement, characteristic eligibility, baseline, learning rate, REINFORCE, Monte Carlo estimator, generalized return, advantage

6.2.4 REINFORCE leave one out

Explains how RLOO estimates an unbiased per-prompt advantage from multiple completions and contrasts its sequence-level updates with PPO and GRPO.

Key terms: REINFORCE leave one out, RLOO, baseline, advantage, trajectories, sequence-level advantage, value network, critic, token-level credit assignment, KL penalty

6.2.5 Proximal policy optimization

This section explains how PPO reuses a batch of policy-generated data, limits overly large updates, and applies its objective to language-model tokens.

Key terms: PPO surrogate objective, policy gradient, current policy, old policy, importance sampling, policy ratio, importance weight, clipping, ε, clipped surrogate objective

6.2.6 Understanding the PPO objective

This section explains how PPO’s clipped objective uses the policy ratio and the sign of the advantage to reinforce or suppress an action without continuing to push an already large change.

Key terms: trust region, policy ratio, clip, policy gradient, positive advantage, clipped objective, gradient, negative advantage

6.2.7 Value functions and PPO

Explains how PPO uses a per-token value function as a learned baseline and how simple rollout-based targets train it without generalized advantage estimation.

Key terms: value function, learned baseline, return, KL penalties, REINFORCE, Monte Carlo returns, rollouts, value loss, policy loss, advantages

6.2.8 Group relative policy optimization

This section explains how GRPO uses groups of completions to estimate advantages without a learned value function, and examines the resulting tradeoffs and variants.

Key terms: GRPO, group-wise GRPO advantage estimate, completions, rewards, value function, policy language model, reference policy, standard deviation, advantage, low reward variance

6.2.9 Group sequence policy optimization

This section explains why GSPO replaces token-level importance ratios with one length-normalized ratio per response when updating a policy from previously collected rollouts.

Key terms: importance sampling, current policy, data-collection policy, distribution mismatch, token-level ratios, clipping, token dropping, GSPO, GRPO, sequence-level importance ratio

6.2.10 Clipped importance sampling policy optimization

This section explains how CISPO clips importance weights while retaining token gradients, and why that tradeoff may help stabilize large-scale RL training.

Key terms: CISPO, importance weights, stop gradient, surrogate objective, advantage, bias-variance tradeoff, per-token importance sampling ratios, MoE models, asymmetric clipping bounds, exploration

6.2.11 Comparing algorithms

This section compares policy-gradient algorithms by their advantage estimates, importance-sampling strategies, and training requirements, while distinguishing DPO from them.

Key terms: advantage, baseline, value function, leave-one-out, group, importance-sampling ratio, clipped objective, clipped importance-sampling weights, stop gradient, completion length

6.3 Implementation

The section explains why language-model RL needs implementation choices beyond the original deep-RL algorithms, focusing on generation-length handling and examples of choices that vary across RLHF systems.

Key terms: EOS token, eos_token, reward model, hard cap, out of distribution, value network initialization, reward normalization, reward whitening, advantage whitening, KL estimators

6.3.1 Policy-gradient basics

This subsection explains how a simple policy-gradient implementation uses a probability ratio and the sign of an advantage to change a model’s token probabilities.

Key terms: ratio, per-token probability ratio, new policy model, reference model, log-probability difference, advantage, loss, logratio, policy model

6.3.2 Loss aggregation tradeoffs

This section compares ways to aggregate token losses, explains their length-dependent gradient effects, and connects those choices to sequence-level and token-level views of RLHF.

Key terms: per-sequence normalization, per-token normalization, fixed-length normalization, L_max, completion_mask, per-token gradients, sequence length, gradient accumulation, numerical stability, variance in loss

6.3.3 Asynchronous RL systems

This section explains why language-model RL systems separate generation from training, how that relaxes exact on-policy execution, and why long, uneven reasoning rollouts complicate the design.

Key terms: on-policy execution, policy gradients, rollouts, actors, learners, nearly on-policy, fully off-policy, weight syncs, reasoning models, sequence-level packing

6.3.4 Truncated importance sampling

This section explains how truncated importance sampling stabilizes language-model RL by capping correction weights, especially when asynchronous sampler and learner systems produce different token probabilities.

Key terms: truncated importance sampling, importance sampling, one-sided upper cap, bounded variance, policy drift, learner–sampler ratio, backend mismatch, effective token distributions, REINFORCE, PPO

6.3.5 Example: PPO

This section walks through a PPO loss computation, explains why clipping stabilizes policy updates, and shows how a single gradient step per sample simplifies PPO and GRPO.

Key terms: reference RL-policy, old logprobs, reference model, KL distance constraint/penalty, KL penalty, returns, advantages, whitens, value function loss, completion mask

6.3.6 Example: GRPO

This section shows how the GRPO implementation differs from PPO in its advantage computation, value model, and KL penalty placement.

Key terms: GRPO, group-wise reward statistics, advantages, value model, vf_loss, KL penalty, loss update, reward function, KL distance, [B, L, N]

6.3.7 RLOO vs. GRPO

This section explains how RLOO computes group-relative advantages and why that makes it conceptually similar to GRPO.

Key terms: RLOO, GRPO, advantage, leave-one-out baseline reward, rloo_k

6.4 Auxiliary topics

6.4.1 Generalized advantage estimation

This section explains how generalized advantage estimation balances bias and variance and how token-level GAE is computed and used in language-model RLHF.

Key terms: GAE, advantage, bias–variance tradeoff, lambda, multistep advantage estimates, TD residual, TD errors, not_done, GAE accumulator, terminal tokens

6.4.2 Double regularization

Explains how PPO-style update constraints and a KL distance penalty can both regularize RLHF, and why the number of gradient steps per batch affects which constraint matters in practice.

Key terms: step-size constraints, KL divergence-based distance penalty, original policy, PPO, REINFORCE, surrogate objective, clip-fraction, probability ratio, clipping interval, clipped branch

6.5 Further reading

This section points to less-central RLHF optimization alternatives and briefly explains how DAPO and VAPO modify existing approaches.

Key terms: P3O, CoPG, ReMax, MDPO, DAPO, GRPO, dynamic sampling, per-token loss, clip hyperparameters, VAPO

6.6 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 5: Reward modeling Chapter 7: Reasoning and inference-time scaling →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.