Sam Babichenko

Reading notes / Reinforcement learning for reasoning

DAPO and Dr. GRPO

Yu et al., 2025; Liu et al., 2025

Sampling
q;q; oi;o_i; oi,to_{i,t}question; ii-th sampled answer; its tt-th token
G;G; ∣oi∣|o_i|answers per question; length of oio_i in tokens
πθ;\pi_\theta; πold\pi_{\rm old}policy being trained; policy that sampled the group
ρi,t\rho_{i,t}probability ratio of token oi,to_{i,t}, current over sampling policy
Rewards and advantages
Ri;R_i; Rˉ;\bar R; std⁡(R)\operatorname{std}(R)reward of oio_i; group mean; group standard deviation
A^i\hat A_iGRPO advantage (Ri−Rˉ)/std(R)(R_i-\bar R)/\mathrm{std}(R)
ppfraction of a group's answers that are correct (Step 2)
Rlen(y)R_{\rm len}(y)DAPO's soft length penalty for response yy
Constants
ε\varepsilonsymmetric clip range of GRPO and PPO (0.2)
εlow,\varepsilon_{\rm low}, εhigh\varepsilon_{\rm high}DAPO's lower and upper clip ranges (0.2 and 0.28)
Lmax⁡,L_{\max}, LcacheL_{\rm cache}DAPO's generation limit (20,480) and penalty band width (4,096)

Context. After DeepSeek-R1, open attempts to reproduce DeepSeek's model trained with answer-checking rewards by reinforcement learning directly from a pretrained base model, with no supervised stage ran group relative policy optimization: a policy-gradient method that samples a group of answers to each question, gives each answer its reward minus the group mean, divided by the group's standard deviation, as its advantage, and clips each update so the policy moves only a little with answer-checking rewards on open pretrained language models that have had no instruction tuning or other fine-tuning and ran into trouble. On Qwen2.5-32B a straightforward GRPO run reached 30% accuracy on the 30 problems of the 2024 American Invitational Mathematics Examination, each with an integer answer, against 47% reported by DeepSeek for the same base model, with the policy's the average entropy of the policy's next-token distributions on its own samples, a measure of how much its sampling still varies collapsing early; other runs produced ever longer answers. DAPO (Yu et al., 2025) and Dr. GRPO (Liu et al., 2025) each trace such failures to specific terms in GRPO's objective and change them. Both drop the a term proportional to the Kullback-Leibler divergence of the trained policy from a reference model, subtracted from the objective to keep the policy near that model and both change how per-token losses are averaged; DAPO also raises the upper clip bound, discards groups whose answers all get the same reward and softens the penalty on truncated answers, and Dr. GRPO also drops the division by the group's standard deviation. Liu et al. also look at the base models, and find that much of what R1-Zero-style training is credited with is already there before RL.

GRPO's two normalizations reweight its gradient in ways the reward does not ask for. Averaging each answer's token losses over its own length gives every answer the same total weight whatever its length, so a long wrong answer is penalized less per token than a short one, and length can grow while accuracy does not. Dividing by the group's reward standard deviation gives more weight to questions that nearly every answer, or nearly none, gets right. The symmetric clip limits how fast unlikely tokens can gain probability, which speeds entropy collapse, and groups whose answers all get the same reward contribute no gradient. Each fix removes one of these effects, and with both normalizations removed GRPO is REINFORCE leave-one-out: the policy gradient in which each answer's baseline is the mean reward of the other answers sampled for the same question, the leave-one-out policy gradient, up to a constant step size.

Setting. For a question qq, sample the number of answers sampled per question: 16 in DAPO, 8 in Liu et al. answers o1,…,oGo_1,\dots,o_G from the sampling policy the policy as it was when the group was sampled; the policy being trained is πθ\pi_\theta and score each with a verifiable reward RiR_i: 1 for a correct final answer and 0 otherwise in Liu et al., +1+1 or −1-1 in DAPO. Write ∣oi∣|o_i| for the length of oio_i in tokens, Rˉ\bar R and std⁡(R)\operatorname{std}(R) for the mean and standard deviation of the group's rewards, 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 token tt of oio_i=πθ(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 of oio_i. GRPO gives every token of oio_i the advantage A^i=(Ri−Rˉ)/std⁡(R)\hat A_i=(R_i-\bar R)/\operatorname{std}(R) and maximizesE[1G∑i1∣oi∣⏟length∑tmin⁡(ρi,tA^i,clip⁡(ρi,t,1−ε,1+ε)A^i)],\begin{aligned}\mathbb E\Big[&\frac1G\sum_i\underbrace{\frac1{|o_i|}}_{\text{length}}\sum_t\min\big(\rho_{i,t}\hat A_i,\\&\operatorname{clip}(\rho_{i,t},1-\varepsilon,1+\varepsilon)\hat A_i\big)\Big],\end{aligned}here with no KL term, where the clip range, 0.2 by default: for a token with positive advantage, the term stops contributing gradient once ρi,t>1+ε\rho_{i,t}\gt1+\varepsilon, and for negative advantage once ρi,t<1−ε\rho_{i,t}\lt1-\varepsilon is the clip range. Dr. GRPO replaces A^i\hat A_i by Ri−RˉR_i-\bar R and divides each answer's summed token losses by one constant for all answers, such as the generation budget, instead of by ∣oi∣|o_i|. DAPO keeps A^i\hat A_i, divides the summed token losses of the group by its total length ∑i∣oi∣\sum_i|o_i|, clips at 1−εlow1-\varepsilon_{\rm low} and 1+εhigh1+\varepsilon_{\rm high} with separate lower and upper clip ranges, 0.2 for the lower and 0.28 for the upper in DAPO, and trains only on groups with why: if every answer in a group gets the same reward, every Ri−RˉR_i-\bar R is 0 and the group adds nothing to the gradient except a smaller average (Step 6).

Main findings (all empirical except the bias computation). (a) DAPO, on Qwen2.5-32B with 17k math problems whose answers were rewritten as integers, reaches 50% on AIME 2024 (accuracy averaged over 32 samples per problem) against 30% for plain GRPO and 47% for DeepSeek's R1-Zero recipe on the same base model, in half of DeepSeek's training steps. Adding the techniques one at a time gives 30, 36 (masking truncated answers), 38 (higher upper clip), 41 (soft length penalty), 42 (token-level averaging) and 50 (dynamic sampling). (b) Liu et al. show that dividing by ∣oi∣|o_i| favors short correct answers and long wrong ones, and dividing by std⁡(R)\operatorname{std}(R) favors questions solved by nearly all or nearly no answers. On a 1.5B model, GRPO's wrong answers keep lengthening after reward levels off, while Dr. GRPO keeps them shorter at equal or better accuracy, consistently over three seeds. (c) Their minimal recipe, Dr. GRPO on Qwen2.5-Math-7B with a dataset of competition math problems in five difficulty levels, scored by exact final answer problems of levels 3 to 5 and the Qwen-Math template for 27 hours on eight A100 GPUs, scores 43.3% on AIME 2024. (d) Base models matter: the Qwen2.5-Math models answer best with no the fixed text wrapped around each question, such as R1's instruction to reason inside think tags before answering at all, and DeepSeek-V3-Base already writes self-reflection phrases such as "wait" and "aha" before RL.

Consequences. For RL with verifiable rewards these papers propose several defaults: no KL penalty, token losses summed and divided by a constant or by the group's token count, no division by the group's standard deviation, an upper clip range a little above the lower one, groups with all-equal rewards filtered out, and truncated answers masked or penalized gently. Growing response length is no evidence of learned reasoning by itself; the length of wrong answers, and accuracy at a fixed length, say more. Before crediting RL with a gain, score the base model with the template that suits it, since a mismatched template can suppress ability that RL then appears to create.

Step 1 (Liu et al.)

Dividing by ∣oi∣|o_i| favors short correct answers and long wrong ones. All tokens of oio_i share the advantage, so with ratios near 1, answer ii's contribution to GRPO's gradient isA^iG ∣oi∣∑t=1∣oi∣∇θlog⁡πθ(oi,t∣q,oi,<t)=A^iG ∣oi∣∇θlog⁡πθ(oi∣q),\begin{aligned}&\frac{\hat A_i}{G\,|o_i|}\sum_{t=1}^{|o_i|}\nabla_\theta\log\pi_\theta(o_{i,t}\mid q,o_{i,\lt t})\\&\quad=\frac{\hat A_i}{G\,|o_i|}\nabla_\theta\log\pi_\theta(o_i\mid q),\end{aligned}while the policy gradient of expected reward weights ∇θlog⁡πθ(oi∣q)\nabla_\theta\log\pi_\theta(o_i\mid q) by the advantage alone. The extra factor 1/∣oi∣1/|o_i| makes a short correct answer gain more probability than a long one, and a long wrong answer lose less than a short one, so the update drifts toward long wrong answers whatever the reward says about length. The same factor appears in open-source proximal policy optimization: the clipped policy-gradient method with a learned value model that GRPO modifies code for language models, which averages the loss over each response's tokens (or the batch's), although PPO's objective sums over tokens. Dividing the summed token losses by a constant, such as the maximum generation length, removes it. With the standard deviation also removed, the advantage is Ri−Rˉ=G−1G(Ri−1G−1∑j≠iRj)R_i-\bar R=\frac{G-1}{G}\big(R_i-\frac1{G-1}\sum_{j\ne i}R_j\big), the leave-one-out advantage of RLOO times a constant, and the gradient is the plain policy gradient with that baseline.

Step 2 (Liu et al.)

Dividing by the group's standard deviation favors questions that are nearly always or nearly never solved. The worked numbers below are my computation, not in the paper. With 0-1 rewards, let a fraction pp of the group be correct. Then Ri−RˉR_i-\bar R is 1−p1-p for correct answers and −p-p for wrong ones, and the group's standard deviation is p(1−p)\sqrt{p(1-p)} (using the population formula). The total weight of a question, ∑i∣Ri−Rˉ∣\sum_i|R_i-\bar R|, is 2Gp(1−p)2Gp(1-p), and dividing by the standard deviation turns it into∑i=1G∣A^i∣=2Gp(1−p),\sum_{i=1}^G|\hat A_i|=2G\sqrt{p(1-p)},larger by the factor 1/p(1−p)1/\sqrt{p(1-p)}, which is 2 at p=1/2p=1/2 and about 3.0 at p=1/8p=1/8. So the division boosts a question solved by one answer in eight 1.5 times as much as one solved by half (3.0 against 2), although its total weight, 2G7/8≈0.66 G2G\sqrt7/8\approx0.66\,G against GG, stays smaller, and the single correct answer gets advantage 7≈2.65\sqrt7\approx2.65. Normalizing advantages over a whole batch, the usual practice in RL, rescales every question by the same factor and changes no relative weight; per-group normalization weights questions by how close they are to all right or all wrong.

Step 3 (Liu et al.)

Removing the normalizations keeps wrong answers shorter at the same or better accuracy. They train Qwen2.5-1.5B with the R1 template on MATH questions with 8 answers per question, a 3,000-token budget, learning rate 10−610^{-6}, one update pass and no KL term. Under both methods length rises with reward at first; under GRPO it keeps rising after reward slows, and on the test benchmarks GRPO's wrong answers grow much longer than Dr. GRPO's. Ablating the two terms separately (on a 3K mix of ASDiv, MATH and pre-2023 AIME questions), removing the length factor accounts for most of the difference in length, and removing either term raises training reward and test accuracy over GRPO. On Llama-3.2-3B after math pretraining, GRPO shows accuracy and length rising together, which could be read as long reasoning emerging, while under Dr. GRPO length does not grow in the same way. Over three independent runs per method, Dr. GRPO's mean curves are better on both length and final accuracy, a gap the authors call statistically significant.

Step 4 (Liu et al.)

Much of what R1-Zero-style training shows is already in the base model and the template. Without a template, Qwen2.5-Math-7B averages 38.2% across five math benchmarks, against 23.8% with four-shot prompting and 0.0% with the R1 template; the authors suspect pretraining on concatenated question-answer text. Training Qwen2.5-Math-1.5B with a matching template on simple grade-school questions nearly doubles its accuracy on harder ones, so RL there mostly restores and reinforces behavior the template had suppressed; with the mismatched R1 template, broader question sets matter more. DeepSeek-V3-Base writes self-reflection phrases before any RL, and in R1-Zero's own outputs, answers with self-reflection are not more accurate than those without on nearly half of the questions tested. Continued pretraining of Llama-3.2-3B on math text, and then on concatenated question-answer text, raises the accuracy RL reaches from 6.8% to 20.7% on the five-benchmark average.

Step 5 (Yu et al.)

The symmetric clip limits how fast unlikely tokens can rise, and raising only the upper bound keeps entropy up. For a token with positive advantage the clipped term has no gradient once ρi,t>1+ε\rho_{i,t}\gt1+\htmlData{gr=g11}{\varepsilon}, so within one round of updates the objective stops pushing its probability up at (1+ε)πold(1+\varepsilon)\htmlData{gr=g9}{\pi_{\rm old}}: 0.012 for a token at 0.01 when ε=0.2\varepsilon=0.2, while for a token at 0.9 the cap, 1.08, is above 1 and does not bind. The tokens that hit the upper clip have mean probability below 0.2. With εhigh=0.28\varepsilon_{\rm high}=0.28 and εlow=0.2\varepsilon_{\rm low}=0.2, entropy no longer collapses and accuracy improves (36 to 38 in the cumulative ablation). The lower bound stays at 0.2, since a larger εlow\varepsilon_{\rm low} would let wrong answers push tokens' probabilities to zero and collapse the sampling space.

Step 6 (Yu et al.)

Groups with all-equal rewards carry no gradient, and dynamic sampling refills the batch with informative ones. If every answer to a question is correct (or every one wrong), every advantage is zero and the question contributes nothing, but it still counts in the batch, so the gradient is smaller and noisier. The fraction of questions answered correctly by all 16 samples rises steadily during training. DAPO samples more questions than needed and keeps only those with at least one correct and at least one wrong answer in the group until the batch is full. This gives the largest single gain in the ablation, 42 to 50, and reaches a given accuracy in fewer steps; the extra sampling adds little wall-clock time because each round's generation time is set by its longest answers.

Step 7 (Yu et al.)

Token-level averaging and gentler handling of truncated answers stabilize long chains of thought. Dividing the group's summed token losses by ∑i∣oi∣\sum_i|o_i| gives every token in the group equal weight, so repetitive or gibberish tokens in a long answer are penalized as much as tokens in a short one; with it, entropy and length grow more steadily, and accuracy goes from 41 to 42. Answers cut off at the length limit got a punitive reward by default, which penalizes sound reasoning only for being long. excluding answers cut off at the length limit from the loss removes them from the loss (30 to 36), and a soft penalty added to the correctness reward then tells the model to stay short (38 to 41): with the hard generation limit, 20,480 tokens in DAPO the limit and the width of the band before the limit over which the length penalty rises, 4,096 tokens in DAPO the width of a band before it, an answer yy getsRlen(y)=(Lmax⁡−Lcache)−∣y∣Lcachefor ∣y∣≤Lmax⁡and ∣y∣>Lmax⁡−Lcache,\begin{aligned}R_{\rm len}(y)&=\frac{(L_{\max}-L_{\rm cache})-|y|}{L_{\rm cache}}\\&\quad\text{for }|y|\le L_{\max}\\&\quad\text{and }|y|\gt L_{\max}-L_{\rm cache},\end{aligned}0 below the band and −1-1 past the limit, so the penalty falls linearly from 0 at 16,384 tokens to −1-1 at 20,480. DAPO also drops the KL penalty, because a long-reasoning policy is expected to move far from its start; Liu et al. add that a rule-based verifier, unlike a learned reward model, stays accurate wherever the policy goes.

Limits. DAPO's ablation is one cumulative sequence on one model, each technique added once in one order, and AIME 2024 has 30 problems, so a point of accuracy is less than a third of one problem; averaging 32 samples per problem reduces sampling noise but not that granularity. DAPO also reports that training reward correlates little with validation accuracy. Liu et al.'s RL experiments use 1.5B to 7B models with 3,000-token budgets, so the size of the length effect at R1's scale and lengths is not measured. DAPO's token-level averaging still divides by each group's total length, so a group of long answers has less weight per token than a group of short ones, which Dr. GRPO's constant avoids; neither paper compares the two directly. Both papers drop the KL penalty for rule-based rewards; with a learned reward the argument for dropping it does not apply.

Terms

Length bias
GRPO's 1/∣oi∣1/|o_i| scales each answer's gradient by its inverse length: short right answers and long wrong ones gain
Difficulty bias
dividing by the group's std raises the total weight of a question by 1/p(1−p)1/\sqrt{p(1-p)} for 0-1 rewards
Dr. GRPO
advantage Ri−RˉR_i-\bar R, token losses summed and divided by a constant; equals RLOO up to a step size
Clip-Higher
εhigh=0.28>εlow=0.2\varepsilon_{\rm high}=0.28\gt\varepsilon_{\rm low}=0.2, so unlikely tokens with positive advantage can rise faster
Entropy collapse
the policy's sampling variety falls early, groups become identical and stop carrying signal
Dynamic sampling
keep only groups with mixed outcomes, sampling more until the batch is full
Token-level loss
divide the group's summed token losses by ∑i∣oi∣\sum_i|o_i|, so every token weighs the same
Overlong filtering
exclude truncated answers from the loss instead of scoring them as wrong
Soft overlong penalty
linear from 0 at Lmax⁡−LcacheL_{\max}-L_{\rm cache} to −1-1 at Lmax⁡L_{\max}, added to the reward
Template effect
Qwen2.5-Math-7B averages 38.2 with no template, 0.0 with the R1 template
DAPO ablation
AIME 2024: 30, 36, 38, 41, 42, 50 as the techniques are added

Quiz

  1. Dr. GRPO removes both the length factor and the standard-deviation division. What estimator results?
  2. Why does scoring truncated answers as wrong add noise to the reward, according to DAPO?
  3. During a GRPO run, mean response length keeps rising after training reward has leveled off. What does Dr. GRPO's analysis suggest checking?

Sources