Sam Babichenko

Reading notes / Reinforcement learning for reasoning

GRPO and DeepSeek-R1

Shao et al., 2024; Guo et al., 2025

Sampling and policies
q;q; oi;o_i; oi,to_{i,t}question; ii-th sampled answer; its tt-th token
GGanswers sampled per question
∣oi∣|o_i|length of answer oio_i in tokens
πθ;\pi_\theta; θ\thetapolicy being trained; its parameters
πold\pi_{\rm old}policy that sampled the current group
πref\pi_{\rm ref}reference policy of the KL penalty
Rewards and objective
ri;r_i; rˉ\bar rreward of oio_i; mean reward of the group
A^i\hat A_igroup-normalized advantage of oio_i, given to all its tokens
ρi,t\rho_{i,t}probability ratio of token oi,to_{i,t} under πθ\pi_\theta and πold\pi_{\rm old}
J(θ)J(\theta)GRPO objective
V;V; Rt;R_t; sts_tvalue model; per-token reward; prefix (q,o<t)(q,o_{\lt t}), in PPO
δt\delta_tone-step value error Rt+γV(st+1)−V(st)R_t+\gamma V(s_{t+1})-V(s_t), in GAE
KKnumber of samples in Pass@K and Maj@K
Constants
ε\varepsilonclip range of the GRPO and PPO objectives (10 in R1's first RL stage)
β\betaKL weight: 0.04 in DeepSeekMath, 0.001 in R1
λ,\lambda, γ\gammaGAE's bias-variance parameter and discount, in the PPO comparison

Context. The usual way to fine-tune a language model with reinforcement learning, the KL-regularized objective of InstructGPT optimized with proximal policy optimization: a policy-gradient method that maximizes a clipped surrogate of expected reward, so each update moves the policy only a little from the one that produced the samples, trains a reward model on human comparisons and a a network, usually a copy of the language model with a scalar output, trained to predict the reward still to come from each prefix of a response; PPO subtracts its prediction from the observed return to make the gradient less noisy next to the policy, each about as large as the policy itself. For math and code there is a cheaper signal: a program can check the final answer or run the tests. DeepSeekMath (Shao et al., 2024) introduced group relative policy optimization: PPO's clipped objective with each answer's advantage computed from the rewards of a group of answers sampled for the same question, and no value model, a variant of PPO that drops the value model and scores each sampled answer against the other answers to the same question. DeepSeek-R1 (Guo et al., 2025) ran GRPO with rule-based rewards directly on a a pretrained language model that has had no instruction tuning or other fine-tuning, with no supervised stage, and reported that long, self-checking the intermediate reasoning a model writes out before its final answer grew out of the reward alone (the model R1-Zero); a short pipeline around that run produced a general-purpose model, R1.

Reinforcement learning improves reasoning when the reward is a check the policy cannot fool and the starting model already solves some of the problems. The gradient then needs only a comparison among a few answers to the same question: answers that score above the group's average are made more likely and the others less likely, so no value model has to be learned. In DeepSeekMath the gain showed up in majority voting while the chance that at least one of 64 samples is right stayed flat, so RL mostly made correct answers the model could already produce more likely. In R1-Zero, with a 671B base model and ten thousand steps, the model also learned to write much longer solutions and to check its own work.

Setting. For a question qq, GRPO samples a group of the number of answers sampled per question: 64 in DeepSeekMath, 16 in R1 answers o1,…,oGo_1,\dots,o_G from the policy as it was when the answers were sampled; the policy being trained, πθ\pi_\theta with parameters θ\theta, moves away from it during the updates on those answers, scores each with a reward rir_i, and gives every token of oio_i the same how much better an answer did than expected for its question; the policy gradient raises the probability of answers with positive advantage and lowers it for negative,A^i=ri−mean⁡(r1,…,rG)std⁡(r1,…,rG).\hat A_i=\frac{r_i-\operatorname{mean}(r_1,\dots,r_G)}{\operatorname{std}(r_1,\dots,r_G)}.Write oi,to_{i,t} for token tt of oio_i, ∣oi∣|o_i| for its length, and the probability ratio πθ(oi,t∣q,oi,<t)/πold(oi,t∣q,oi,<t)\pi_\theta(o_{i,t}\mid q,o_{i,\lt t})/\pi_{\rm old}(o_{i,t}\mid q,o_{i,\lt t}) of that token under the current and the sampling policy=πθ(oi,t∣q,oi,<t)/πold(oi,t∣q,oi,<t)=\pi_\theta(o_{i,t}\mid q,o_{i,\lt t})/\pi_{\rm old}(o_{i,t}\mid q,o_{i,\lt t}), the probability ratio of token tt. GRPO maximizes PPO's clipped surrogate, averaged first over the tokens of each answer and then over the group, minus a an estimate of the Kullback-Leibler divergence of the trained policy from a reference policy, times a weight, subtracted from the objective to keep the policy near it to a reference policy πref\pi_{\rm ref}:J(θ)=E[1G∑i=1G1∣oi∣∑t=1∣oi∣min⁡(ρi,tA^i,clip⁡(ρi,t,1−ε,1+ε)⏟clipped ratioA^i)]−β DKL(πθ∥πref)⏟KL penalty,\begin{aligned}J(\theta)=\mathbb E\Big[&\frac1G\sum_{i=1}^G\frac1{|o_i|}\sum_{t=1}^{|o_i|}\min\big(\rho_{i,t}\hat A_i,\\&\underbrace{\operatorname{clip}(\rho_{i,t},1-\varepsilon,1+\varepsilon)}_{\text{clipped ratio}}\hat A_i\big)\Big]\\&-\underbrace{\beta\,D_{\rm KL}(\pi_\theta\|\pi_{\rm ref})}_{\text{KL penalty}},\end{aligned}where the expectation is over questions and groups sampled from πold\pi_{\rm old}, with PPO's clip range: once ρi,t\rho_{i,t} leaves [1−ε,1+ε][1-\varepsilon,1+\varepsilon] in the direction the advantage favors, that token's term stops contributing gradient the clip range and the weight of the KL penalty: 0.04 in DeepSeekMath, 0.001 in R1 the KL weight. The KL is estimated per token by πref/πθ−log⁡(πref/πθ)−1\pi_{\rm ref}/\pi_\theta-\log(\pi_{\rm ref}/\pi_\theta)-1, which is never negative. In R1 the reward is rule-based: an accuracy reward of 1 if the final answer matches the reference (or the code passes the tests) and 0 otherwise, plus a format reward for putting the reasoning between <think> tags.

Main findings (all empirical). (a) In DeepSeekMath, GRPO with a learned reward model, run on about 144k questions from grade-school math word problems, scored by exact final answer and competition math problems in five difficulty levels, scored by exact final answer, raises DeepSeekMath-Instruct 7B from 46.8% to 51.7% on MATH and from 82.9% to 88.2% on GSM8K, and also improves benchmarks with no questions in the RL data; it raises the fraction of questions on which the most common answer among KK samples is correct at every KK up to 64 but the fraction of questions on which at least one of KK samples is correct only at small KK. (b) In R1-Zero, rule-based GRPO from DeepSeek-V3-Base raises the American Invitational Mathematics Examination, 15 hard competition problems per paper with integer answers; AIME 2024 has 30 2024 accuracy averaged over several sampled answers per question (here at temperature 0.6), the expected accuracy of a single sample from 15.6% to 77.9% (86.7% by majority vote over 16 samples), while the average response length grows steadily to many thousands of tokens. (c) For R1, thousands of curated long solutions before RL, a reward for staying in one language, a supervised round on 800k samples and a final RL stage that adds reward models give a readable general model at 79.8% on AIME 2024. Fine-tuning a 32B open base model on 800k R1 outputs does better than running large-scale RL on it (72.6% against 47.0% on AIME 2024), the one size where the two were compared. (d) In one comparison PPO comes close to GRPO when the bias-variance parameter λ\lambda of its advantage estimator (GAE, Step 1) is 1, and is much worse at the usual default of 0.95.

Consequences. The recipe that followed, now called reinforcement learning in which the reward comes from a program that checks the answer (exact match, unit tests) instead of a learned reward model, is the one R1 states: hard questions with checkable answers, a reliable verifier, a large base model and many RL steps, with the value model replaced by a group baseline. Dropping the value model saves memory and compute and avoids learning per-token values for a reward that arrives only at the end of a long answer whose early parts may later be revised; the PPO comparison suggests a well-tuned PPO gets close, so the case for GRPO rests on cost. A learned reward is the weak point. R1 kept rule-based rewards for reasoning and used its preference reward models only in the last 400 steps of training, because longer training against them led to the policy raising a learned reward through flaws of the reward model, without the improvement the reward stands for. For smaller models, fine-tuning on a strong reasoner's outputs beat RL from the base model in R1's one comparison, at 32B, and costs far less.

Step 1 (DeepSeekMath)

The group mean replaces the value model as the baseline. PPO computes each token's advantage with generalized advantage estimation: A^t=∑l≥0(γλ)lδt+l\hat A_t=\sum_{l\ge0}(\gamma\lambda)^l\delta_{t+l} with δt=Rt+γV(st+1)−V(st)\delta_t=R_t+\gamma V(s_{t+1})-V(s_t), where RtR_t is the reward at token tt, VV the value model, γ\gamma a discount and λ∈[0,1]\lambda\in[0,1] trades bias for variance from a value model trained alongside the policy, and in reinforcement learning from human feedback: RL against a reward model trained on human comparisons of responses the reward model scores only the last token, so the value model must predict the final reward from every prefix. GRPO samples GG answers per question and uses their mean reward as the baseline, dividing by their standard deviation; with a reward on the whole answer, every token of oio_i gets A^i\hat A_i. The group mean rˉ\bar r includes rir_i itself; a standard identity, not stated in the paper, shows that centering on it equals centering on the leave-one-out mean, up to a constant factor,ri−rˉ=G−1G(ri−1G−1∑j≠irj).r_i-\bar r=\tfrac{G-1}{G}\Big(r_i-\frac1{G-1}\sum_{j\ne i}r_j\Big).The leave-one-out mean does not depend on oio_i, so subtracting it leaves the expected gradient unchanged (the score ∇θlog⁡πθ(oi∣q)\nabla_\theta\log\pi_\theta(o_i\mid q) has mean zero), and the centered estimator has the direction of the policy gradient on average; the division by the group's standard deviation changes how much each question weighs, which Liu et al. (2025) later examined. The KL penalty moves out of the per-token reward, where PPO for RLHF puts it, into the loss, and its per-token estimator has mean DKL(πθ∥πref)D_{\rm KL}(\pi_\theta\|\pi_{\rm ref}) when tokens are drawn from πθ\pi_\theta. DeepSeekMath also defines a process-supervision variant, in which a a learned model that scores each intermediate reasoning step, as opposed to only the final answer scores each step, the step scores are normalized across the group, and each token gets the sum of the normalized scores of the steps from it onward.

Step 2 (DeepSeekMath)

Sampling from the current policy and penalizing wrong answers both add accuracy. Shao et al. write each method's gradient as an average over a data source of a per-token gradient coefficient times ∇θlog⁡πθ(ot∣q,o<t)\nabla_\theta\log\pi_\theta(o_t\mid q,o_{\lt t}). Supervised fine-tuning uses human answers with coefficient 1. sampling answers from a fixed model, keeping the correct ones, and fine-tuning on them with ordinary next-token loss samples from the supervised model and gives its correct answers coefficient 1; online RFT does the same with samples from the current policy. GRPO's coefficient is A^i+β(πref/πθ−1)\hat A_i+\beta(\pi_{\rm ref}/\pi_\theta-1), graded by reward and negative for answers below the group mean. On DeepSeekMath-Instruct 1.3B, online RFT pulls ahead of RFT later in training, once the policy has moved away from the supervised model; GRPO beats online RFT; and process supervision beats outcome supervision. On the 7B model, two rounds of iterative RL, which retrain the reward model on the policy's samples (with 10% of the old data replayed) and reset the reference, add more, mostly in the first round. The method comparisons are on one 1.3B model.

Step 3 (DeepSeekMath)

RL raised Maj@K at every K and Pass@K only at small K. At temperature 0.7 on GSM8K and MATH, the RL model's Maj@K exceeds the Instruct model's for KK from 1 to 64. Its Pass@K is higher at K=1K=1, where Pass@1 and Maj@1 are the same number, but the gap is gone by K=16K=16, and on GSM8K the Instruct model is slightly ahead at K=64K=64 (read off the paper's Figure 7). The authors read this as RL making the output distribution more robust: it makes correct answers that were already among the KK samples the most common and adds few problems the model could not already solve. They suggest two reasons specific to their setup, that the RL questions came from the supervised data and that sampling was plain sampling each token from the smallest set of most likely tokens whose total probability exceeds a threshold. The measurement is for one 7B model with answers capped at 1,024 tokens; it does not settle what longer RL from a base model does, which is what R1 tests.

Step 4 (R1)

R1-Zero is GRPO on a base model with a rule-based reward and a fixed template. The policy starts from DeepSeek-V3-Base, a 671B a transformer in which each token passes through only a few of many feed-forward blocks, so only part of the parameters is active per token model, and a template asks it to reason inside <think> tags and answer inside <answer> tags, with no guidance on how to reason. The reward is why: R1 found that neural reward models, outcome or process, are open to reward hacking during large-scale RL, and retraining them adds compute and complexity, on math, code, STEM multiple-choice and logic questions. Training uses learning rate 3×10−63\times10^{-6}, β=0.001\beta=0.001, sampling temperature 1, G=16G=16, and 32 questions per step, so each step trains on 512 answers; each rollout generates 8,192 answers, split into 16 minibatches of 512 and trained on once (the note's reading: one rollout feeds 16 steps). The maximum length is 32,768 tokens until step 8,200 and 65,536 after, and both accuracy and length jump at the switch. The run lasts 10,400 steps, 1.6 epochs over the data, and the reference policy is replaced by the current policy every 400 steps.

Step 5 (R1)

Accuracy and response length grow together, and reflective behavior appears during training. AIME 2024 pass@1 rises from 15.6% to 77.9%. The average training response length rises steadily to many thousands of tokens without any length reward. On MATH, the easy levels are solved early and accuracy on the hardest level goes from about 0.55 to 0.90. Counts of reflective words ("wait", "mistake", "verify", "check" and others) rise five- to sevenfold over training, and "wait" in particular is nearly absent early, occasional between steps 4,000 and 7,000, and frequent after 8,000; the paper shows one transcript in which the model stops, writes that this is an "aha moment", and re-derives its answer. All of this is measured on one run. It shows that these behaviors arose without examples of them in training, since R1-Zero has no supervised stage before RL; it does not show they were absent from the base model, and later work found them there (see the limits below).

Step 6 (R1)

The R1 pipeline restores readability and general skills, at an early cost in reasoning. R1-Zero mixes English and Chinese and is hard to read, and its RL covered only reasoning. R1 first fine-tunes the base model on thousands of long solutions written in a first-person, readable style (R1-Zero outputs rewritten by annotators and then by a model), runs reasoning RL with a the fraction of words in the chain of thought that are in the target language, added to the reward (which costs a little accuracy in an ablation), then fine-tunes on 800k samples of reasoning and other data, and ends with an RL stage that combines rule rewards with helpfulness and safety reward models, at temperature 0.7. The preference rewards enter only in the last 400 of that stage's 1,700 steps. Along the way AIME 2024 pass@1 is 59.0% after the small first fine-tune, against R1-Zero's 77.9%, and recovers to 79.8% for R1, while a benchmark of open-ended instructions on which a strong model judges which of two responses is better; LC is its length-controlled win rate length-controlled win rate goes from R1-Zero's 24.7% to R1's 87.6%. The paper sets the clip range ε\varepsilon to 10 in the first RL stage and notes that small values remove the gradient of many tokens while large values destabilize training.

Step 7 (R1)

PPO nearly matches GRPO when GAE uses λ=1\lambda=1, not at 0.95. On MATH with DeepSeek-Coder-V2-Lite (16B mixture-of-experts, 2.4B active parameters), PPO with GAE at why: with λ=1\lambda=1, GAE's sum telescopes to the observed return minus V(st)V(s_t), so the value model enters only as a baseline and its errors add noise without bias (standard GAE algebra; the paper gives no reason) nearly reaches GRPO, while the common default λ=0.95\lambda=0.95 is considerably worse. The paper gives two further reasons to prefer GRPO for long chains of thought. A value model must predict the final reward from a partial answer whose content may later be revised, which is hard. And PPO's KL penalty enters the reward at every token, so the return accumulates it over the whole answer and implicitly penalizes length, while GRPO's KL term sits in the loss and is not summed into a return.

Step 8 (R1)

RL from a general base model worked from 32B up, and distillation beat it at 32B. Early attempts with a 7B dense and a 16B mixture-of-experts base model failed to improve AIME: as responses grew longer they became repetitive. Pure RL worked from 32B, 230B and 671B models. The threshold is not sharp: a math-specialized 7B base, Qwen2-Math-7B, trained with about 10,000 RL steps reached 22.3% on AIME 2024, against 7.9% for its instruct version. Qwen2.5-32B-Base trained with the same RL for over 10k steps reaches 47.0% on AIME 2024, against 72.6% for the same base model fine-tuned on 800k R1 outputs, and the fine-tuned with ordinary supervised loss on outputs generated by a stronger model 1.5B model scores 28.9% where GPT-4o scores 9.3%. Two methods gave no net benefit at R1's scale: a process reward model (steps are hard to define and to label, and a learned model gets hacked) and a search that grows a tree of partial solutions, choosing which branch to extend with a learned value model over reasoning steps (the token-level search space is too large and the value model too hard to train).

Limits. The evidence is mostly single training runs read off benchmark curves, and the reasoning behaviors are measured by counting words. Later analyses found self-reflection words in base models before any RL, DeepSeek-V3-Base among them, and traced part of the growth in response length to GRPO's per-answer length averaging (Liu et al., 2025). The Pass@K result is for one 7B model trained on questions from its own supervised data. DeepSeekMath's GRPO uses a learned reward model, while R1's uses rules, so the two papers support GRPO in different regimes.

Terms

GRPO
PPO's clipped objective with advantage (ri−rˉ)/std(r_i-\bar r)/\mathrm{std} from GG answers to one question; no value model
Group baseline
ri−rˉ=G−1G(ri−leave-one-out mean)r_i-\bar r=\tfrac{G-1}{G}(r_i-\text{leave-one-out mean}): unbiased up to a constant
KL in the loss
GRPO adds β\beta times a per-token KL estimate to the loss; PPO for RLHF subtracts it from each token's reward
Verifiable reward
1 if the answer matches the reference or the code passes the tests, else 0; plus a format reward in R1
R1-Zero
GRPO on DeepSeek-V3-Base with rule rewards and no supervised stage; AIME 2024 pass@1 15.6% to 77.9%
R1
cold-start fine-tune, reasoning RL with a language reward, 800k-sample fine-tune, final RL with reward models
Maj@K vs Pass@K
DeepSeekMath's RL raised the first at every K, the second only at small K: it sharpened answers the model could already produce
Gradient coefficient
per-token weight on ∇log⁡πθ\nabla\log\pi_\theta; 1 for SFT and RFT, A^i+β(πref/πθ−1)\hat A_i+\beta(\pi_{\rm ref}/\pi_\theta-1) for GRPO
PPO with λ=1\lambda=1
nearly matches GRPO in R1's comparison; λ=0.95\lambda=0.95 is much worse
Reward hacking
the policy raising a learned reward without real improvement; why R1 used rules for reasoning
Distillation
fine-tuning a small model on a strong model's outputs; beat RL from the base model at 32B (72.6% vs 47.0%)

Quiz

  1. GRPO trains no value model. What takes its place in the advantage?
  2. Why did R1 use rule-based rewards for reasoning questions instead of a neural reward model?
  3. R1 argues that PPO's usual KL handling works against long chains of thought. What is the mechanism?

Sources