Lecture 18 · Reasoning Models: RL Algorithms for Post-Training

Scalable AI: Bridging Theory, Understanding, and Practice · Lecture 18。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: UC Berkeley EE 290/194 Scalable AI, Fall 2026 Lecture 14, Reasoning Models (slides lecture14.pdf), §1 “Reasoning models”, §2 “The policy gradient and its fixes” and §4 “What RL does to a language model”; its §3, “RL at scale is an inference problem”, is Lecture 19 here. Also drawn on: Spring 2026 Lecture 15, RL Algorithms for Post-Training (slides lecture_15.pdf). Recommended reading:

  • Foundations: Williams, REINFORCE (1992); Schulman et al., TRPO (arXiv:1502.05477), GAE (arXiv:1506.02438), PPO (arXiv:1707.06347).
  • GRPO and its successors: Shao et al., DeepSeekMath (GRPO, arXiv:2402.03300); DeepSeek-AI, DeepSeek-R1 (arXiv:2501.12948); Ahmadian et al., RLOO (arXiv:2402.14740); Hu, REINFORCE++ (arXiv:2501.03262); Yu et al., DAPO (arXiv:2503.14476); Liu et al., Understanding R1-Zero-Like Training (Dr. GRPO, arXiv:2503.20783); Zheng et al., GSPO (arXiv:2507.18071); MiniMax, MiniMax-M1 (CISPO, arXiv:2506.13585).
  • What RL does: Yue et al., Does RL Really Incentivize Reasoning Capacity? (arXiv:2504.13837); Gandhi et al., Cognitive Behaviors (arXiv:2503.01307); Liu et al., ProRL (arXiv:2505.24864); Cui et al., The Entropy Mechanism of RL for Reasoning LMs (arXiv:2505.22617); Shenfeld et al., RL’s Razor (arXiv:2509.04259); Shao et al., Spurious Rewards (arXiv:2506.10947). Code: code/lecture18/ contains:
  • pg_toy.py: a “reasoning” toy small enough to enumerate every response, so every gradient and every metric is exact;
  • five demos (estimators, GRPO fixes, clipping and ratios, what RL does, RL vs SFT forgetting).

Reading time: ~2.5 hours for the prose; ~20 seconds to run all demos.


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Tell the story of reasoning RL from RLHF to R1-Zero to 2026’s specialist-then-distil recipes, and say why RL became the “capability engine”.
  2. Derive the policy gradient and explain its noise: REINFORCE, baselines (critic, group mean, leave-one-out), why noise grows with response length, which groups carry any signal.
  3. Explain importance ratios and clipping: the three (at scale, four) policies in one update; the per-token approximation; what PPO’s clip does case by case.
  4. Map each 2025 fix to the part of the objective it repairs: dynamic sampling, token-level loss / Dr. GRPO, clip-higher, GSPO, CISPO, the return of the critic.
  5. Reason about what RL does to a model: sharpening vs discovery under pass@k, how the base model shapes the result, entropy and diversity, and why RL forgets less than SFT.

0.2 Prerequisites and scope

  • Prerequisites: Lecture 16 §5 (RLVR, GRPO in one paragraph); Lecture 17 (environments and verifiers); probability (expectations, variance, KL).
  • Scope: the RL update for language models and its 2025–26 variants; what RL does to the model’s distribution.
  • Not in scope: making RL fast at scale (rollout engines, asynchrony, engine mismatch), which is Lecture 19.

0.3 Section → code map

SectionIdeaCode in code/lecture18/
§2.1–2.4REINFORCE, baselines, signal, importance weightspg_toy.py, 01_policy_gradient.py
§3.3–3.5aggregation over tokens, dynamic sampling, overlong responses02_grpo_fixes.py
§2.5, §3.6–3.8the clip, clip-higher, CISPO, GSPO03_clipping_and_ratios.py
§5.2–5.6sharpening, discovery, entropy, diversity, random rewards04_what_rl_does.py
§5.7RL vs SFT forgetting05_rl_vs_sft_forgetting.py

0.4 Notation

  • xx = prompt; y=(y1,…,yT)y = (y_1,\dots,y_T) = response; R(x,y)R(x, y) = reward (here 0/1 from a checker).
  • πθ\pi_\theta = the policy being trained; πold\pi_{\text{old}} = the policy that generated the batch; πref\pi_{\text{ref}} = a fixed anchor (usually the SFT model).
  • ρt=πθ(yt∣x,y<t)/πold(yt∣x,y<t)\rho_t = \pi_\theta(y_t \mid x, y_{<t}) / \pi_{\text{old}}(y_t \mid x, y_{<t}) = per-token importance ratio.
  • AA = advantage; GG = samples (rollouts) per prompt; ϵ\epsilon = clip range.

0.5 The toy

Every experiment uses one toy (pg_toy.py). A problem has one correct answer among M. A response is some “think” tokens followed by an answer, at most L tokens; L think tokens and no answer is a truncated response, which gets reward 0. With L = 8 and M = 5 there are only 41 possible responses per problem, so every expectation can be summed exactly. The policy is a table of logits per (problem, position).

Two ways of initialising it stand for two kinds of base model:

  • a model that rambles when it does not know: answers after more think tokens are less accurate;
  • a model whose thinking helps: later answers are more accurate.

For effects that need parameters shared across problems (sharpening, forgetting), demos 04 and 05 add the smallest such models (§5). The toy cannot tell you the size of an effect in a 30B model. It can tell you whether a mechanism exists, and what causes it, with no sampling noise in the measurement.


1. Reasoning models: how the recipe changed

1.1 From preference models to checkers to environments

periodrewardresponses
2017–2022 (PPO, RLHF, InstructGPT)a reward model learned from human comparisonsshort answers
2023 (DPO)the same comparisons, no explicit RLshort answers
2024–2025 (o1, GRPO, DeepSeek-R1)a checker on the final answerlong chains of thought
2025–2026 (agent RL)environments with toolsmany steps of tool use

1.2 The 2025 recipe and the 2026 recipe

  • DeepSeek-R1 (2025) ran its stages one after another: cold-start SFT → reasoning RL → rejection sampling and SFT → general RL. Each later RL stage could erode skills from an earlier one. DeepSeek-V3.2 merged its RL into one mixed stage to avoid this forgetting (Nemotron 3 Nano did the same; Lecture 20).
  • The 2026 recipes (DeepSeek-V4, Kimi K3, GLM-5.2) run a separate RL job per domain and effort level, often by different teams at once. They then distil all the specialists into one released model, usually by on-policy distillation (Lecture 17 §9).

The Spring 2026 slides frame the shift: before 2025 RL was alignment polish; from 2025 on, it is the capability engine. Three things matured together:

  • verifiable domains: exact answers in math, unit tests in code, scores from environments;
  • long chains of thought as learned search: plan → check → revise → commit, rewarded on the outcome;
  • systems: rollout fleets, asynchronous schedulers, separate training and inference (Lecture 19).

1.3 R1-Zero’s “aha moment”, and AlphaGo’s Move 37

DeepSeek-R1-Zero was trained with RL only, from the base model, with a rule-based reward. Nobody showed it examples of checking its work. After roughly 8,000 steps its responses started to contain “wait”, rechecking and self-correction, while its answers grew longer and more accurate. DeepSeek called this an “aha moment”.

The Fall slides open with a comparison. AlphaGo’s policy network, trained on human games, gave Move 37 against Lee Sedol about a 1-in-10,000 chance; search with a value network chose it anyway. Can RL on a language model come up with genuinely new ideas, or only make existing behaviours more common? We first look at the update that produced R1-Zero’s behaviour (§2–§3), then return to this question with evidence (§5).


2. The policy gradient

2.1 REINFORCE, and why its noise grows with length

The objective is the expected reward, J(θ)=Ex, y∼πθ(⋅∣x)[R(x,y)]J(\theta) = \mathbb{E}_{x,\,y\sim\pi_\theta(\cdot|x)}[R(x,y)]. The log-derivative trick gives its gradient:

∇θJ=E[R(x,y)∑t∇θlog⁡πθ(yt∣x,y<t)].\nabla_\theta J = \mathbb{E}\Big[R(x,y)\sum_t \nabla_\theta \log \pi_\theta(y_t \mid x, y_{<t})\Big].

Sampling a response and weighting its log-probability by its reward gives an unbiased estimate: REINFORCE (Williams 1992). Two problems follow:

  • Every token gets the same credit. In a correct response, the filler and the false start are pushed up exactly as much as the key step. A wrong response with R=0R = 0 contributes no gradient at all.
  • Each token adds a random term, so the noise grows with the response length.

Demo 01 Part B measures the second problem exactly: a policy that thinks with probability 0.8 per position, with answers 40% correct at every position, so length carries no information.

max length Lmean lengthREINFORCE relative varianceRLOO relative variance
11.000.20.2
42.952.01.5
84.166.44.7
325.0010.47.3

The relative variance is E∥g^−Eg^∥2/∥g∗∥2\mathbb{E}\|\hat g - \mathbb{E}\hat g\|^2/\|g^*\|^2 for a group of 8. Going from 1 to 5 tokens multiplies it by 50, and a baseline lowers it without stopping the growth. With chains of thought of 10,000 tokens and one 0/1 at the end, raw REINFORCE is too noisy to train on.

2.2 Baselines

Any baseline b(x)b(x) that does not depend on the sampled response leaves the expected gradient unchanged, because Ey∼π[b(x)∇log⁡π(y∣x)]=b(x)∇∑yπ(y∣x)=0\mathbb{E}_{y\sim\pi}[b(x)\nabla\log\pi(y|x)] = b(x)\nabla\sum_y \pi(y|x) = 0. So we replace RR by an advantage A=R−b(x)A = R - b(x).

methodbaseline bbcost
PPOa learned critic VϕV_\phi for every prefixa second model the size of the policy
GRPOthe mean reward of the G samples for the same promptG rollouts per prompt
RLOOthe mean reward of the other G − 1 samplesG rollouts per prompt
REINFORCE++the mean reward over the whole batchone rollout per prompt

Demo 01 Part A compares them on one problem with G=8G = 8, against the exact gradient g∗g^*:

estimator∥Eg^∥/∥g∗∥\|\mathbb{E}\hat g\| / \|g^*\|cosine to g∗g^*relative variance
REINFORCE (no baseline)0.9981.00001.79
exact value baseline1.0021.00001.17
GRPO mean (the sample included)0.8791.00001.06
RLOO (leave one out)1.0011.00001.38
GRPO mean / std1.7971.00004.38
  • Every baseline keeps the direction and lowers the variance.
  • GRPO’s group mean includes the sample itself, so it shrinks the gradient by (G−1)/G(G-1)/G: here 0.879, predicted 0.875. It is a harmless rescaling, which RLOO removes.
  • Dividing by the std rescales each group. With many problems it changes the relative weight of problems, so it optimises a reweighted objective (§2.3).

The group mean estimates how often the model solves the prompt, the same quantity PPO’s critic learns. GRPO does the critic’s job by sampling more. Advantages are signed: correct samples are pushed up, wrong ones down, and a prompt the model always solves gives A=0A = 0. For example, with 3 of 8 correct the baseline is 0.375: correct samples get +0.63, wrong ones −0.38.

GAE, generalised advantage estimation (Schulman et al.), is PPO’s knob between the critic and the actual return:

A^t=∑l≥0(γλ)lδt+l,δt=rt+γV(st+1)−V(st).\hat A_t = \sum_{l\ge0}(\gamma\lambda)^l\delta_{t+l},\qquad \delta_t = r_t + \gamma V(s_{t+1}) - V(s_t).

  • λ = 0 trusts the critic one step ahead: low variance, but biased when the critic is wrong, which is common on long chains.
  • λ = 1 (with γ = 1, the usual language-model setting) telescopes to “actual return minus the critic’s guess”: unbiased, higher variance.

With a sparse terminal reward, every token’s advantage is “outcome minus how promising this prefix looked”.

2.3 Only problems the model sometimes solves produce a gradient

If all GG samples get the same reward, every advantage is zero. The group cost a full set of rollouts and gave nothing. The probability that a group of GG carries signal is 1−pG−(1−p)G1 - p^G - (1-p)^G. Demo 01 Part C tabulates it:

P(correct)groups of 8 with signalrollouts per useful group
0.0010.8%1,004
0.0533.7%24
0.599.2%8
0.997.7%104

Signal vanishes at both ends. Too hard and already solved both waste rollouts, which is why recipes drop such prompts before training (difficulty filters) and again while forming each batch (dynamic sampling, §3.4).

The std division also reweights problems by difficulty. Per group that has signal, the total ∣A∣|A| is 7.0 at P(correct) = 0.5 and 5.0 at 0.01 with the std. Without it (Dr. GRPO) the totals are 3.5 and 1.8. So dividing by the std gives nearly solved and nearly impossible problems about 1.4× more relative weight. Dr. GRPO removes the division; GRPO keeps it.

2.4 Reusing a batch requires importance weights

A rollout batch takes minutes to hours to generate, so it is reused for several updates. After the first update the samples come from an older policy, and the importance ratio corrects for it:

Ey∼πθ[f(y)]=Ey∼πold[πθ(y)πold(y)f(y)].\mathbb{E}_{y\sim\pi_\theta}[f(y)] = \mathbb{E}_{y\sim\pi_{\text{old}}}\Big[\frac{\pi_\theta(y)}{\pi_{\text{old}}(y)}f(y)\Big].

Over a whole response the ratio is a product of thousands of token ratios, which can explode or vanish. PPO and GRPO use only each token’s own ratio ρt\rho_t. That is TRPO’s surrogate approximation: it ignores how earlier tokens changed the context, so it is accurate only while πθ\pi_\theta stays close to πold\pi_{\text{old}}.

Demo 01 Part D reuses a batch after updates of growing size, against the exact gradient at the new policy:

KL(new ‖ old)no correction: cosineper-token ratios: cosinesequence ratio: cosine / variancelargest sequence ratio
0.110.8670.9921.000 / 2.582.4
0.770.5670.9591.000 / 2.438.3
1.420.3950.9431.000 / 1.5613.9
  • Uncorrected, the gradient turns away from the truth.
  • Per-token ratios stay close but are not exact.
  • The sequence ratio is exact in expectation and has the largest variance. Its weights reach 13.9 even on 6-token responses; over thousands of tokens they explode (§3.8).

Three policies appear in one update:

  • the policy being optimised, πθ\pi_\theta (the numerator);
  • the one that generated the batch, πold\pi_{\text{old}} (the denominator);
  • a fixed anchor, πref\pi_{\text{ref}}, for an optional KL penalty.

At scale there is a fourth: the inference engine’s copy of πold\pi_{\text{old}}, which computes slightly different probabilities from the trainer’s (Lecture 19). Many reasoning recipes drop the KL penalty. DAPO’s argument is that a model learning long chains of thought has to move far from the SFT model.

2.5 The clip: one batch cannot move a token too far

Jclip=1G∑i1∣oi∣∑tmin⁡(ρi,tAi,  clip(ρi,t,1−ϵ,1+ϵ)Ai).J_{\text{clip}} = \frac{1}{G}\sum_i \frac{1}{|o_i|}\sum_t \min\big(\rho_{i,t}A_i,\; \text{clip}(\rho_{i,t}, 1-\epsilon, 1+\epsilon)A_i\big).

Case by case, with ϵ=0.2\epsilon = 0.2:

  • If a token was good (A>0A > 0), its gain stops once its probability has risen to 1.2×1.2\times its old value. Past that point it gives no gradient for the rest of the batch.
  • If it was bad (A<0A < 0), its penalty stops once its probability has fallen to 0.8×0.8\times.
  • The clip only stops movement in the direction the advantage pushes. A token that moved the other way still gets a gradient.

The clip is a cheap stand-in for TRPO’s trust region. Because it bounds a ratio, its limit in probability is proportional to where a token starts. Demo 03 Part A computes it:

start probabilitymax after one batch, ε = 0.2with clip-higher, ε_high = 0.28
0.50.6 (+0.1)0.64 (+0.14)
0.010.012 (+0.002)0.0128 (+0.0028)

A likely token can gain 0.1 per batch, a rare one only 0.002. §3.6 shows why that matters.


3. The 2025 fixes, one part of the objective each

3.1 The map

The Fall slides organise the 2025 literature by which part of the objective each fix targets:

partproblemfixes
which groupsgroups with identical rewards cost rollouts and give no gradientdifficulty filters, dynamic sampling
averagingdividing by length lets long wrong answers off lightlytoken-level loss, Dr. GRPO
clipa symmetric clip keeps rare tokens from gaining probabilityclip-higher
ratioa few outlier token ratios dominate a long responseGSPO, CISPO
baselinePPO’s critic is costly and hard to fit to long chainsGRPO’s group mean; GLM-5.2 brings a critic back for agent RL

3.2 DAPO

DAPO (ByteDance Seed and Tsinghua’s AIR, 2025) is a diagnosis-and-repair package for long-chain GRPO, not a new family. On Qwen2.5-32B base it took AIME 2024 from 30 to 50 (avg@32), adding one change at a time:

change (cumulative)AIME 2024
GRPO30
+ overlong filtering36
+ clip-higher38
+ soft overlong penalty41
+ token-level loss42
+ dynamic sampling50

Each gain depends on the order the changes were added. The open recipes of 2025 converged on the same few choices:

  • DeepSeek-R1 used plain GRPO with a KL penalty;
  • nearly every later report filtered problems by difficulty. Those reports are Kimi k1.5, DAPO, Open Reasoner Zero, INTELLECT-2, Llama-Nemotron, MiMo, Skywork OR-1, Magistral and GLM-4.5;
  • most dropped the KL penalty and averaged the loss over tokens.

3.3 How the loss is averaged over tokens

GRPO divides each response’s loss by its own length, 1/∣oi∣1/|o_i|. Two wrong answers to the same prompt, both with A=−1A = -1:

  • the 100-token one pushes each of its tokens down by 1/1001/100;
  • the 1,000-token one only by 1/10001/1000.

A long wrong answer spreads its penalty over more tokens. Dr. GRPO observed that under GRPO wrong answers grew to ~2,000 tokens, and without the division they fell back to ~950 at the same reward. Two repairs exist:

  • DAPO’s token-level loss divides by the total number of tokens in the batch;
  • Dr. GRPO divides by a constant.

Either way every token gets the same weight within a batch.

Demo 02 isolates the length dynamics. It trains only the “think” logits, so the accuracy of an answer given after tt think tokens is fixed by the base model, and the policy can only learn when to answer:

base modellossstep 1: lengthstep 300: lengthaccuracy
thinking helpsGRPO (1/|o|, std)2.005.9461.6%
thinking helpsDr. GRPO2.006.4264.8%
thinking helpstoken-level2.006.0261.4%
ramblesGRPO1.981.11 (wrong answers 1.16)58.9%
ramblesDr. GRPO1.981.08 (wrong 1.11)59.2%
ramblestoken-level1.981.06 (wrong 1.09)59.4%
  • When thinking helps, RL lengthens responses on its own, the R1-Zero pattern in miniature.
  • GRPO’s averaging slows every length change. It gives each response the same total weight however long it is, so long correct responses are reinforced less per token, and long wrong ones penalised less.

In this toy the bias shows as slower length change, not the runaway growth Dr. GRPO saw in a real model; we report what we measured.

3.4 Dynamic sampling

DAPO drops groups whose rewards are all equal and samples more prompts until the batch is full. Demo 02 Part C trains on 20 hard (2%), 20 medium (30%) and 20 easy (95%) problems:

step 100rollouts by thenat ~19,500 rollouts
static batches69.6%12,80089.7% (step 150)
dynamic sampling87.7%26,54472.2% (step 75)

Dynamic sampling makes every step count, and pays for it in rollouts. Per rollout, static batches did better in this toy. Whether it pays depends on whether gradient steps or rollouts are the bottleneck. At scale rollouts usually are (Lecture 19), which is one reason recipes also filter prompts before training: Nemotron removes prompts its SFT model already solves 100% of the time (Lecture 20).

3.5 Responses that run out of room

A response cut off at the length limit gets reward 0 and is treated as a negative example, punished for running out of room rather than for being wrong. DAPO has two fixes:

  • overlong filtering masks the loss of truncated responses;
  • soft overlong punishment lowers the reward gradually as a response nears the limit.

Demo 02 Part D (L = 6, thinking helps up to the last position):

truncated responsesaccuracymean lengthtruncated
reward 0 (a negative)73.0%5.591.1%
left out of the loss73.3%5.733.4%
soft length penalty (last 2 positions)46.5%3.770.2%
  • Filtering and the plain negative end at the same accuracy here. Filtering lets more responses run out, since running out is no longer punished.
  • The soft penalty cost 27 points, because in this task the best answers come at the end of the budget. A length penalty is a prior that long is bad; it helps when that is true of the task (DAPO’s AIME setting) and hurts when it is not.

3.6 Clip-higher and rare tokens

MiniMax and DAPO both noticed that the tokens the clip removes are often rare words like “However”, “Recheck”, “Wait”: tokens that start with low probability and open new behaviour. By §2.5’s arithmetic a symmetric clip lets them gain almost nothing per batch. With a symmetric clip, DAPO saw entropy fall to almost zero and AIME accuracy stall near 25%. Clip-higher raises only the upper bound (0.2 → 0.28), letting rare good tokens grow faster while bad tokens are still suppressed at 0.8.

Demo 03 tests the mechanism. Reusing each batch for 4 updates, and with a “trap” (each problem has a common half-credit answer at 40% and a rare full-credit answer at 2%):

updateproblems that settle on the full-credit answer (5 seeds)
on-policy, 1 update per batch62.0%
4 updates, no clip56.0%
4 updates, clip 0.234.7%
4 updates, clip-higher 0.2 / 0.2835.7%
4 updates, CISPO (weight capped at 1.28)35.7%
  • Bounding the ratio during reuse holds back the rare answer. The likely mechanism is Part A’s: the rare answer’s ratio reaches the bound after one update, while the common answer keeps rising within it.
  • We could not reproduce clip-higher’s gain: its +0.08 changed nothing measurable here. DAPO measured it on a 32B model whose entropy falls across all prompts at once, a shared-parameter effect a per-problem table cannot show (§5.6 shows one).

3.7 CISPO: cap the weight, keep the gradient

Past the clip, PPO and GRPO drop the token’s gradient entirely. MiniMax-M1’s CISPO keeps every token and caps its weight:

∇J=E[sg(min⁡(ρi,t,ρmax⁡)) Ai ∇log⁡πθ(oi,t)],\nabla J = \mathbb{E}\big[\text{sg}(\min(\rho_{i,t}, \rho_{\max}))\,A_i\,\nabla\log\pi_\theta(o_{i,t})\big],

where sg is stop-gradient: the capped weight is a constant, and every token keeps contributing.

On Qwen2.5-32B, CISPO matched DAPO’s AIME accuracy in half the training steps. MiniMax-M1 was trained with it on 512 H800s for three weeks (about $535K), with 1M-token native context. In demo 03 Part B, reusing each batch 4 times:

  • the clip removes the gradient of 50% of the tokens after the first update;
  • CISPO learns as fast as an unclipped update (91.9% vs 91.0% at step 50);
  • the clipped update is slower (87.2%), clip-higher in between (88.3%).

3.8 GSPO: one ratio per response

The reward belongs to the whole response, but GRPO clips each token separately, so a few outlier ratios can dominate. GSPO (Qwen) uses one ratio per response, the geometric mean of its token ratios, and clips that:

si=(∏tρi,t)1/∣oi∣=exp⁡(1∣oi∣∑tlog⁡ρi,t).s_i = \Big(\prod_t \rho_{i,t}\Big)^{1/|o_i|} = \exp\Big(\frac{1}{|o_i|}\sum_t\log\rho_{i,t}\Big).

Demo 03 Part D simulates per-token log-ratio noise of σ = 0.02 (essentially no token falls outside [0.8, 1.2]):

tokensproduct of ratios (5%–95%)geometric mean (5%–95%)
1000.71 – 1.40.9966 – 1.0032
4,0000.13 – 7.70.9995 – 1.0005
1,000 with 0.5% outlier tokens0.022 – 440.996 – 1.004

The geometric mean stays near 1 and can be clipped tightly, and outliers move it far less than they move the product. Outliers are what a mixture-of-experts model produces when a token is routed to different experts at rollout and at training. GRPO needed routing replay, recording the rollout’s expert choices and reusing them during training, to stay stable on Qwen3-30B-A3B. GSPO did not, and reached the same reward with less compute; it was used for Qwen3 Instruct, Coder and Thinking.

3.9 The critic, gone and back

With the usual GAE setting (λ = 0.95), DeepSeek found PPO clearly worse than GRPO on MATH. With λ = 1 it came close. GRPO matched it without training a second, policy-sized model, and Open Reasoner Zero and VAPO showed a critic can still train well.

For long agent tasks, a GRPO group waits for its slowest rollout (Lecture 19). GLM-5.2 went back to one rollout per prompt with a value model (single-rollout asynchronous optimisation, SAO). In its comparison, vanilla GRPO collapsed after ~160 steps, and GRPO with an off-policy correction ended a few points below.

3.10 The consensus, and what matters more than the name

The Spring slides’ choosing guide:

settingmethod
a critic and dense rewardsPPO
a verifier and multiple samples per promptGRPO or DAPO
long MoE responsesGSPO
heavy off-policy reuseCISPO

But what matters more than the algorithm’s name is entropy control, reward normalisation per task and difficulty, and credit assignment at the right granularity.

ScaleRL (Meta, Oct 2025, >400,000 GPU-hours) fit compute–performance curves to RL runs and separated two kinds of change:

  • changes that move the asymptote: the prompt and task distribution, verifier precision, architecture, environment richness;
  • changes that only move compute efficiency: loss aggregation, normalisation, off-policy reuse, clipping and baseline variants.

Do not confuse “learns faster” with “will ultimately learn more”. Much of 2025’s algorithm work improved efficiency. The lever on the end point is usually reward and environment quality (Lecture 17).


4. Off-policy reuse and agent RL, briefly

  • Reuse versus staleness. Off-policy reuse trades cost for correctness. Three quantities govern it:
    • the reuse factor (updates per generated batch);
    • the staleness (how far the policy has drifted from the one that sampled);
    • the quality of the correction.
  • Kimi k1.5 made context length an RL scaling axis (up to 128K). It uses partial rollouts: long responses are continued in later steps instead of regenerated. It then distils long reasoning into short (“long2short”).
  • Agent RL interleaves actions and observations: τ=(s0,a1,o1,s1,… )\tau = (s_0, a_1, o_1, s_1, \dots).
    • Latency varies by 100× between trajectories, and an early bad retrieval poisons 50 later steps.
    • The reward is composite: task success + process − latency − tool cost − unsafe actions, as MiniMax M2.5 reports.
    • Its failure modes are tool farming, context bloat, environment over-fit, credit leakage (process rewards for busy activity) and non-stationary tools.
  • Systems. All of this turns RL into a systems problem, the subject of Lecture 19.

5. What RL does to a language model

5.1 No tree search, no process rewards

Many expected o1-style models to use tree search, as AlphaGo did, plus graders that score each reasoning step (process reward models). DeepSeek tried both and dropped them:

  • a reasoning step is hard to define and grade, and a step grader gets gamed;
  • the space of token sequences is too large for tree search, and the value model it needs is hard to train.

This removes the part of AlphaGo that found Move 37. In the open recipes, exploration is limited to what the model itself samples.

5.2 Sharpening and discovery look different under pass@k

Pass@k counts a problem as solved if any of k samples is right (Lecture 16 §6.3). Pass@1 measures what the model does by default; pass@k at large k measures what it can reach with enough tries. Two outcomes are possible:

  • Sharpening. The correct answer was sampled, say 8% of the time. RL raises pass@1, while large-k pass@k was already near 1.
  • Discovery. The correct answer was sampled 1 in 10,000 times. RL raises pass@k even at large k.

These labels describe outcomes, not mechanisms, and “almost never sampled” depends on how large k is. Move 37 was a discovery.

Yue et al. compared base and RL models on math and code benchmarks up to 32B. For Qwen-2.5-32B on AIME 2024, RL raised pass@1 from 9% to 27%, but at k = 1,024 the base model solved 90% and the RL model 83%. The crossover appeared on every benchmark they tested, and the RL model lost some problems the base could solve. (At very large k an answer-only benchmark can also credit lucky guesses, which flatters the base model.)

Demo 04 reproduces the crossover and shows its cause. Its policy, SharpPolicy, has one shared sharpness ese^s (an inverse temperature for all problems) and per-problem corrections δx\delta_x: logits =es⋅base+δ= e^s\cdot\text{base} + \delta. The 100 problems are of three types:

  • type A: the correct answer is the base model’s favourite;
  • type B: it is the 4th choice, at ~10%;
  • type C: it has probability 10−410^{-4}.
model (200 RL steps)pass@1pass@16pass@256pass@1024
base14.9%78.0%85.4%86.5%
shared sharpness only (rises to 31)44.8%50.4%51.7%53.0%
shared sharpness + per-problem83.0%85.0%85.0%85.0%
per-problem only (no sharing)82.4%85.0%85.4%86.6%
  • Sharpening alone raises pass@1 (every A problem’s favourite answer is right) and drops pass@1024: B and C problems lose correct answers they could reach by sampling.
  • With per-problem parameters as well, the base still wins from k = 61 on.
  • Without a shared parameter, nothing is lost at large k.

In this toy the crossover has one cause: a shared parameter that makes every rarely sampled answer rarer, including correct ones RL never saw. Real models share all their parameters.

5.3 The base model shapes what RL finds

  • The behaviour was already there. R1-Zero’s “wait” already appeared in DeepSeek-V3-Base: prompted with math, it wrote it and corrected itself occasionally, before any RL.
  • Same RL, different bases. Under the same RL on a number game (Countdown), Qwen-2.5-3B reached ~50% within 50 steps, while Llama-3.2-3B stayed near zero for 60 steps and ended near 35%. Qwen’s base already checked its work and backtracked. Training Llama briefly on examples with those behaviours before RL brought it to ~73% (Gandhi et al.).
  • Distillation can beat RL on a small model. DeepSeek distilled R1 into Qwen-32B and got 72.6 on AIME 2024, against 47.0 for RL on the same base model.

5.4 Weak signals gave large gains on Qwen models

  • Spurious rewards. On Qwen2.5-Math-7B, a reward assigned at random raised MATH-500 by 21.4 points; the correct reward raised it by 29.1. The same random reward did nothing for Llama or OLMo models.
    • Shao et al. attribute the random-reward gain to the clip, which favours behaviour the model already prefers. For Qwen-Math that is reasoning in code, which went from 65% to ~90% of responses.
    • Wu et al. found signs that Qwen2.5 saw MATH-500 in pre-training. On new synthetic tasks it could not have seen, only correct rewards helped.
    • Demo 04 Part F could not reproduce the clip mechanism in a tabular toy, even with an 86% favourite answer. Random rewards only diffused the distribution (a right favourite fell from 87.5% to 56.7%), so the effect depends on something the toy lacks.
  • Fixing the first words. Starting OLMo-3-7B’s response with ”.\n\nOkay” raised MATH-500 from 42% to 78%, close to the RL model’s 75%. In these short runs (at most 300 steps), the largest change RL made was raising that opening’s probability from 0.14 to 0.65. Replacing “okay” with “chicken” in mid-training data raised the “chicken” opening from 2% to 37%; openings seem to work because of what followed them in training data (Wang et al.).
  • Training-free sharpening. Sampling from a sharpened version of the base model’s distribution, with no training, reached 74.8 on MATH-500, against 78.5 for GRPO and 49.6 for the base (Karan and Du), at the cost of many extra forward passes per answer.
  • Weight perturbation. On GSM8K, the share of small random weight changes that did at least as well as the model rose from 0% at 0.5B to 64% at 32B, and voting over the best 50 of 5,000 beat GRPO on most tasks, at 50× the inference cost (Gan and Isola).

Both studies compared against GRPO on models of 8B or fewer.

5.5 With long training, RL can solve what the starting model never solved

With more than 2,000 RL steps on varied tasks, ProRL took a 1.5B model (itself distilled from R1) from 0% at every k to 100% at k = 256 on a planning puzzle it was never trained on. Several studies report RL combining skills the model already had into combinations it had never seen. RL helped most on problems just beyond what the model could already do, and for agents the advantage of RL grew with k. The reported cases share three ingredients:

  • long training;
  • tasks that compose known skills;
  • a reward on problems at the edge of competence.

Demo 04 Part C runs 2,000 steps on the 15 C problems (correct answer at 10−410^{-4}):

modelC problems solved after 200 stepsafter 2,000 stepspass@1024 after 2,000
shared sharpness + per-problem0 / 150 / 1585.0%
per-problem only0 / 153 / 1590.0% (base 86.5%)

Discovery needs the answer to be sampled at all. Without sharpening, ~5,000 samples per problem eventually hit some correct answers, and RL then reinforced them. With sharpening, the answers became rarer still. ProRL kept a KL penalty, which most recipes drop, and periodically reset its reference model, which is what kept it improving past 2,000 steps.

The strongest frontier results come without base-model comparisons:

  • Gemini Deep Think and an OpenAI experimental model reached gold-medal level at IMO 2025 (35 of 42);
  • DeepSeekMath-V2 scored 118 of 120 on Putnam 2024 with RL against a trained proof verifier.

These systems use far more RL compute and longer reasoning than the controlled studies, and none reports the base model’s pass@k on the same problems. So they cannot say how much RL found and how much it selected.

5.6 Entropy, and fewer distinct answers

In Cui et al.’s runs, accuracy during RL fit R=−a eH+bR = -a\,e^{H} + b, where HH is the policy’s entropy. Most of the gain came early, while entropy dropped quickly, and the fit predicts that accuracy stops improving as entropy approaches zero. This is the collapse that clip-higher, entropy bonuses and fewer reuse steps are meant to slow.

Demo 04 Part D fits the same form to our run, with R2=0.945R^2 = 0.945. The fit’s value at zero entropy, 82.6%, is close to where the run ends: 83.0% at H=0.34H = 0.34. Once entropy is gone, so is the room to improve.

Diversity shrinks with it. After RL, ProRL-1.5B gave fewer distinct final answers to the same prompt and lost about four times as many reachable correct answers as it gained (Wu et al., “The Invisible Leash”), while also being the model that solved the new puzzle. One model can show both patterns. In demo 04 Part E:

  • answers above 1% probability fall from 10.9 to 2.0 per problem;
  • the expected number of problems 1,024 samples solve falls from 86.46 to 85.00, all of it on the C problems.

Attempts to keep diversity include training on pass@k instead of pass@1, and keeping a KL term to the base model.

5.7 RL forgets less than SFT

Shenfeld et al. compared fine-tuned models across math, science, tool use and robotics. At the same accuracy on a new task, RL kept more of the model’s earlier abilities than SFT did. The KL divergence from the base model, measured on the new task, predicted how much was forgotten. Their argument: because RL samples from itself, it moves to a nearby solution.

Demo 05 tests it on a shared linear policy. The old task B is known at 90.8%. On the new task A, each problem has two correct forms: one the base leans toward, and one a teacher writes. At 80% accuracy on A:

methodpoints of B lostKL on AKL on B
SFT on the teacher’s answers20.01.990.715
SFT on the model’s own correct samples11.20.640.233
RL (GRPO, either form rewarded)6.00.760.097
  • Across 9 runs (three methods × three targets), KL on A predicts forgetting with correlation 0.867. SFT on the teacher at 60% and RL at 90% have nearly the same KL (1.07 vs 1.04) and lose nearly the same (10.8 vs 10.7 points).
  • KL is a predictor, not the whole story. Self-sampled SFT ends closer to the base on A than RL and still forgets more. A plausible reason: matching a fixed target pushes every wrong answer down, while RL moves only what its samples touch.

The flip side is the slide’s point: many recipes drop the KL penalty, yet RL still stays close. If the argument holds, the same pull that limits forgetting also limits how far RL explores.

5.8 The evidence so far points both ways

consistent with sharpeningconsistent with discovery
random rewards helped Qwen modelsolympiad-level proofs (without a base comparison)
forcing an opening word recovered most of a short run’s gainlong RL taught a puzzle the starting model never solved at any k
better sampling and weight perturbation reached much of the gainseveral studies report RL composing known skills in new ways
the base wins pass@k at large k; answer diversity shrinksfor agents, the advantage of RL grows with k

Most controlled studies use models of 8B or fewer, short runs, and math benchmarks that may be in pre-training data. Frontier labs run RL far longer but do not publish base-model comparisons. Language-model RL differs from AlphaGo in search, value estimates and how far it may move from its start. Settings that relax these (long runs, checked proof verifiers, long agent tasks) are where discovery is most likely to show up. How much RL adds, and when, is still open.


6. Summary

  • RL became the capability engine of post-training once checkers, long chains of thought and rollout systems matured together. The 2026 recipes train RL specialists per domain and distil them into one model.

  • The policy gradient credits every token of a response equally, and its noise grows with length (×50 from 1 to 5 tokens in our toy). Baselines remove much of the noise without bias:

    • GRPO’s group mean shrinks the gradient by (G−1)/G;
    • RLOO is exact;
    • the std reweights problems by difficulty.

    Only mixed groups carry signal.

  • Reusing a batch needs importance ratios. Per-token ratios are an approximation valid near πold\pi_{\text{old}}, and the clip bounds how far one batch moves a token, in proportion to its starting probability.

  • Each 2025 fix repairs one part of the objective.

    • Which groups: dynamic sampling, faster per step and not per rollout in our toy.
    • Averaging: token-level loss or Dr. GRPO; GRPO’s 1/|o| slows length changes.
    • The clip: clip-higher; bounds on the ratio hold back rare answers during reuse.
    • The ratio: GSPO’s geometric mean stays near 1 where products explode; CISPO keeps clipped tokens’ gradients.
    • The baseline: GRPO’s group mean, and a critic back for long agent tasks.

    Most of this improves efficiency; the asymptote is set by rewards and data.

  • RL sharpens what the model can already sample. Pass@1 rises and pass@k at large k can fall, because shared parameters make rare answers rarer. Discovery happens when correct answers are sampled at all, in long runs that keep entropy. Accuracy tracks entropy, and diversity shrinks.

  • RL forgets less than SFT, because it stays near the base model. KL on the new task predicts forgetting, roughly.

7. Common pitfalls

  • Raw REINFORCE on long responses; a group mean but no check for all-equal groups.
  • Training on prompts the model always or never solves.
  • Reusing a batch without ratios, or with full sequence ratios on long responses.
  • Reading GRPO’s std division as harmless: it reweights problems.
  • Per-response length normalisation when lengths matter.
  • A soft length penalty on a task whose best answers are long.
  • Comparing algorithms per step when rollouts are the bottleneck (or the reverse).
  • Mistaking faster learning for a higher ceiling.
  • Claiming RL “taught reasoning” from pass@1 alone, without pass@k of the base model.
  • Letting entropy collapse early: the run stops improving there.
  • Dropping the KL term without watching diversity and forgetting.

8. Exercises

  1. Baseline algebra. Show that Ey∼π[b ∇log⁡π(y)]=0\mathbb{E}_{y\sim\pi}[b\,\nabla\log\pi(y)] = 0 for any constant b. Then show that GRPO’s group-mean advantage, with the sample included, gives E[g^]=G−1Gg∗\mathbb{E}[\hat g] = \frac{G-1}{G}g^* for binary rewards.
Answer

E[b∇log⁡π]=b∑yπ∇log⁡π=b∇∑yπ=b∇1=0\mathbb{E}[b\nabla\log\pi] = b\sum_y \pi\nabla\log\pi = b\nabla\sum_y\pi = b\nabla 1 = 0. For GRPO, Ai=ri−1G∑jrj=G−1Gri−1G∑j≠irjA_i = r_i - \frac1G\sum_j r_j = \frac{G-1}{G}r_i - \frac1G\sum_{j\neq i}r_j. The second term is independent of sample ii, so it is a valid baseline and contributes zero in expectation; the first scales the REINFORCE term by (G−1)/G(G-1)/G. Demo 01 measured 0.879 for G = 8 (0.875 predicted).

  1. Signal. A batch has 512 prompts: 40% that the model solves 99% of the time, 40% at 50%, and 20% at 0.1%. With G = 16, what fraction of groups carries signal? How many rollouts per useful group?
Answer

1−p16−(1−p)161-p^{16}-(1-p)^{16}: p = 0.99 → 14.9%; p = 0.5 → ~100%; p = 0.001 → 1.6%. Weighted: 0.4 × 0.149 + 0.4 × 1.0 + 0.2 × 0.016 = 46.3%. Rollouts per useful group = 16 / 0.463 ≈ 35. Filtering the solved and unsolvable prompts first would bring it close to 16.

  1. Clip arithmetic. A token has probability 0.02 under πold\pi_{\text{old}}, and its advantage is positive. What is the most its probability can reach within one batch with ε = 0.2? With ε_high = 0.28? How many batches to reach 0.5 if every batch hits the bound?
Answer

0.024 and 0.0256. From 0.02 to 0.5 is a factor of 25: log⁡25/log⁡1.2=17.7\log 25/\log 1.2 = 17.7 batches vs log⁡25/log⁡1.28=13.0\log 25/\log 1.28 = 13.0. In practice the token is not pushed by every batch, so the gap is larger, which is DAPO’s argument.

  1. Length normalisation. Two wrong responses with A = −1 are 50 and 500 tokens long. Under GRPO’s per-response averaging, what does each token of each get? Under a token-level loss in a batch of 1,000 tokens? Which is the unbiased policy gradient?
Answer

GRPO: −1/50 and −1/500 per token (each response’s total is −1). Token-level: −1/1000 per token for both, so the long one’s total is ten times the short one’s. The unbiased gradient sums A∇log⁡πA\nabla\log\pi over tokens with no per-response division (up to a constant), which is what Dr. GRPO and the token-level loss do.

  1. The crossover. A model has two problems. On problem 1, P(correct) is 0.5 at base and 0.9 after RL. On problem 2, it is 0.01 at base and 0.0001 after RL. Compute pass@1 and pass@256 for both models.
Answer

Base: pass@1 = (0.5 + 0.01)/2 = 25.5%; pass@256 = (1 + (1 − 0.99^256))/2 = (1 + 0.924)/2 = 96.2%. RL: pass@1 = (0.9 + 0.0001)/2 = 45.0%; pass@256 = (1 + (1 − 0.9999^256))/2 = (1 + 0.025)/2 = 51.3%. RL wins at k = 1 and loses badly at k = 256: sharpening.

  1. Forgetting. In demo 05, why might RL stay closer to the base model than SFT on a teacher’s answers, even though both reach 80% on the new task?
Answer

RL samples from the model and reinforces the correct answers it already produces. The base leaned toward form 1, so RL raised form 1, a small move. SFT on the teacher pulled every problem to form 2, which the base gave 5%: a large move in distribution (KL 1.99 vs 0.76), and with shared weights a large move on the old task too.

The post-training assignment (A3 in both offerings) includes an RL stage. This lecture’s lessons are its prerequisites:

  • check what fraction of your groups carries signal;
  • report the aggregation, clip and KL settings you used;
  • watch entropy and response length;
  • evaluate pass@k for both the starting and the trained model.

No solutions are given here.

10. Research directions

  • When does RL discover? Controlled studies at larger scale and longer horizons; base-model pass@k for frontier results.
  • Exploration without tree search. Entropy control that does not slow learning; pass@k objectives; resetting references.
  • Credit assignment for long chains and agents without gameable process rewards.
  • Algorithms vs asymptotes. Which changes move the ceiling (ScaleRL’s distinction), measured rather than assumed.
  • Forgetting and distance. When KL to the base predicts forgetting and when it does not (demo 05’s self-sampled SFT).

11. Further reading

  • Schulman et al., TRPO, GAE, PPO (arXiv:1502.05477, 1506.02438, 1707.06347); Williams (1992).
  • DeepSeekMath (arXiv:2402.03300); DeepSeek-R1 (arXiv:2501.12948); Kimi k1.5 (arXiv:2501.12599); Open Reasoner Zero (arXiv:2503.24290); VAPO (arXiv:2504.05118).
  • DAPO (arXiv:2503.14476); Dr. GRPO (arXiv:2503.20783); RLOO (arXiv:2402.14740); REINFORCE++ (arXiv:2501.03262); GSPO (arXiv:2507.18071); MiniMax-M1 / CISPO (arXiv:2506.13585); ScaleRL (arXiv:2510.13786).
  • Yue et al. (arXiv:2504.13837); Gandhi et al. (arXiv:2503.01307); Shao et al., Spurious Rewards (arXiv:2506.10947); Wu et al., Reasoning or Memorization (arXiv:2507.10532); Karan and Du (arXiv:2510.14901); ProRL (arXiv:2505.24864); Cui et al. (arXiv:2505.22617); Wu et al., The Invisible Leash (arXiv:2507.14843); Chen et al., Pass@k Training (arXiv:2508.10751); Shenfeld et al., RL’s Razor (arXiv:2509.04259).

12. Next lecture

Lecture 19 · RL at Scale Is an Inference Problem: NeMo RL and NeMo Gym. Rollout generation can take most of an RL step. Lecture 19 follows one step through the serving system and the training system:

  • the long tail of response lengths;
  • shared vs separate GPUs;
  • asynchronous RL and its staleness limits;
  • the inference engine and the trainer disagreeing about probabilities, and the corrections;
  • sandboxes as a second serving system;
  • how NeMo RL and NeMo Gym organise it.

术语表 (Glossary, English → 中文)

English中文
reasoning model / chain of thought推理模型 / 思维链
policy gradient / REINFORCE / score function策略梯度 / REINFORCE / 得分函数
baseline / advantage / critic / value function基线 / 优势 / 评论家 / 价值函数
GAE (generalised advantage estimation)广义优势估计
group-relative advantage / leave-one-out (RLOO)组相对优势 / 留一法
zero-signal group / difficulty filter / dynamic sampling无信号组 / 难度过滤 / 动态采样
importance ratio / behaviour policy / reference policy重要性比率 / 行为策略 / 参考策略
trust region / clipped surrogate objective信赖域 / 裁剪替代目标
clip-higher (asymmetric clipping)上界放宽的非对称裁剪
length normalisation / token-level loss长度归一化 / 词元级损失
overlong filtering / soft overlong penalty超长过滤 / 软超长惩罚
sequence-level ratio (GSPO) / routing replay序列级比率 / 路由回放
capped importance weight (CISPO) / stop-gradient截断重要性权重 / 停止梯度
entropy collapse / exploration熵坍缩 / 探索
sharpening / discovery锐化 / 发现
pass@k crossover / answer diversitypass@k 交叉 / 答案多样性
spurious reward / training-free sampling虚假奖励 / 免训练采样
catastrophic forgetting / RL’s Razor灾难性遗忘 / “RL 剃刀”
specialist distillation / on-policy distillation专家模型蒸馏 / 同策略蒸馏
← 返回课程目录