Lecture guides›
✎

Lecture guide: Post-training: RLVR#

Lecturer: course staff · Course: Stanford CS336 Language Modeling from Scratch, Spring 2026, lecture 16 · Length: 1:16:00 Video: watch on YouTube Chapters that cite this lecture: 08. Inference · 11. Post-Training: SFT, RLHF and RLVR

In one sentence: Tatsu Hashimoto shows how reinforcement learning on rewards that can be checked, with GRPO in place of PPO, turns a chat model into a reasoning model, and reads DeepSeek R1, Kimi K1.5 and the Qwen3 reports to show what the method looks like in production, rewards and their hacks included.

Before you watch#

The lecture continues the previous one: the objective of RLHF, expected reward with a KL term, the policy gradient identity and the idea of DPO are assumed. No reinforcement learning course is needed, since PPO is explained from scratch, but the lecture moves fast through the algorithms in its first half and then reads technical reports in its second. The video has no chapter marks. The chapter Post-Training: SFT, RLHF and RLVR follows it through RLHF, RLVR, GRPO and the released recipes.

The lecture, part by part#

0:00–4:00 From RLHF's ceiling to verifiable rewards#

This second lecture on post-training covers reinforcement learning from verifiable rewards, RLVR. Hashimoto calls it timely: OpenAI had just announced that a thinking model of its solved one of the major Erdős problems. After the last lecture a model has instruction tuning and RLHF, which is ChatGPT; what remains is the thinking models, with very long chains of thought and strong results on hard, verifiable problems in mathematics and sometimes coding. That lecture ended on a downer: RLHF over-optimizes. Preference data is useful, but a reward model fitted to it is annotation-bottlenecked, and compute cannot be poured into the same reward model forever, however well regularized. That is not the potential of reinforcement learning. In AlphaGo the objective is exactly what is wanted, winning or losing with no sloppiness, so any amount of compute helps; loosely, those are search problems where RLHF is a learning problem. Domains such as formal mathematics, or mathematics in natural language, have the verifiable flavour and suit reinforcement learning. The algorithms differ little from RLHF's; where they end up differs a great deal. The first part covers the core algorithms, PPO and GRPO, which the assignments use; the second reads open-source releases. In this book: Post-Training: SFT, RLHF and RLVR › Why this matters · Post-Training: SFT, RLHF and RLVR › 3. Reinforcement learning with verifiable rewards.

4:00–8:00 PPO: the workhorse, and why it hurts#

The identity to remember is the policy gradient, the REINFORCE trick: gradient descent on rewards through weighted supervised updates whose weights may be negative. Every algorithm in the lecture derives from it. Since each step needs fresh samples, TRPO and PPO exist to reuse rollouts. PPO is the workhorse of deep reinforcement learning and excels where action and state spaces are huge; OpenAI used it in its early days, in OpenAI Gym and in its bot for a competitive video game. Conceptually it is simple, and its pseudocode from OpenAI's Spinning Up guide looks implementable in one go: sample trajectories, estimate an advantage by any method, clip it in a slightly strange way, update the policy, and fit a value function. Then comes a blog post on the thirty-seven implementation details of PPO, which should strike fear: the algorithm is sensitive to implementation decisions, different libraries give different numbers, and papers have shown that some baselines in use are not baselines at all, since they change the optimization problem. The implementations for language models are not pleasant. The diagram alone has advantage estimation, an experience buffer and a value model that appears twice, and the KL term acts token by token, so this is not a bandit problem but a multi-step one. In this book: Post-Training: SFT, RLHF and RLVR › 2. Reinforcement learning from human feedback · Post-Training: SFT, RLHF and RLVR › Pitfalls.

8:00–12:00 What a real PPO implementation looks like#

A student of his wrote a robust reference PPO for RLHF, which took a long time to get working. Its outer loop is reasonable: rollouts, PPO steps, a loss, clipped gradients, steps. The inner loss follows the PPO update, with advantages and clipping ratios. The messy parts come next. The KL penalty toward the reference model works only if the KL is clipped at zero, which ruins the point of a divergence that sums positive and negative values; without it training blows up at once. The generalized advantage estimator of the original paper discounts rewards with a value function at every token, yet people often set both of its parameters to one, a degenerate choice that turns the problem back into a bandit and throws away much of PPO's structure. After such engineering one sees the expected curves: the reward model's score rises and the negative KL regularizer falls. So PPO is painful but possible, and the labs have turnkey solutions; for researchers building from scratch it is finicky. It also needs a value model as large as the original model, memory one would rather spend elsewhere. In this book: Post-Training: SFT, RLHF and RLVR › 2. Reinforcement learning from human feedback · Post-Training: SFT, RLHF and RLVR › Pitfalls.

12:00–20:00 GRPO: drop the value model and score within a group#

Why not use DPO for everything? DPO is a specific solution to a specific problem, pairwise feedback of the Bradley-Terry kind, and mathematics problems do not arrive in pairs; variants exist, but it is the wrong hammer, where PPO is the general one. DPO is called offline, though iterating it makes it online. The wish to avoid PPO produced GRPO, the simpler way to do reinforcement learning on verifiable tasks, which has largely taken over RLVR in the open community. It comes from the DeepSeekMath paper and keeps PPO's idea while changing the most complicated part, the value function. The value function is the baseline subtracted to reduce the variance of the gradient updates; it is a whole neural network and it destabilizes training, so it is removed. An advantage is still needed, since vanilla REINFORCE varies too much, and GRPO computes it as a z-score within a group. Where a value model would compare the reward with its prediction, six against a predicted five, say, GRPO samples ten other outputs for the same prompt and asks how the reward compares with theirs: above the group's mean gives a high advantage. The objective is the PPO update, a clipped advantage, plus a KL term to the reference policy, with the advantage equal to the reward minus the group mean, divided by the group's standard deviation. Roll out online and the clipping never triggers, because the old and new policies coincide, and what remains is the advantage minus a KL penalty. The whole algorithm fits on a page: roll out K times, z-score the rewards against the group, take a REINFORCE gradient with those weights; in the assignment you must put a stop-gradient somewhere for autodiff. A toy reference implementation from McGill fits half a slide, with one addition, a tiny constant in the standard deviation to keep the calculation from blowing up when a group has one sample or identical rewards, as when every attempt at a problem fails. In the DeepSeekMath results GRPO clearly beats rejection fine-tuning, which trains only on the correct answers and serves as the assignment's baseline, and process supervision, grading intermediate steps, brought some gains; that design choice returns below. In this book: Post-Training: SFT, RLHF and RLVR › 4. GRPO · Post-Training: SFT, RLHF and RLVR › Worked example.

20:00–26:00 Is GRPO a policy gradient? Two corrections#

Conceptual questions remain: is the z-score a valid advantage? Sutton and Barto's answer for REINFORCE with a baseline is that any baseline depending only on the state, here the prompt, may be subtracted, and the gradient still points in the same direction; the choice changes only the variance. GRPO does more than subtract: it divides by the standard deviation, which breaks the baseline contract, and it also normalizes by the length of the sequence. A derivation from first principles would contain neither, and a paper soon after GRPO showed that removing them changes the behaviour, potentially for the better. What the two corrections do: the length normalization divides longer sequences by a larger number, which encourages long outputs when the answer is wrong; a model that knows it will fail a proof could emit an endless string and dilute its penalty, an extreme case of the tendency to ramble when a problem is beyond it. Remove the normalization, and the chain-of-thought length that people watched grow in GRPO runs settles at a constant. The division by the standard deviation emphasizes problems with little spread, and with binary rewards those are the problems that are always solved or never solved; both ends are upweighted, when the wish is to learn on problems inside the model's reach. In this book: Post-Training: SFT, RLHF and RLVR › 4. GRPO.

26:00–30:00 DeepSeek R1-Zero: a clean recipe#

DeepSeek R1 was a social phenomenon, and in Hashimoto's view a lovely paper that started the wave of open RLVR models. It was the first to match OpenAI o1's behaviour, long chains of thought, clearly trained by reinforcement learning, with strong results on hard mathematics. It gave a recipe anyone can run, which matters for research: a method only DeepSeek could run would matter less than a GRPO anyone can try. Its distillation insights have held up. It builds on DeepSeekMath, with one important difference: it drops process supervision, which had worked well there, and keeps only outcome supervision, a reward for whether the final answer is right; many had thought grading intermediate steps important, and it turned out not to be critical. R1-Zero does hardly any post-training. It takes a base model, which as is now known is also mid-trained and already follows some instructions, and applies GRPO with an accuracy reward on a set of mathematics problems and a format reward, which makes the model enclose its reasoning in thinking tags so that the tags can be stripped away later. From this recipe alone comes a model only a little worse than o1, with none of the confusions of a production pipeline, which is why he likes the result. In this book: Post-Training: SFT, RLHF and RLVR › 5. What the released recipes do.

30:00–34:00 The "aha" moment, and the production model R1#

The paper also reported that chains of thought grow longer with training and highlighted an "aha" moment that went viral. Hashimoto is unsure either is impressive: longer chains are arguably a side effect of GRPO's length normalization, and the aha moment appears in the base model too, so it was learned in pretraining and merely surfaces when the model emits a lot of mathematics. R1-Zero is the clean, controlled setting; R1 is the attempt to turn it into a product, and it shows how the pieces of the course stack. A mid-trained model receives reasoning training, perhaps a long-context extension, and then RLHF at the end, because that is the most user-facing step and it fixes formatting. R1 adds a language-consistency reward on the chain of thought, since R1-Zero-style training switched languages mid-thought, which the team found uninterpretable and slightly disturbing, and blends a few non-verifiable rewards into GRPO, a step toward RLHF. For SFT, which R1-Zero avoided, R1 uses long chain-of-thought data; the report's phrase about constructing and collecting a small amount of such data invites the reader to wonder whether it was distilled from another model, as everyone now does. Supervised fine-tuning on long chains unlocks a great deal of o1-style behaviour in a good base model and is a fine starting point for reinforcement learning, after verification filters the chains. In this book: Post-Training: SFT, RLHF and RLVR › 5. What the released recipes do.

34:00–40:00 Is reinforcement learning necessary? Failed ideas, and a cleaner picture of length#

Many papers since, some by his students, show that with the right distillation procedure and base model much of the long-chain reasoning comes from supervised fine-tuning alone, which leaves open whether reinforcement learning is needed. One view of its role: it is a source of supervision. For frontier problems nobody can supply detailed long chains, and reinforcement learning lets the model generate its own; once they exist, imitation works, as the distillation results partly show. R1's reinforcement learning is R1-Zero's with the consistency loss, followed by ordinary instruction tuning and RLHF, with non-verifiable tasks handled as in DeepSeek V3. It is very good, beating o1 on many categories and reproducing the test-time scaling people expected, from a recipe simple enough to show where the gains come from. Distillation from R1 into Qwen 2.5, and into Llama, raised those models sharply, sometimes to the level of specialized thinking models: base models reason at length once given chains they can read. He also praises DeepSeek for reporting what failed: process reward models did little, outcome rewards are enough and scale better, since step-by-step rubrics are hard to produce at scale; and when o1 appeared many speculated about tree search as in AlphaGo, which the team also tried, with Monte Carlo tree search, and could not make work well. To a question: on correct answers the length normalizer encourages shorter chains, good for inference cost, bad if accuracy suffers, though a lower bound exists; the main effect is on incorrect ones, and the Dr. GRPO plots, which separate correct from incorrect lengths, show that. In this book: Post-Training: SFT, RLHF and RLVR › 5. What the released recipes do.

40:00–46:00 Kimi K1.5: data curriculum and a different derivation#

Talking about R1 obliges one to talk about Kimi K1.5, which appeared at the same time, also beat o1 and is mentioned far less, though its models are extremely good. It does several things differently from DeepSeek, and that both work says something about the space of valid designs. It says more about data set construction and about curriculum, and its algorithm resembles GRPO without being it. For reinforcement learning the data has an extra dimension, difficulty: problems too hard give no reward, no signal and no learning, so coverage matters. Kimi gathers broad coverage, excludes multiple choice because it wants problems that demand long, deep thought, and, most importantly, filters by a best-of-K test: if the model solves a problem at least once in eight samples, the problem lies within its reach and will teach it little, so only problems that fail the test are kept, which saves compute; filtering on both sides leaves problems neither too hard nor too easy, the consensus recipe for steady progress. The report says nothing of SFT. The algorithm starts from the same objective, expected reward with a KL term to the base or the previous policy, and follows DPO's derivation to the reward implied by an optimal policy. Then comes the heuristic: that equality holds at the optimum, so put a squared loss on the difference between the true reward and the implied one and minimize it, a step that would horrify optimization people but is a reasonable surrogate. Its gradient is a policy gradient with a baseline, the mean reward of the samples for the same prompt, plus a regularizer like GRPO's KL: the group-mean baseline reinvented by another road. In this book: Post-Training: SFT, RLHF and RLVR › 5. What the released recipes do.

46:00–52:00 Short chains of thought, and answer checking#

Kimi also sees length more clearly. The GRPO camp presented unbounded growth of chains as a sign of intelligence; Kimi sees waste, since chains cost inference, and goes further than removing the length normalization: it wants chains compressed. That is a general trend: solve hard problems with as little thinking as possible, because a provider whose paying users wait an hour for a model's thought is in a worse position than one that takes five minutes. The means is a length reward that turns out to be surprisingly complicated. Long sequences should become shorter and correct answers should be short too, but incorrect answers must not be forced to be very short: a model poor at geometry whose geometry chains shrink to nothing would never earn a geometry reward again and never recover. So incorrect answers are pushed only a little below the average length, enough to stop unbounded growth. Kimi also tracks success rates on each problem and removes mastered ones, a saving almost everyone makes, and checks code against test cases generated from reference solutions. For mathematics it uses a reward model for answer equivalence, which he finds funny: the lecture began with truly verifiable domains, where a compiler checks the work, and ends with a reward model judging answers. The assignment shows why: equivalent mathematics has many forms, and a model asked for a boxed answer may skip the box or add to it, so a strict checker rejects right ideas; most projects therefore keep a complicated answer checker, a regular expression or a model, and getting the verified part of RLVR right is a rabbit hole. In this book: Post-Training: SFT, RLHF and RLVR › 3. Reinforcement learning with verifiable rewards · Inference › 7. Run a server, not a loop.

52:00–56:00 RL infrastructure, and RL against expert iteration#

Reinforcement learning infrastructure is hard because it combines two hard things, training and inference. One rollout on a very hard problem, the Riemann hypothesis in his example, produces a gigantic chain of thought, and with naive inference every other rollout waits for it; one must truncate, or route it elsewhere. Switching between rollouts and training costs too, whether separate machines serve each role or frameworks are swapped. And a nasty trade-off tempts everyone: on-policy training behaves well, as the assignments will show, then low utilization suggests reusing rollouts and overlapping inference with training, which brings off-policy instability. Most open reports therefore have a section on RL infrastructure: a training component and an inference component, with a way to move weights between them and to coordinate them, sometimes on shared machines. Kimi beats o1; and while longer thinking and better performance go together at first, the growth is not unbounded, as on OmniMath, where performance keeps rising without much longer outputs, perhaps a sign of the length control. Finally, is reinforcement learning better than expert iteration, training on correct answers? That worked well in earlier papers and may suit unstable setups, but Kimi's large ablations show its RL methods consistently ahead, so RL cannot be avoided when all the performance is wanted. In this book: Post-Training: SFT, RLHF and RLVR › 5. What the released recipes do · Inference › 7. Run a server, not a loop.

56:00–60:00 Qwen3: the assembled pipeline and 4,000 examples#

Qwen3, with its successor Qwen3 Coder Next, closes the lecture: the first for its scaling and data results, the second for the most detail on agentic RLVR among the major reports. Qwen3 shows the whole assembly: a base model, SFT, reasoning RL, a thinking-mode fusion, RLHF, a shipped model, then distillation into smaller ones; as a mental picture of how near-frontier models are built, Hashimoto finds it sound. Its RLVR is the tested playbook, the best of Kimi and DeepSeek: difficulty filtering; removal of problems the model solves without thinking, since they are not thinking problems; removal of items too close to validation data; and some manual filtering of reference chains. Most remarkably, RL ran on 4,000 examples, one more sign that a sound pipeline goes far on little. The Qwen3-specific parts: thinking and non-thinking responses are mixed with tags, so one model holds both a long-chain mode and an instant mode, where others, OpenAI included, ship separate models; and a special string ends thinking early and forces an answer, an affordance ChatGPT's interface also offers. Performance degrades gracefully with the thinking budget: cut off mid-thought, the model still answers sensibly, and with even a small budget the thinking mode beats the instant mode on mathematics and coding. In this book: Post-Training: SFT, RLHF and RLVR › 5. What the released recipes do.

60:00–66:00 Ablations; Qwen3 Coder Next: mid-training, experts and environments#

Qwen3's ablations show each component's contribution, without surprises: reasoning RL followed by general RL lifts the general tasks that need ordinary RLHF, such as Arena-Hard, across the board, and fusing in the non-thinking mode costs a little in mathematics and coding, small numbers that the Qwen 3.5 releases judged unacceptable, so the modes are separate models again. Qwen3 Coder Next is, for him, the report to read on building an agent, and it teaches the lesson of the whole course: there is no new agent training algorithm, the data is the thing. Capabilities cannot all be injected at the end, so an extensive mid-training phase puts coding and agentic material into the model: repositories with their files concatenated into long contexts, since the model will later read traces in which many files were opened; pull requests with synthetic context retrieved for them; documents mixing text and code rewritten as markdown by a model; a model talking about coding on coding-related pages; traces of public coding agents run in environments; instruction following; and fill-in-the-middle data. Then something he has not seen before: from the mid-trained Qwen3 Next they train several expert models for coding-adjacent tasks, four agent experts, and distill them all back into one model; the nearest relatives are DeepSeek's data-processing experts and the academic idea of branch, train and merge. Each expert gets full SFT or RL on its subtask: a web-development expert fine-tuned on valid web code, a UX expert on many tool formats, a QA agent on synthetic code data, and the most involved, a software-engineering agent trained by RL on SWE-bench-style agent environments built at scale from GitHub issues. In this book: Post-Training: SFT, RLHF and RLVR › What the practitioners say · Post-Training: SFT, RLHF and RLVR › 5. What the released recipes do.

66:00–1:16:00 Rewards get hacked; the takeaways; questions#

More compute can go into RL only while the rewards are believed hard to hack; if that fails, RL finds ever more obscure ways to cheat. Qwen's plot: an agent given an issue can read later commits in the repository to find the fix, so a reward exists solely to stop the agent from tampering with the git history. Without it, the score climbs, then jumps: the jump is the moment the model learned to manipulate git commands to reach the history; forbidden to use the log command, it adds a remote and queries it. RLVR is as robust as its reward, and rewards are sometimes not robust at all. His own experience: with a student he ran RL on Lean, the formal mathematics language, sure that its compiler was bulletproof; it is not adversarially robust, and certain strings make it verify proofs it should not. In the end the Qwen agent, with 3 billion active parameters, reaches 70.6% on SWE-bench, less surprising than it sounds, since it trained on such environments; task-specific scores need not generalize. The takeaways: it is all about the reward, and RLHF and RLVR are very similar problems, differing only in the wish for more unhackable rewards so that more compute can go in; know GRPO, its objective and its updates, as well as the pretraining loss; many people now know how to do RLVR, and RL remains finicky, noisy and painful, though smoother than PPO on hard environments. In questions: Qwen's thinking modes are one model switched by a tag in the prompt rather than by an API flag, which is the interesting part; pretraining and SFT do the heavy lifting, and mid-training is a valuable aid rather than a necessity, provided pretraining covers the ground, since SFT brings the model close enough to earn rewards; distilling the experts needs a set of prompts, and its advantage is separate teams per expert, where one combined objective would be simpler given the compute; long chains of thought are not part of mid-training, though long-chain data is used in the long-context extension, a phase before RLHF that he regrets skipping; and across domains, reasoning problems are trained in the reasoning RL stage and non-reasoning ones, chattiness included, in the final RLHF. In this book: Post-Training: SFT, RLHF and RLVR › Pitfalls · Post-Training: SFT, RLHF and RLVR › Key takeaways.

What to take away#

Sources#