RL for Reasoning & LLM Agents
Verifiable rewards, GRPO and agents that act over many turns.
Some answers can be checked: a math problem has a final number, a program has unit tests. Rewarding only checked correctness, with a policy gradient whose baseline is the average reward of a group of attempts, turned pretrained language models into models that write long chains of thought, as reported for DeepSeek-R1-Zero. This lesson builds the method from REINFORCE, runs it on a toy, and separates what is established from what is still argued about, from pass@k to agents that act over many turns.
What you’ll learn
- Formulate RL with verifiable rewards as a contextual bandit over whole responses, with the average success probability as its objective.
- Derive the group-relative advantage from REINFORCE with a baseline, relate it to the leave-one-out estimator, and write the GRPO objective.
- Describe what the DeepSeek-R1 report shows about RL from a base model, longer reasoning and distillation, and what it does not show.
- Explain pass@k, the crossover between base and RL-trained models at large k, and the competing readings of it.
- Extend the setting to agents that use tools over many turns, and name the main open problems.
Rewards a program can check
RL with verifiable rewards (RLVR) trains a language model on tasks whose answers a program can check: a math problem with a known final answer, compared after normalizing its format; a coding problem with unit tests; a formal proof checked by a proof assistant. The name comes from the Tülu 3 report (Lambert et al., 2024). DeepSeek-R1 was trained largely this way; OpenAI described its o1 models (2024) as trained with large-scale RL, without publishing their rewards.
A verifiable reward removes the learned reward model and its blind spots, but not every problem. Checkers can be fooled: an answer-extraction rule can accept a malformed answer, and unit tests can be passed by code that special-cases them. DeepSeek-R1-Zero's rewards were rule-based, an accuracy check plus a format reward for placing the reasoning between think tags; for reasoning tasks the authors avoided learned reward models because they found them prone to reward hacking in large-scale RL (DeepSeek-AI, 2025). The released DeepSeek-R1 added a language-consistency reward and, for general non-reasoning data, learned reward models.
GRPO: a baseline from the group
The score-function gradient of (The Policy Gradient Theorem & REINFORCE), with any baseline that does not depend on the sampled response:
The natural baseline is the prompt's own success probability , which a value network could learn. Instead, sample a group of responses per prompt and estimate it from the group. A leave-one-out mean does not depend on , so the estimator stays unbiased (RLOO; Kool, van Hoof & Welling, 2019; Ahmadian et al., 2024):
GRPO (Shao et al., 2024) centers each reward on the group mean and divides by the group's standard deviation . This group-relative advantage is given to every token of response :
By the identity above, centering on the full mean only rescales RLOO by . Dividing by is a real change: it reweights prompts by difficulty. (Some implementations divide by inside , a constant rescaling.) GRPO & Critic-Free Policy Optimization derives what this and the rest of the objective do.
import torch
def group_advantages(rewards, normalize=True, eps=1e-6):
"""rewards: (num_prompts, G) verifier scores, one row per prompt's group."""
adv = rewards - rewards.mean(dim=1, keepdim=True) # centered on the group's average
if normalize: # GRPO also divides by the group's spread
adv = adv / (rewards.std(dim=1, correction=0, keepdim=True) + eps)
return adv # an all-equal group gives zerosEvery token of response then gets advantage adv[prompt, i]. The small eps makes an all-equal group, whose standard deviation is 0, yield zero advantages instead of a division by zero.
In a batch, half of the prompts are so easy that the current policy always solves them and the other half so hard that it never does. What does one GRPO update do?
- It makes large updates, because the rewards are extreme
- Nothing through the advantages: every group has equal rewards and every advantage is 0, so only the KL term, if any, moves the policy
- It reinforces the answers to the easy prompts
- It lowers the probability of the answers to the hard prompts
Show the answer
B. Nothing through the advantages: every group has equal rewards and every advantage is 0, so only the KL term, if any, moves the policy
Advantages are relative to the group, and a group with equal rewards has nothing to compare. This is why sampling compute spent on prompts the policy always or never solves is wasted, and why some methods filter such prompts out and draw new ones.
What R1-Zero showed, as reported
DeepSeek-AI (2025) applied GRPO directly to their pretrained base model, DeepSeek-V3-Base, with only rule-based rewards and no supervised fine-tuning first; they called the result DeepSeek-R1-Zero. They report that accuracy on competition math rose steeply during training, that the average response length grew steadily, and that behaviors such as re-examining and revising earlier steps appeared, including an episode the authors called an "aha moment". They also report its weaknesses: poor readability and mixing of languages.
The released model, DeepSeek-R1, used a multistage pipeline instead: a small "cold start" set of long, readable reasoning examples for supervised fine-tuning, reasoning-oriented RL, rejection sampling and supervised fine-tuning on a broad mix of data, and a final RL stage. Its outputs were then used to fine-tune smaller models, a form of distillation. One comparison in the report stands out: on a 32-billion-parameter base model, distillation from DeepSeek-R1 performed significantly better across benchmarks than more than 10,000 steps of large-scale RL on the same base.
Longer reasoning is one way to spend test-time compute. OpenAI (2024) reported that o1's performance improved steadily both with more RL training and with more thinking time at inference. Snell et al. (2025) studied how best to spend a fixed inference budget, for example by revising answers or by searching against a verifier, and found that the best strategy depends on how hard the problem is.
According to the DeepSeek-R1 report, which gave the better reasoning model on a 32-billion-parameter base model?
- More than 10,000 steps of large-scale RL from the base model
- Supervised fine-tuning on reasoning traces generated by the much larger DeepSeek-R1 (distillation)
- Both gave identical results
- Neither improved on the base model
Show the answer
B. Supervised fine-tuning on reasoning traces generated by the much larger DeepSeek-R1 (distillation)
The distilled model performed significantly better across benchmarks. The authors concluded that distilling a stronger model is economical and effective for small models, while going beyond the strongest model may still require more powerful base models and larger-scale RL. Distillation copies the teacher's strategies; on the sharpening reading discussed next (contested), RL on a small model mostly reweights what that model already samples.
Sharpening or discovering? pass@k
pass@k is the probability that at least one of sampled answers is correct. For a problem with success probability it is ; from samples of which are correct, estimates it without bias (Chen et al., 2021). At it measures reliability; at large , reach: whether the model can produce a correct answer at all.
Already in DeepSeekMath, Shao et al. (2024) observed that RL improved majority-vote accuracy over samples but not pass@K, and read RL as making the output distribution more robust rather than raising fundamental capability. Yue et al. (2025) tested this across model families, math, coding and visual-reasoning benchmarks, and several RL algorithms: RL-trained models won at small , but the base models consistently caught up and overtook them as grew into the tens or hundreds. Their analyses suggest that the RL models' reasoning paths were already in the base model's sampling distribution, whereas distillation appeared to add patterns from the teacher.
Think first Two problems. The base model solves A with probability 0.5 and B with probability 0.05; after RL it solves A with probability 0.95 and B never. Compute pass@1 and pass@4 for both models, averaged over the two problems. Which wins at each k?
pass@1: base , RL , so RL wins. pass@4: base , RL , so the base model wins; the curves cross between (RL ahead, 0.499 to 0.424) and (base ahead, 0.509 to 0.500). As the base model's pass@k tends to 1 and RL's stays at 0.5. At large only reach counts, so RL can lose there only by making some problems (nearly) unreachable.
The reading is contested. ProRL (Liu et al., 2025) trained a small model much longer on a broad mix of tasks, with a KL penalty whose reference policy was reset from time to time, and reported gains in pass@k even at large k, especially where the base model was weak. Gandhi et al. (2025) found that whether RL helps depends on reasoning behaviors, such as verification and backtracking, that the base model already shows. What RL Adds to a Language Model weighs this evidence, together with the finding that even random rewards improved some models.
Critic-free variants, and agents that act
| Method | Advantage | Value network | Notes |
|---|---|---|---|
| PPO, as in RLHF | GAE with a learned value | yes | per-token credit; memory-heavy; value estimates for reasoning can be poor |
| RLOO (Ahmadian et al., 2024) | minus the mean of the other rewards | no | unbiased REINFORCE with a baseline |
| GRPO (Shao et al., 2024) | within the group; PPO-style clipping; KL in the loss | no | its standard-deviation and length normalizations bias the objective |
| Dr. GRPO (Liu et al., 2025) | , with a constant in place of the length normalizer | no | removes GRPO's two normalization biases |
| DAPO (Yu et al., 2025) | group-relative, with a wider upper clip, filtering of all-equal groups, a token-level loss and length shaping; no KL | no | aimed at stable training of long chains of thought |
| VinePPO (Kazemnejad et al., 2025) | Monte Carlo value estimates from extra rollouts at intermediate steps | no (sampled instead) | finer credit assignment at extra sampling cost |
Verifiable rewards extend naturally to agents that act over several turns: search the web, run code, call other tools, read the results and continue. An episode now interleaves the model's tokens with tokens produced by the environment, such as a search result or a compiler message. Those are observations, not actions, so the policy gradient should flow only through the model's own tokens; implementations mask the environment's tokens out of the loss, as Search-R1 did with retrieved text (Jin et al., 2025). Rewards usually arrive only at the end, after many turns, which makes credit assignment harder, and the environment itself becomes something the policy can exploit: a coding agent rewarded for passing tests may learn to edit the tests.
def masked_policy_loss(logp, adv, from_model):
"""logp: (T,) log-probs of every token in an episode under the policy; adv: (T,) advantages;
from_model: (T,) bool, False for prompt, tool-output and other environment tokens."""
mask = from_model.float()
return -(adv * logp * mask).sum() / mask.sum() # only the agent's own tokens are actionsWithout the mask, the loss would also raise the probability of text the environment produced, teaching the model to imitate tool outputs instead of acting.
Key takeaways
- RLVR treats each response as one action with a 0/1 verifier reward; its objective is the average success probability (pass@1). Rule-based rewards remove the reward model, but not every way to game a checker.
- GRPO is REINFORCE with a baseline estimated from a group of responses: centering on the group mean is RLOO up to the factor , while dividing by the group's standard deviation reweights prompts. All-equal groups carry no signal.
- DeepSeek-R1-Zero reported that RL from a base model with rule-based rewards produced longer reasoning with self-revision. Base models already show some of these behaviors, and on a 32B base, distillation from a stronger model beat large-scale RL.
- pass@1 measures reliability and pass@k at large k measures reach. RL raises the first; several studies find base models ahead at large k, and whether longer or different RL expands reach is debated.
- Tool-using agents interleave model and environment tokens: mask the environment's tokens out of the loss, expect sparse rewards over many turns, and expect the policy to exploit flaws in its environment.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In RLVR with a 0/1 verifier, what is ?
- The average over prompts of the probability that a sampled answer is correct, that is, pass@1
- pass@k for large k
- The fraction of prompts the model can ever solve
- The negative log-likelihood of the correct answers
Show the answer
A. The average over prompts of the probability that a sampled answer is correct, that is, pass@1
The expected 0/1 reward for a prompt is its success probability ; averaging over prompts gives pass@1. RLVR therefore directly optimizes first-try reliability, not reach.
Why does RLOO use the mean of the other rewards as response 's baseline, rather than the mean of all ?
- It is cheaper to compute
- So that the baseline does not depend on , which keeps the estimator unbiased; including scales the expected gradient by
- So that the advantages can be divided by the standard deviation
- Because the mean of all rewards is always zero
Show the answer
B. So that the baseline does not depend on , which keeps the estimator unbiased; including scales the expected gradient by
A baseline is allowed to depend on anything but the action whose score it multiplies. The leave-one-out mean satisfies that, and since , using the full mean merely shrinks the expected gradient by the constant .
During DeepSeek-R1-Zero's training, the average response length grew steadily. Which statement is best supported?
- Length was directly rewarded
- Response length grows in any RL training of language models
- Length grew because there was no KL penalty
- The reward paid only for correct, well-formatted answers, and longer reasoning helped on hard problems; a normalization bias in GRPO's loss can also inflate the length of wrong answers
Show the answer
D. The reward paid only for correct, well-formatted answers, and longer reasoning helped on hard problems; a normalization bias in GRPO's loss can also inflate the length of wrong answers
Nothing in the rule-based reward mentioned length; longer reasoning was reinforced because it raised the success rate. Liu et al. (2025, Dr. GRPO) showed that per-response length normalization in GRPO's loss also favors longer incorrect answers, so part of such growth can be an artifact.
An RL-trained model beats its base model at pass@1 but loses at pass@256. What must have happened on some problems?
- RL increased their success probability
- The base model memorized them
- RL lowered their success probability, so that 256 attempts now fail on them more often than the base model's 256 attempts did
- Nothing: pass@256 is too noisy to compare
Show the answer
C. RL lowered their success probability, so that 256 attempts now fail on them more often than the base model's 256 attempts did
Raising every problem's success probability raises pass@k for every k. Losing at large k therefore requires some problems whose success probability fell; in the studies, these are typically problems that became nearly unreachable, the narrowing that the sharpening hypothesis describes.
Go deeper
- GRPO & Critic-Free Policy Optimization · Group-relative advantages, RLOO, and the biases hidden in normalization.
- What RL Adds to a Language Model · Verifiable rewards, emergent long reasoning, and the pass@k debate.
- Training Multi-Turn Agents · Credit assignment over long tool-using episodes, and process versus outcome rewards.
Further reading
- Z. Shao et al., "DeepSeekMath: Pushing the limits of mathematical reasoning in open language models," arXiv:2402.03300 (2024).
- D. Guo et al. (DeepSeek-AI), "DeepSeek-R1 incentivizes reasoning in LLMs through reinforcement learning," Nature 645, 633–638 (2025).
- A. Ahmadian, C. Cremer, M. Gallé, M. Fadaee, J. Kreutzer, O. Pietquin, A. Üstün & S. Hooker, "Back to basics: Revisiting REINFORCE-style optimization for learning from human feedback in LLMs," ACL (2024).
- Y. Yue et al., "Does reinforcement learning really incentivize reasoning capacity in LLMs beyond the base model?" NeurIPS (2025).