Reinforcement Learning for Reasoning
Verifiable rewards, GRPO and spending more compute at test time.
A base model that solved 15.6% of the AIME 2024 competition problems on its first attempt was trained by reinforcement learning on rewards a program could check: was the final answer right, and was the reasoning placed inside the required tags? By the end it solved over 70%, writing chains of thought thousands of tokens long (DeepSeek-AI, 2025). Checkable rewards turned post-training into a way to buy reasoning with compute twice: during training, and again at test time by sampling, searching and checking. This lesson follows the path from bootstrapped rationales and process rewards to GRPO and test-time scaling, and asks what the reinforcement learning actually adds.
What you’ll learn
- Show that STaR and ReST-EM are approximate policy-gradient and EM methods for binary rewards, and that fine-tuning on a model's own correct samples ascends the log of its success probability.
- Compare outcome and process supervision, and explain what Monte Carlo step labels estimate (a value function of the completer) and why progress, an advantage, makes a better process reward.
- Write GRPO's objective exactly as published, derive its group-relative advantages for binary rewards and the properties of its KL estimator, and describe what DeepSeek-R1 reported, including distillation into smaller models.
- Analyze test-time compute: the unbiased pass@k estimator, why coverage follows a power law in the number of samples, and when search, revision or a larger model is the better use of compute.
Bootstrapping rationales
Prompting a model to write out intermediate steps, a chain of thought, and voting over several sampled chains (self-consistency) improves accuracy on multi-step problems. The Artificial Intelligence course proves when voting helps and covers search over thoughts; What Transformers Can Compute shows why written-out steps add computational power. This lesson is about training models to reason, and the obstacle is data: worked solutions written by people are scarce, while problems with checkable answers are plentiful.
STaR (Zelikman et al., 2022) bootstraps from about ten worked examples. Prompted with them, the model writes a rationale and an answer for every training problem, and the rationales that reach the correct answer are kept. For problems it got wrong, it is shown the correct answer as a hint and asked to justify it (rationalization); those rationales are kept too, with the hint removed. The original pretrained model is fine-tuned on everything kept, and the loop repeats with the new model generating. On CommonsenseQA, the 6-billion-parameter GPT-J gained 35.9 points over few-shot prompting and 12.5 over fine-tuning on answers alone, reaching 72.5%, close to the 73.0% of a fine-tuned model 30 times larger.
Give a sampled rationale-plus-answer the binary reward , and let be the probability of solving problem . The policy gradient keeps only the successful samples, exactly as STaR's filter does, a link Zelikman et al. point out:
ReST-EM (Singh et al., 2024) makes the link exact with expectation–maximization. The E-step restricts the current policy to its correct responses; the M-step is supervised fine-tuning on them:
At the current parameters, the M-step's gradient is the gradient of the log success probability (Fisher's identity):
So fine-tuning on each problem's successes, normalized per problem, ascends rather than : a problem solved 1% of the time gets 100 times the weight REINFORCE would give it. Three things separate it from on-policy RL: the samples come from the previous round's model, wrong answers are discarded rather than pushed down, and each round restarts from the base model to limit overfitting.
With PaLM 2 models on competition mathematics (MATH) and code (APPS), ReST-EM sampled 32 or 64 solutions per problem, kept at most 10 correct ones per problem so that easy problems would not dominate, and beat fine-tuning on human-written solutions, by margins that grew with model size. It raised pass@ at every measured, most at ; gains shrank over iterations, and more iterations began to overfit.
Shao et al. (2024) wrote supervised fine-tuning, rejection-sampling fine-tuning, DPO, PPO and GRPO as one gradient, , differing only in where the data come from, what supplies the reward, and the per-token gradient coefficient . Online rejection-sampling fine-tuning reinforces every correct answer equally and never penalizes a wrong one; GRPO, which scales both by the reward, beat it.
In the policy-gradient view of STaR, what happens to a sampled rationale that reaches a wrong answer?
- It is pushed down, as a negative advantage would do
- It is kept with the correct answer appended, and trained on
- It contributes nothing: the indicator reward zeroes its term in the gradient
- It is kept with a smaller weight than correct rationales
Show the answer
C. It contributes nothing: the indicator reward zeroes its term in the gradient
With reward and no baseline, failed samples multiply their score function by zero, which is exactly STaR's filter. Rationalization is separate: for a failed problem the model writes a new rationale with the answer as a hint. Methods with a baseline, such as GRPO, do push wrong answers down.
Outcome versus process supervision
An outcome reward model (ORM) scores a whole solution by whether its final answer is right; a process reward model (PRM) scores every step. Uesato et al. (2022) compared them on grade-school math (GSM8K) with a 70-billion-parameter model. Final-answer error came out similar either way, 23.5% against 22.3% without a reward model and 16.6% against 14.8% with one. Reasoning was another matter: among answer-correct solutions, the best model trained by RL directly on final-answer correctness still had flawed reasoning in 12.4% of them, against 3.8% for the best process-supervised method, and RL against a learned reward model brought it to 5.5%. Their best system cut the trace error from the previous best of 14.0% to 3.4%.
Lightman et al. (2024) scaled process labels up. PRM800K holds 800,000 human labels (positive, negative or neutral) for the steps of 75,000 solutions to 12,000 MATH problems, and the PRM was supervised only up to each solution's first incorrect step. A solution's PRM score is the product of its steps' probabilities of being correct. Choosing the best of 1,860 sampled solutions per problem on 500 test problems, the PRM solved 78.2%, an ORM 72.4% and majority voting 69.6%. Active learning, labeling the solutions the current PRM found most convincing but that reached wrong answers, made labeling about 2.6 times more data-efficient.
Think first A completer finishes 8 solutions from a partial solution and 3 reach the right answer. What are the soft and hard labels, and what does the hard label's average become if the completer truly succeeds 37.5% of the time?
Soft label , hard label . With and the hard label's mean is : hard labels call almost any salvageable step good, so they mostly detect steps from which the answer is unreachable.
Automatic process labels work in practice. Step-by-step PPO against Math-Shepherd's PRM raised Mistral-7B from 77.9% to 84.1% on GSM8K and from 28.6% to 33.0% on MATH. Trained to predict progress under a prover, Setlur et al.'s process advantage verifiers made search more than 8% more accurate and 1.5 to 5 times more compute-efficient than with an ORM, and as dense RL rewards gave 5 to 6 times better sample efficiency, where automated PRMs had previously beaten ORMs in RL by only 1–2%.
At the largest scale the verdict has been cautious. The DeepSeek-R1 report lists PRMs among its unsuccessful attempts: a "step" is hard to define in general reasoning, step correctness is hard to label automatically and expensive to label by hand, and a learned PRM invites reward hacking. It kept them for reranking and guided search, where they work, but found their benefit in large-scale RL too small for their cost.
GRPO, as published
With a verifiable reward there is no reward model to train, but PPO still needs a value network about as large as the policy, which is hard to train when the only reward arrives at the last token. GRPO (Shao et al., 2024) drops it: for each question it samples a group of outputs from the old policy and uses their rewards relative to one another as the baseline, maximizing
With binary rewards and of outputs correct, let . The group mean is and the population standard deviation , so
The advantages sum to zero; a rare success earns a large one ( when 1 of 8 is right, against when 4 of 8 are); and a group whose rewards are all equal has zero advantages and contributes only the KL term. Implementations that use the sample standard deviation scale every advantage by .
The KL term is estimated at each sampled token with (Schulman, 2020, a blog note). For tokens sampled from itself, and , so the estimate is unbiased, and because for all , no single sample is ever negative:
Unbiased in value is not unbiased in gradient: differentiated as part of the loss with the samples held fixed, the estimate's expected gradient at each token is that of , the divergence with its arguments swapped (the Reinforcement Learning course derives this). DeepSeekMath used , and a single gradient update per batch of samples. With one update, wherever the gradient is taken, so the clipping never binds and the gradient is a group-baselined policy gradient plus the KL term; clipping matters only when a batch is reused.
GRPO samples 8 answers to a question and 2 are correct (reward 1; the rest get 0). Using the population standard deviation, what advantage does each correct answer receive?
Show the answer
1.73
Mean , standard deviation , so for each correct answer and for each wrong one; they sum to zero. With the sample standard deviation, as torch.std computes by default, both shrink by , to and .
def grpo_loss(logp, logp_old, logp_ref, rewards, mask, eps=0.2, beta=0.04):
"""One question. logp, logp_old, logp_ref: (G, T) log-probs of each sampled token
under the current, sampling and reference policies; rewards: (G,); mask: (G, T)."""
adv = (rewards - rewards.mean()) / (rewards.std() + 1e-4) # group-relative advantage
ratio = torch.exp(logp - logp_old)
clipped = torch.clamp(ratio, 1 - eps, 1 + eps)
surrogate = torch.min(ratio * adv[:, None], clipped * adv[:, None])
log_r = logp_ref - logp
kl = torch.exp(log_r) - log_r - 1 # per-token KL estimate, always >= 0
per_token = (surrogate - beta * kl) * mask
per_output = per_token.sum(1) / mask.sum(1) # average over each output's tokens
return -per_output.mean() # minimize the negative objectiveThe objective above for one group, written as a loss. The small constant keeps a group with equal rewards from dividing by zero; such a group then contributes only its KL term.
In DeepSeekMath itself the rewards came not from a checker but from a learned reward model, whose training data were built as in Math-Shepherd (previous step). Trained this way on about 144,000 chain-of-thought questions from GSM8K and MATH, DeepSeekMath-Instruct 7B rose from 82.9% to 88.2% on GSM8K and from 46.8% to 51.7% on MATH, and improved on benchmarks it was not trained on. The authors also observed that RL raised accuracy under majority voting over samples but not pass@, the chance that any of samples is right: it made the output distribution more reliable rather than widening what it could solve.
The normalizations are choices with side effects. Dividing each output's sum by its length penalizes a long wrong answer less per token than a short one, which Liu et al. (2025) found lengthened incorrect responses during training; dividing by the group's standard deviation reweights questions by difficulty. Their Dr. GRPO removes both. The Reinforcement Learning course analyzes these normalizations and critic-free estimators such as RLOO.
DeepSeek-R1, and distilling reasoning
R1-Zero. DeepSeek-AI (2025) applied GRPO directly to the DeepSeek-V3 base model, with a template asking for the reasoning between <think> tags before the answer and rule-based rewards only: accuracy (a matching answer, or passing test cases for code) plus format, weighted equally. Neural reward models, outcome or process, were left out because they were susceptible to reward hacking in large-scale RL. Pass@1 on AIME 2024 rose from 15.6% to over 70% (86.7% with self-consistency over 16 samples), and the average response grew steadily to thousands of tokens, with more passages that re-check earlier steps or try another approach. The report's "aha moment", an intermediate checkpoint writing "Wait, wait. Wait." and starting over, is an anecdote; Liu et al. (2025) found such self-reflection already present in DeepSeek-V3-Base before RL, so training may have amplified rather than created it.
R1. R1-Zero's reasoning was hard to read and mixed languages. DeepSeek-R1 added stages: fine-tuning on a few thousand curated long chain-of-thought examples (a "cold start"), reasoning RL with an extra reward for staying in one language, rejection sampling from the RL model to build about 800,000 supervised examples (about 600,000 reasoning traces that reached correct answers, 200,000 general ones), fine-tuning DeepSeek-V3-Base afresh on them, and a second RL stage for helpfulness and harmlessness that also kept refining reasoning. The report stresses the base model: pure RL from a 7-billion-parameter dense and a 16-billion-parameter mixture-of-experts base failed to improve AIME accuracy, their longer outputs turning repetitive, while 32-billion dense and 230- and 671-billion mixture-of-experts bases improved substantially.
| 32-billion-parameter model | How it was trained | AIME 2024 pass@1 |
|---|---|---|
| QwQ-32B-Preview | an earlier open reasoning model, for reference | 50.0% |
| Qwen2.5-32B-Zero | large-scale RL from the base model, over 10,000 steps | 47.0% |
| DeepSeek-R1-Distill-Qwen-32B | SFT only, 2–3 epochs on the 800,000 samples generated with R1 | 72.6% |
How little distillation data is needed? s1 (Muennighoff et al., 2025) selected 1,000 questions from a pool of 59,000 for difficulty, diversity and quality, with reasoning traces generated by a Gemini model, and fine-tuned Qwen2.5-32B-Instruct on them in 26 minutes on 16 GPUs. Budget forcing then controls the thinking at test time: to stop, the end-of-thinking marker is forced in; to continue, the marker is suppressed and "Wait" is appended whenever the model would end its thinking, which often leads it to re-check and fix its answer. Forcing longer thinking raised its AIME 2024 accuracy from 50% to 57%. Supervised distillation of traces is sequence-level knowledge distillation (Knowledge Distillation), and the forward-KL analysis of Instruction Tuning & Its Data applies to it.
DeepSeek-R1-Distill-Qwen-32B far outperformed the same base model trained by large-scale RL. What best explains why distillation can win for a smaller model?
- RL cannot be applied to models below 70 billion parameters
- The distilled model saw the test problems during training
- RL can only reinforce strategies the small model already samples, while supervised fine-tuning on the teacher's traces makes it imitate strategies it would rarely find itself
- Distillation uses a larger learning rate
Show the answer
C. RL can only reinforce strategies the small model already samples, while supervised fine-tuning on the teacher's traces makes it imitate strategies it would rarely find itself
The policy gradient sees only what the policy samples, so RL sharpens what is reachable. Imitating a stronger model's long traces (a forward-KL fit) transfers patterns from outside the student's sampling distribution, as Yue et al. (2025) also report. The price is needing a stronger teacher.
Spending compute at test time
A trained model can spend more test-time compute in three ways: sample many answers in parallel and select one (majority vote, or best-of- by a verifier or reward model); search step by step, guided by a process reward model (beam search, lookahead); or generate and revise sequentially, as long chains of thought and revision models do. Brown et al. (2024) separate two questions: coverage, whether any sample is correct, and precision, whether the right one can be picked. Coverage is measured by pass@, which needs care to estimate.
For a problem with single-sample success probability , pass@. Draw samples, of which are correct. Plugging in is biased: is convex, so by Jensen's inequality the estimated failure rate is too high on average, and pass@ too low:
Instead, choose of the samples uniformly at random. The probability that none of them is correct is a ratio of binomial coefficients, so
Averaged over the draw of the samples, a random -subset is a set of independent samples, so its expectation is exactly : the estimator is unbiased, and averaging it over problems estimates a benchmark's pass@.
You draw samples for a problem and are correct. What is the unbiased estimate of pass@5, in percent?
Show the answer
60 %
. The plug-in estimate is lower, as Jensen's inequality predicts; the gap matters when pass@ curves are compared at large .
Coverage is not accuracy. With a checker, coverage turns directly into solved problems: on SWE-bench Lite, repeated sampling raised the issues solved by DeepSeek-Coder-V2-Instruct from 15.9% with one sample to 56% with 250, above the single-sample state of the art of 43% (Brown et al., 2024). Without one, majority voting and reward models plateaued beyond several hundred samples: the gap between generating a correct answer and recognizing it becomes the bottleneck.
Allocating compute. Snell et al. (2025) studied PaLM 2-S* on MATH, sorting questions into five difficulty levels by the model's own success rate. On easy questions, beam search against a PRM over-optimized it and got worse as the budget grew, while best-of- did not; on medium questions beam search won; on the hardest, nothing helped much. Easy questions did best with purely sequential revisions, harder ones with a mix of sequential and parallel. Choosing the strategy per difficulty beat best-of- with about 4 times less compute, and at matched FLOPs extra test-time compute beat a roughly 14 times larger model on easy and medium questions, though not on the hardest ones or when inference load is large compared with pretraining.
Revision needs a signal. Asked only to review and correct its own answer, without external feedback, a model rarely improves its reasoning and sometimes makes it worse (Huang et al., 2024). Revision works when it is trained, as in Snell et al.'s revision model, or when the feedback comes from a checker.
What does the RL add? Across model families, six RL algorithms and math, code and visual benchmarks, Yue et al. (2025) found that models trained with verifiable rewards beat their base models at small but were matched or overtaken at large , and that their reasoning paths were already probable under the base model, whereas distillation added new ones: current RL mostly sharpens sampling toward what the base model can find, as DeepSeekMath's majority-voting result also suggested. Under other conditions the opposite has been reported: prolonged RL with KL control and periodic resets of the reference policy improved pass@ even on tasks where the starting model, a 1.5-billion-parameter distillation of DeepSeek-R1 rather than a pretrained base, failed at every (Liu et al., 2025, ProRL), and ReST-EM raised pass@ at every it measured. The answer likely depends on the task, base model, training length and measurement; the Reinforcement Learning course examines the debate.
Key takeaways
- STaR and ReST-EM sample, keep what a checker accepts, fine-tune and repeat: an EM approximation to RL whose step ascends the log success probability, upweighting hard problems, without pushing wrong answers down.
- Process supervision lowers reasoning errors more than final-answer errors (Uesato et al.), and Lightman et al.'s PRM picked correct MATH solutions more often than an ORM (78.2% against 72.4%, best of 1,860). Monte Carlo step labels estimate the completer's value; progress, a step-level advantage, is the better reward.
- GRPO is PPO with group-standardized rewards as advantages, per-output token averaging and an unbiased, nonnegative KL estimator in the objective; binary rewards give advantages and , and its normalizations bias length and difficulty.
- DeepSeek-R1 grew long, self-checking chains of thought from rule-based rewards on a large base model; distilling its traces into smaller models (SFT only) beat large-scale RL on them, and 1,000 curated traces with budget forcing (s1) already give test-time scaling.
- At test time, estimate pass@ without bias, expect coverage power laws from a heavy tail of hard problems, and treat verification as the bottleneck; the best use of compute depends on difficulty, and whether RL with verifiable rewards expands or mainly sharpens a base model's reasoning is debated.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In GRPO with binary rewards, compare a group of 8 in which one answer is correct with a group of 8 in which four are. How do the correct answers' advantages compare?
- They are equal, since both answers earned reward 1
- The lone correct answer's advantage is larger: against
- The lone correct answer's advantage is smaller, because its group's mean is lower
- Both are zero, because the advantages sum to zero
Show the answer
B. The lone correct answer's advantage is larger: against
: with it is , with it is . Standardizing within the group makes a rare success count heavily, which is part of why training sets are filtered toward problems the model sometimes, but not always, solves.
A process reward model is trained on Monte Carlo labels: for each step, the fraction of a completer's continuations that reach the right answer. What does it learn to predict?
- The completer's probability of eventually succeeding from that prefix, a value function
- Whether each step is logically valid
- How a human expert would grade the step
- The probability that the step appears in the reference solution
Show the answer
A. The completer's probability of eventually succeeding from that prefix, a value function
The soft label is an unbiased estimate of for the completer . A valid step can score low if the completer is weak, and a flawed one high if the completer recovers, which is why Setlur et al. propose rewarding progress, the change in value a step causes.
A model is fine-tuned on its own correct solutions, each problem's correct samples weighted equally in total (the EM view of STaR and ReST-EM). At the current parameters, which objective's gradient does this follow?
- The expected reward , exactly as REINFORCE
- The likelihood of human-written solutions
- The KL divergence to the base model
- The log success probability , which weights hard problems by
Show the answer
D. The log success probability , which weights hard problems by
With , Fisher's identity gives . Relative to REINFORCE's , rarely solved problems get far more weight. Filtering without that normalization weights each problem by its number of correct samples, which favors easy problems; ReST-EM's cap of 10 correct samples per problem moves the weighting toward the normalized one.
Snell et al. (2025) compared ways of spending test-time compute on MATH by question difficulty. Which matches their findings?
- One strategy, beam search against a PRM with the largest budget, was best for every question
- Easy questions did best with sequential revisions, and beam search there over-optimized the PRM; harder questions needed a mix with parallel sampling or search; on the hardest, little helped, and a larger model could be the better buy
- Test-time compute always beat a 14 times larger model, whatever the difficulty
- Sequential revision never helped
Show the answer
B. Easy questions did best with sequential revisions, and beam search there over-optimized the PRM; harder questions needed a mix with parallel sampling or search; on the hardest, little helped, and a larger model could be the better buy
The best use of test-time compute depended on difficulty, so allocating it per question beat best-of- with about 4 times less compute. At matched FLOPs it beat a much larger model on easy and medium questions, but pretraining a larger model was better for the hardest ones or under heavy inference load.
Further reading
- E. Zelikman, Y. Wu, J. Mu & N. D. Goodman, "STaR: Bootstrapping reasoning with reasoning," NeurIPS (2022).
- H. Lightman et al., "Let's verify step by step," ICLR (2024).
- Z. Shao et al., "DeepSeekMath: Pushing the limits of mathematical reasoning in open language models," arXiv:2402.03300 (2024).
- DeepSeek-AI, "DeepSeek-R1: Incentivizing reasoning capability in LLMs via reinforcement learning," arXiv:2501.12948 (2025).
- C. Snell, J. Lee, K. Xu & A. Kumar, "Scaling LLM test-time compute optimally can be more effective than scaling parameters for reasoning," ICLR (2025).
- Y. Yue et al., "Does reinforcement learning really incentivize reasoning capacity in LLMs beyond the base model?," NeurIPS (2025).