GRPO: Learning from Groups of Responses

On this page

LLM Alignment: From PPO to DPO described PPO updates that use a learned value critic to estimate advantages. Group Relative Policy Optimization (GRPO) instead compares rewards among responses sampled for the same prompt. We derive this construction from DeepSeekMath, Section 4.1. We then examine the effects of subtracting the group mean, dividing by the group standard deviation, and using the resulting weights in a clipped update.

We begin with the baseline identity because replacing a critic by a sample group mean changes the dependence between a response and its update weight.

Recap: Which baselines preserve a reward gradient?

At a fixed prompt xx, let Sθ(x,Y)=∇θlog⁡πθ(Y∣x)S_\theta(x,Y)=\nabla_\theta\log\pi_\theta(Y\mid x). For a fixed reward and a prompt-only baseline, the earlier score calculation gives

EY∼πθ(⋅∣x)[(r(x,Y)−b(x))Sθ(x,Y)]=∇θEY∼πθ(⋅∣x)[r(x,Y)].\mathbb E_{Y\sim\pi_\theta(\cdot\mid x)} [(r(x,Y)-b(x))S_\theta(x,Y)] =\nabla_\theta\mathbb E_{Y\sim\pi_\theta(\cdot\mid x)}[r(x,Y)].

The baseline is fixed as the response varies. A mean computed from that same response group does not satisfy this independence argument directly; Section 2 calculates the resulting expectation.

1. One prompt, several sampled responses

Let X∈XX\in\mathcal X be a prompt, including its task context, in a finite prompt set. Its distribution ρ\rho may be the empirical distribution over a fixed prompt dataset. For a verification task, any fixed answer key is used by the scorer, not supplied as an extra policy input. Let Y(x)\mathcal Y(x) be a finite set of valid token sequences, with an end-of-sequence token and a specified maximum horizon. Deterministic stopping/padding operations have no trainable log-probability contribution.

We distinguish three policies:

πk=πθk(frozen rollout policy),πθ(updated policy),πref(frozen reference).\begin{aligned} \pi_k=\pi_{\theta_k}&\quad\text{(frozen rollout policy)},\\ \pi_\theta&\quad\text{(updated policy)},\\ \pi_{\rm ref}&\quad\text{(frozen reference)}. \end{aligned}

Assume differentiable positive probabilities on the same valid response support. For G≥2G\ge2, the group sampling law at iteration kk is

X∼ρ,Y1,…,YG∣X=x∼iidπk(⋅∣x),Pk(G)(x,y1:G)=ρ(x)∏i=1Gπk(yi∣x).\begin{aligned} X&\sim\rho,\\ Y_1,\ldots,Y_G\mid X=x& \overset{\rm iid}{\sim}\pi_k(\cdot\mid x), \\ P_k^{(G)}(x,y_{1:G}) &=\rho(x)\prod_{i=1}^G\pi_k(y_i\mid x). \end{aligned}

Thus responses are independent conditional on the prompt, not necessarily marginally. A batch consists of BB independent groups from Pk(G)P_k^{(G)}. Conditional on this batch, all sampled tokens, rewards, old-policy likelihoods, and computed advantages remain fixed during its optimizer updates.

Write Li=∣Yi∣L_i=|Y_i| for the number of scored response tokens, Hi,t=(X,Yi,<t)H_{i,t}=(X,Y_{i,<t}) for a prefix, and

πθ(yi∣x)=∏t=1Liπθ(yi,t∣hi,t),Sθ(x,yi):=∇θlog⁡πθ(yi∣x)=∑t=1Li∇θlog⁡πθ(yi,t∣hi,t).\begin{aligned} \pi_\theta(y_i\mid x) &=\prod_{t=1}^{L_i}\pi_\theta(y_{i,t}\mid h_{i,t}),\\ S_\theta(x,y_i) &:=\nabla_\theta\log\pi_\theta(y_i\mid x)\\ &=\sum_{t=1}^{L_i}\nabla_\theta\log\pi_\theta(y_{i,t}\mid h_{i,t}). \end{aligned}

These response log-probabilities are sums, not length averages. An average over token losses, introduced later, is a separate weighting choice.

Let r(x,y)∈Rr(x,y)\in\mathbb R be a bounded deterministic scorer, fixed throughout one rollout/update cycle, and set Ri=r(X,Yi)R_i=r(X,Y_i). A learned reward model can supply rr; a verifier can instead check an answer or run tests. GRPO does not require a learned reward model, but it still requires an informative reward.

In DeepSeek-R1-Zero, Sections 2.2.1–2.2.2, rule-based accuracy and format rewards supply this feedback. That is a particular reward design, not part of the mathematical definition of every GRPO run. A passed test need not certify every reasoning statement, and an imperfect verifier remains an imperfect training target.

Original DeepSeekMath Figure 4 compares PPO, whose policy sends a response to reference, reward and trained value models before generalized advantage estimation, with GRPO, which samples several responses and uses their reward scores in group computation without a value model. Yellow marks trained models and blue marks frozen models.
Figure 1. PPO's value critic and GRPO's group computation. Original figure from Shao et al. (2024), DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models, Figure 4. This is the source's learned-reward architecture. GRPO can instead use a fixed rule-based scorer; removing the value critic does not remove generation or reward evaluation. Full resolution ↗Figure excerpt for discussion; copyright remains with the authors/rightsholder.

2. What a group mean does to the reward gradient

To isolate the group baseline's effect, we first use full response scores without clipping, reward scaling, length averaging, or KL regularization. At a fixed prompt xx, define the expected reward

Vθ(x):=EY∼πθ(⋅∣x)[r(x,Y)].V_\theta(x) :=\mathbb E_{Y\sim\pi_\theta(\cdot\mid x)}[r(x,Y)].

Finite support permits differentiation under the sum. The likelihood-ratio identity and score identity give

∇θVθ(x)=∑yr(x,y)∇θπθ(y∣x)=EY∼πθ(⋅∣x)[r(x,Y)Sθ(x,Y)],EY∼πθ(⋅∣x)[Sθ(x,Y)]=∇θ∑yπθ(y∣x)=0.\begin{aligned} \nabla_\theta V_\theta(x) &=\sum_y r(x,y)\nabla_\theta\pi_\theta(y\mid x)\\ &=\mathbb E_{Y\sim\pi_\theta(\cdot\mid x)} [r(x,Y)S_\theta(x,Y)],\\ \mathbb E_{Y\sim\pi_\theta(\cdot\mid x)}[S_\theta(x,Y)] &=\nabla_\theta\sum_y\pi_\theta(y\mid x)=0. \end{aligned}

As in the policy-gradient baseline derivation, subtracting a fixed prompt-only b(x)b(x) preserves this gradient. A sample group mean requires more care because it includes the response whose score it multiplies.

A finite-group baseline identity

Proposition. Under the conditional iid law above, put Rˉ=G−1∑jRj\bar R=G^{-1}\sum_jR_j and Si=Sθk(x,Yi)S_i=S_{\theta_k}(x,Y_i). Then

EY1:G∼πk⊗G(⋅∣x)[1G∑i=1G(Ri−Rˉ)Si]=G−1G∇θVθ(x)∣θ=θk.\mathbb E_{Y_{1:G}\sim\pi_k^{\otimes G}(\cdot\mid x)} \left[\frac1G\sum_{i=1}^G(R_i-\bar R)S_i\right] =\frac{G-1}{G} \left.\nabla_\theta V_\theta(x)\right|_{\theta=\theta_k}.

To prove this, write gk(x)=∇θVθ(x)∣θkg_k(x)=\nabla_\theta V_\theta(x)|_{\theta_k}. For j≠ij\ne i, conditional independence and the zero-score identity imply

E[RjSi∣X=x]=E[Rj∣X=x] E[Si∣X=x]=0,E[RiSi∣X=x]=gk(x).\begin{aligned} \mathbb E[R_jS_i\mid X=x] &=\mathbb E[R_j\mid X=x]\, \mathbb E[S_i\mid X=x]=0,\\ \mathbb E[R_iS_i\mid X=x]&=g_k(x). \end{aligned}

Consequently,

E[RˉSi∣X=x]=1GE[RiSi∣X=x]+1G∑j≠iE[RjSi∣X=x]=gk(x)G,E[(Ri−Rˉ)Si∣X=x]=(1−1G)gk(x).\begin{aligned} \mathbb E[\bar R S_i\mid X=x] &=\frac1G\mathbb E[R_iS_i\mid X=x]\\ &\quad+\frac1G\sum_{j\ne i}\mathbb E[R_jS_i\mid X=x]\\ &=\frac{g_k(x)}G,\\ \mathbb E[(R_i-\bar R)S_i\mid X=x] &=\left(1-\frac1G\right)g_k(x). \end{aligned}

Averaging over ii proves the claim. Averaging over X∼ρX\sim\rho, with ρ\rho fixed, gives the same factor for ∇θEX∼ρ[Vθ(X)]∣θk\nabla_\theta\mathbb E_{X\sim\rho}[V_\theta(X)]|_{\theta_k}.

Next define the leave-one-out baseline

b−i=1G−1∑j≠iRj,Ri−b−i=GG−1(Ri−Rˉ).b_{-i}=\frac1{G-1}\sum_{j\ne i}R_j,\qquad R_i-b_{-i}=\frac{G}{G-1}(R_i-\bar R).

The other responses are conditionally independent of YiY_i, so

E[1G∑i(Ri−b−i)Si∣X=x]=gk(x).\mathbb E\left[\frac1G\sum_i(R_i-b_{-i})S_i\mid X=x\right] =g_k(x).

This establishes an unbiased estimator at the rollout policy when we use the full response score without dividing by a group standard deviation. It does not show that every group baseline reduces variance. Standardizing the rewards or clipping the update can change the expectation.

3. Group-relative advantages are not just centering

For an explicit convention, use the divisor-GG standard deviation

sR={1G∑i=1G(Ri−Rˉ)2}1/2,A^i={(Ri−Rˉ)/sR,sR>0,0,sR=0.s_R=\left\{\frac1G\sum_{i=1}^G(R_i-\bar R)^2\right\}^{1/2}, \qquad \widehat A_i= \begin{cases} (R_i-\bar R)/s_R,&s_R>0,\\ 0,&s_R=0. \end{cases}

With outcome supervision, the same A^i\widehat A_i is assigned to every scored token in response ii. This is the construction in DeepSeekMath, Section 4.1.2. It is a group-relative weight, not automatically an estimate of the prefix-specific Qπk(h,a)−Vπk(h)Q^{\pi_k}(h,a)-V^{\pi_k}(h).

For a nonconstant group,

∑iA^i=0,1G∑iA^i2=1.\sum_i\widehat A_i=0,\qquad \frac1G\sum_i\widehat A_i^2=1.

Using divisor G−1G-1 instead multiplies these advantages by (G−1)/G\sqrt{(G-1)/G}. Adding a stabilizer δ>0\delta>0 to the denominator is another specified variant: (Ri−Rˉ)/(sR+δ)(R_i-\bar R)/(s_R+\delta). It does not satisfy the unit-second-moment identity exactly. We use the explicit zero-variance branch above, so no undefined 0/00/0 appears.

A binary-reward group

Suppose Ri∈{0,1}R_i\in\{0,1\} and C=∑iRiC=\sum_iR_i counts successes. Conditional on X=xX=x, let

pk(x)=PY∼πk(⋅∣x){r(x,Y)=1},C∣X=x∼Binomial⁡(G,pk(x)).p_k(x)=\mathbb P_{Y\sim\pi_k(\cdot\mid x)}\{r(x,Y)=1\}, \qquad C\mid X=x\sim\operatorname{Binomial}(G,p_k(x)).

For 0<C<G0<C<G, put p^=C/G\widehat p=C/G. Since Ri2=RiR_i^2=R_i,

sR2=1G∑iRi2−p^2=p^(1−p^),A^i={(1−p^)/p^,Ri=1,−p^/(1−p^),Ri=0.s_R^2=\frac1G\sum_iR_i^2-\widehat p^2 =\widehat p(1-\widehat p), \qquad \widehat A_i= \begin{cases} \sqrt{(1-\widehat p)/\widehat p},&R_i=1,\\ -\sqrt{\widehat p/(1-\widehat p)},&R_i=0. \end{cases}

For example, (R1,R2,R3,R4)=(1,0,1,1)(R_1,R_2,R_3,R_4)=(1,0,1,1) gives

Rˉ=34,sR=34,(A^1,A^2,A^3,A^4)=(13,−3,13,13).\bar R=\frac34,\qquad s_R=\frac{\sqrt3}{4}, \qquad (\widehat A_1,\widehat A_2,\widehat A_3,\widehat A_4) =\left(\frac1{\sqrt3},-\sqrt3,\frac1{\sqrt3},\frac1{\sqrt3}\right).

The sole failure receives a larger negative weight than each success's positive weight. For C=0C=0 or C=GC=G, every advantage is zero: there is no within-group reward contrast. This makes the reward part vanish, not necessarily a separately applied KL gradient.

The probability of a mixed-reward group is

ak(x):=P(0<C<G∣X=x)=1−pk(x)G−{1−pk(x)}G.a_k(x) := \mathbb P(0<C<G\mid X=x) =1-p_k(x)^G-\{1-p_k(x)\}^G.

Thus the supply of nonzero reward updates depends on both GG and the current success probability. It can be small for very hard or nearly solved prompts.

Why random normalization changes the gradient

The denominator sRs_R depends on all rewards, including RiR_i. For this reason, the independence argument in Section 2 does not remove it from an expectation.

An exact counterexample uses one prompt and three responses with πθ(j)=eθj/∑ℓ=13eθℓ\pi_\theta(j)=e^{\theta_j}/\sum_{\ell=1}^3e^{\theta_\ell}, probabilities πk=(1/3,1/3,1/3)\pi_k=(1/3,1/3,1/3), and rewards (0,1,10)(0,1,10). The ordinary reward gradient is

gk=diag⁡(πk)r−πk(πk⊤r)=(−119,−89,199).g_k =\operatorname{diag}(\pi_k)r-\pi_k(\pi_k^\top r) =\left(-\frac{11}{9},-\frac89,\frac{19}{9}\right).

Take G=2G=2 and let eje_j denote the jjth coordinate vector. Distinct rewards give normalized advantages (−1,+1)(-1,+1) in reward order, regardless of the reward gap; equal responses give zero. Since Si=eYi−πkS_i=e_{Y_i}-\pi_k, each unordered distinct pair contributes (ehigher−elower)/2(e_{\rm higher}-e_{\rm lower})/2, and has probability 2/92/9. Hence

Eπk⊗2[12∑i=12A^iSi]=19{(e2−e1)+(e3−e1)+(e3−e2)}=(−29,0,29).\begin{aligned} \mathbb E_{\pi_k^{\otimes2}} \left[\frac12\sum_{i=1}^2\widehat A_i S_i\right] &=\frac19\{(e_2-e_1)+(e_3-e_1)+(e_3-e_2)\}\\ &=\left(-\frac29,0,\frac29\right). \end{aligned}

The two vectors are not scalar multiples. Standardization can change the direction, not only the scale, of the mean-reward gradient. This calculation concerns the unclipped, full-sequence score estimator at θk\theta_k, without length averaging; it is not a convergence theorem for GRPO.

4. From group weights to clipped token updates

On a collected response define the current-to-old token ratio

ui,t(θ)=πθ(Yi,t∣Hi,t)πk(Yi,t∣Hi,t),cε(u,A)=min⁡{uA,clip⁡(u,1−ε,1+ε)A},0<ε<1.u_{i,t}(\theta) =\frac{\pi_\theta(Y_{i,t}\mid H_{i,t})} {\pi_k(Y_{i,t}\mid H_{i,t})}, \qquad c_\varepsilon(u,A) =\min\{uA,\operatorname{clip}(u,1-\varepsilon,1+\varepsilon)A\}, \quad 0<\varepsilon<1.

For a batch Bk={(Xb,Yb,1:G,Rb,1:G)}b=1B\mathcal B_k=\{(X_b,Y_{b,1:G},R_{b,1:G})\}_{b=1}^B, write the reward surrogate as

L^k,reward(θ)=1BG∑b=1B∑i=1G1Lb,i∑t=1Lb,icε(ub,i,t(θ),A^b,i).\widehat L_{k,\rm reward}(\theta) =\frac1{BG}\sum_{b=1}^B\sum_{i=1}^G \frac1{L_{b,i}}\sum_{t=1}^{L_{b,i}} c_\varepsilon(u_{b,i,t}(\theta),\widehat A_{b,i}).

The population surrogate averages the corresponding single-group expression under Pk(G)P_k^{(G)}. Because this is the old-policy sampling law, it is held fixed when we differentiate with respect to θ\theta. Only the current-policy probabilities inside the surrogate change.

The clipping mechanism can be read directly:

cε(u,A)={Amin⁡(u,1+ε),A≥0,Amax⁡(u,1−ε),A<0.c_\varepsilon(u,A)= \begin{cases} A\min(u,1+\varepsilon),&A\ge0,\\ A\max(u,1-\varepsilon),&A<0. \end{cases}

For positive advantage, the sample's incentive to increase its ratio flattens above 1+ε1+\varepsilon. For negative advantage, its incentive to decrease the ratio flattens below 1−ε1-\varepsilon. The sampled objective does not impose hard bounds on all token probabilities or guarantee improvement in expected reward.

Original PPO Figure 1. With positive advantage the objective rises with the probability ratio and then plateaus above one plus epsilon. With negative advantage it is flat below one minus epsilon and decreases thereafter. Red markers indicate the initial ratio one.
Figure 2. The PPO paper's clipped-surrogate figure. Original figure from Schulman et al. (2017), Proximal Policy Optimization Algorithms, Figure 1. The horizontal axis is the new-to-old action-probability ratio r. These are the authors' original objective plots, not new experimental evidence. Full resolution ↗Figure excerpt for discussion; copyright remains with the authors/rightsholder.

At θ=θk\theta=\theta_k, every ratio is one and lies in the unclipped interval. Differentiating the empirical reward surrogate gives

∇θL^k,reward(θ)∣θk=1BG∑b,iA^b,iLb,i Sθk(Xb,Yb,i).\left.\nabla_\theta\widehat L_{k,\rm reward}(\theta)\right|_{\theta_k} =\frac1{BG}\sum_{b,i} \frac{\widehat A_{b,i}}{L_{b,i}}\, S_{\theta_k}(X_b,Y_{b,i}).

Two changes distinguish this update from the baseline proposition: dividing by a random group standard deviation and weighting by response length. When lengths vary, multiplying the sequence score by 1/L(Y)1/L(Y) can prevent even a response-independent baseline from canceling. The reason is that Eπ[Sθ(X,Y)/L(Y)∣X]\mathbb E_\pi[S_\theta(X,Y)/L(Y)\mid X] need not be zero.

The old policy is also not the reference:

ui,t(θ)⏟current / rollout≠πθ(Yi,t∣Hi,t)πref(Yi,t∣Hi,t)⏟current / reference,πθ(Yi∣X)πk(Yi∣X)=∏tui,t(θ).\underbrace{u_{i,t}(\theta)}_{\text{current / rollout}} \ne \underbrace{\frac{\pi_\theta(Y_{i,t}\mid H_{i,t})} {\pi_{\rm ref}(Y_{i,t}\mid H_{i,t})}}_{\text{current / reference}}, \qquad \frac{\pi_\theta(Y_i\mid X)}{\pi_k(Y_i\mid X)} =\prod_tu_{i,t}(\theta).

A single token ratio is not a full-response importance weight. Old-policy prefixes remain old-policy prefixes. Moreover, if generation uses a different temperature or truncation rule, its actual sampling law must be recorded; a nominal πk\pi_k denominator does not by itself correct that mismatch. These are the same sampling distinctions used in the PPO–DPO article.

5. The KL term: value identity versus sampled gradient

For a fixed prefix hh, abbreviate p(a)=πθ(a∣h)p(a)=\pi_\theta(a\mid h) and q(a)=πref(a∣h)q(a)=\pi_{\rm ref}(a\mid h). Both are positive normalized token distributions. DeepSeekMath's equation (4) uses the nonnegative sampled quantity

kθ(h,a)=q(a)p(a)−log⁡q(a)p(a)−1.k_\theta(h,a) =\frac{q(a)}{p(a)} -\log\frac{q(a)}{p(a)}-1.

To establish nonnegativity, set z=q(a)/p(a)>0z=q(a)/p(a)>0 and apply log⁡z≤z−1\log z\le z-1. Equality holds at z=1z=1. Next, when the token is sampled from pp, its expectation is

EA∼p[kθ(h,A)]=∑ap(a){q(a)p(a)+log⁡p(a)q(a)−1}=∑aq(a)−∑ap(a)⏟0+∑ap(a)log⁡p(a)q(a)=DKL(p∥q).\begin{aligned} \mathbb E_{A\sim p}[k_\theta(h,A)] &=\sum_a p(a)\left\{\frac{q(a)}{p(a)} +\log\frac{p(a)}{q(a)}-1\right\}\\ &=\underbrace{\sum_aq(a)-\sum_ap(a)}_{0} +\sum_ap(a)\log\frac{p(a)}{q(a)} =D_{\rm KL}(p\Vert q). \end{aligned}

This is a conditional token-KL value identity. If A∼pk=πk(⋅∣h)A\sim p_k=\pi_k(\cdot\mid h) instead, generally Epk[kθ]≠DKL(p∥q)\mathbb E_{p_k}[k_\theta]\ne D_{\rm KL}(p\Vert q) after θ\theta moves. For a fixed prefix and full support, the corrected identity is

EA∼pk[p(A)pk(A) kθ(h,A)]=DKL(p∥q).\mathbb E_{A\sim p_k} \left[\frac{p(A)}{p_k(A)}\,k_\theta(h,A)\right] =D_{\rm KL}(p\Vert q).

Even an on-policy value identity is not automatically an unbiased gradient identity when differentiation treats samples as fixed. Let sθ(a)=∇θlog⁡p(a)s_\theta(a)=\nabla_\theta\log p(a). Direct differentiation gives

∇θkθ(h,a)=(1−q(a)p(a))sθ(a),EA∼p[∇θkθ(h,A)]=−EA∼q[sθ(A)].\nabla_\theta k_\theta(h,a) =\left(1-\frac{q(a)}{p(a)}\right)s_\theta(a), \qquad \mathbb E_{A\sim p}[\nabla_\theta k_\theta(h,A)] =-\mathbb E_{A\sim q}[s_\theta(A)].

To differentiate its on-policy expectation, the sampling distribution contributes a score term:

∇θDKL(p∥q)=EA∼p[∇θkθ(h,A)+kθ(h,A)sθ(A)]=EA∼p[log⁡p(A)q(A)sθ(A)].\begin{aligned} \nabla_\theta D_{\rm KL}(p\Vert q) &=\mathbb E_{A\sim p} \left[\nabla_\theta k_\theta(h,A) +k_\theta(h,A)s_\theta(A)\right]\\ &=\mathbb E_{A\sim p} \left[\log\frac{p(A)}{q(A)}s_\theta(A)\right]. \end{aligned}

The last equality uses 1−q/p+kθ=log⁡(p/q)1-q/p+k_\theta=\log(p/q). Thus averaging the derivative of the sampled penalty need not equal differentiating its on-policy expectation. We recover the conditional forward-KL gradient by differentiating the corrected fixed-pkp_k expression including its probability ratio. That correction still does not replace old-policy prefixes by current-policy prefixes.

For the concrete GRPO surrogate discussed here, define

K^k(θ)=1BG∑b,i1Lb,i∑tkθ(Hb,i,t,Yb,i,t),L^k,GRPO(θ)=L^k,reward(θ)−βK^k(θ),β≥0.\begin{aligned} \widehat K_k(\theta) &=\frac1{BG}\sum_{b,i}\frac1{L_{b,i}} \sum_t k_\theta(H_{b,i,t},Y_{b,i,t}),\\ \widehat L_{k,\rm GRPO}(\theta) &=\widehat L_{k,\rm reward}(\theta)-\beta\widehat K_k(\theta), \quad\beta\ge0. \end{aligned}

This sampled regularization surrogate evaluates the penalty on fixed old-policy responses. Its expectation can therefore differ from forward KL under the current policy's trajectories. Averaging within each response also differs from full sequence KL. The latter sums token contributions and averages prefixes according to how often the current policy reaches them.

For the broader KL-regularized reward target and its exact optimizer, see the earlier objective-gap derivation. The centered, normalized, clipped surrogate above is a practical update construction, not an exact derivation of that optimizer.

6. A complete outcome-supervised update

Algorithm 1 Outcome-supervised GRPO with a fixed scorer and reference

Input: Initial policy πθ0\pi_{\theta_0}; reference πref\pi_{\rm ref}; prompt law ρ\rho; fixed scorer rr; group size G≥2G\ge2; batch size BB; clipping parameter ε\varepsilon; penalty coefficient β\beta; rollout rounds KK; inner updates MM; learning rates ηk,m\eta_{k,m}.

Output: Updated policy πθK\pi_{\theta_K}.

  1. Freeze the scorer and reference. Specify the actual generation distribution, stopping rule, response-token masks, standard-deviation convention, and zero-variance handling.
  2. For k=0,…,K−1k=0,\ldots,K-1 do
  3. Snapshot the rollout policy πk←πθk\pi_k\leftarrow\pi_{\theta_k}. Independently sample Xb∼ρX_b\sim\rho for b=1,…,Bb=1,\ldots,B.
  4. For each XbX_b, sample Yb,1,…,Yb,G∣Xb∼iidπk(⋅∣Xb)Y_{b,1},\ldots,Y_{b,G}\mid X_b\overset{\rm iid}{\sim}\pi_k(\cdot\mid X_b) and cache old-policy and reference token log-probabilities.
  5. Score each completed response with Rb,i=r(Xb,Yb,i)R_{b,i}=r(X_b,Y_{b,i}). Compute Rˉb,sR,b\bar R_b,s_{R,b} and A^b,i\widehat A_{b,i}, using zero advantages when sR,b=0s_{R,b}=0.
  6. Set θ(0)←θk\theta^{(0)}\leftarrow\theta_k. Keep all sampled tokens, rewards, cached probabilities, advantages and masks fixed.
  7. For m=0,…,M−1m=0,\ldots,M-1 do
  8. Teacher-force the recorded responses under πθ(m)\pi_{\theta^{(m)}}. Sum or average only where specified in L^k,GRPO\widehat L_{k,\rm GRPO}; exclude prompt and deterministic padding tokens.
  9. Compute token ratios and the clipped reward terms, then subtract the sampled reference penalty. Update θ(m+1)=θ(m)+ηk,m∇θL^k,GRPO(θ(m))\theta^{(m+1)}=\theta^{(m)}+\eta_{k,m}\nabla_\theta\widehat L_{k,\rm GRPO}(\theta^{(m)}).
  10. End for. Set θk+1←θ(M)\theta_{k+1}\leftarrow\theta^{(M)} and collect fresh groups for the next round.
  11. End for.
  12. Return πθK\pi_{\theta_K}.

The pseudocode keeps the scorer and reference fixed to isolate the actor update; DeepSeekMath additionally considers outer iterations that refresh them. We display the full-batch gradient of the specified surrogate. Minibatch versions must retain the same group statistics and loss-reduction weights.

Zero reward variance does not require discarding a group in this algorithm: its reward term is zero, while its KL term can remain active. Filtering such groups is an additional design choice.

7. When rewards are assigned along a response

Outcome supervision attaches one score to the completed response. Process supervision instead supplies scores at selected reasoning-step endpoints. To state the construction in DeepSeekMath, Section 4.1.3, let ei,je_{i,j} be the final token of step jj in response ii, for j=1,…,Jij=1,\ldots,J_i, and let ri,jr_{i,j} be its process score.

Assume at least one step score is available in the group. Pool its Nx=∑iJi>0N_x=\sum_iJ_i>0 step scores and define

rˉproc=1Nx∑i,jri,j,sproc2=1Nx∑i,j(ri,j−rˉproc)2,r~i,j=ri,j−rˉprocsproc,\bar r_{\rm proc}=\frac1{N_x}\sum_{i,j}r_{i,j},\qquad s_{\rm proc}^2=\frac1{N_x}\sum_{i,j}(r_{i,j}-\bar r_{\rm proc})^2, \qquad \widetilde r_{i,j}=\frac{r_{i,j}-\bar r_{\rm proc}}{s_{\rm proc}},

using zero normalized scores if sproc=0s_{\rm proc}=0. The token weight is then

A^i,tproc=∑j: ei,j≥tr~i,j.\widehat A_{i,t}^{\rm proc} =\sum_{j:\,e_{i,j}\ge t}\widetilde r_{i,j}.

Thus a token receives the normalized scores of reasoning steps ending at or after it. Unlike the outcome version, these weights vary within a response. This is still a specified group-normalized weighting rule; a learned process scorer, its normalization, and the chosen step segmentation do not automatically produce the true reward-to-go advantage.

8. DAPO: changing clipping, sampling, and token weights

Yu et al.'s DAPO changes how group-relative updates clip ratios, select groups, and average token losses. We examine each change in terms of the objective or sampling distribution it modifies.

Asymmetric clipping

Replace the symmetric interval by [1−εlow,1+εhigh][1-\varepsilon_{\rm low},1+\varepsilon_{\rm high}], with 0<εlow<10<\varepsilon_{\rm low}<1 and εhigh>0\varepsilon_{\rm high}>0:

casym(u,A)=min⁡{uA,clip⁡(u,1−εlow,1+εhigh)A}.c_{\rm asym}(u,A) =\min\{uA,\operatorname{clip}(u,1-\varepsilon_{\rm low},1+\varepsilon_{\rm high})A\}.

Choosing a larger upper threshold postpones the positive-advantage plateau. At a particular old token probability pk(a)p_k(a), that plateau begins at pθ(a)=(1+εhigh)pk(a)p_\theta(a)=(1+\varepsilon_{\rm high})p_k(a), if reachable. It is a surrogate plateau, not a maximum admissible probability. Parameter sharing and other sample gradients can still move that probability further.

Dynamic sampling and its conditional distribution

For binary correctness rewards, keep only groups with 0<C<G0<C<G and continue sampling until enough accepted groups have accumulated. With the acceptance probability ak(x)a_k(x) derived in Section 3, the accepted law is

Pk,acc(G)( ⋅ )=Pk(G)( ⋅ ∣0<C<G),ρk,acc(x)=ρ(x)ak(x)EX∼ρ[ak(X)],P_{k,\rm acc}^{(G)}(\,\cdot\,) =P_k^{(G)}(\,\cdot\,\mid0<C<G), \qquad \rho_{k,\rm acc}(x) =\frac{\rho(x)a_k(x)} {\mathbb E_{X\sim\rho}[a_k(X)]},

provided the denominator is positive. Within a retained group, responses are no longer independent draws from the original response distribution conditional on the prompt. Retaining only mixed outcomes creates dependence between them. Prompts with ak(x)=0a_k(x)=0 cannot enter. A practical rejection loop also needs a sampling budget and a rule for stopping if too few groups are accepted.

Filtering therefore maintains nonzero reward contrasts and changes the group/prompt distribution. It is not an unbiased sample from the original ρ\rho without further correction. Even without explicit filtering, normalized GRPO already gives zero reward contribution to constant groups.

Original Yu et al. Figure 6 plots AIME average accuracy over 32 generations against training steps. The purple run with dynamic sampling reaches a dashed accuracy level around step 2400, while the cyan run without dynamic sampling reaches it around step 6000. Both curves fluctuate.
Figure 3. Dynamic sampling in the DAPO paper's baseline setting. Original figure from Yu et al. (2025), DAPO: An Open-Source LLM Reinforcement Learning System at Scale, Figure 6. These are author-reported baseline runs, not a reproduction or a universal comparison. The axis counts update steps, not rejected generations, generated tokens or wall-clock time. Full resolution ↗Figure excerpt for discussion; copyright remains with the authors/rightsholder.

The source comparison concerns training progress in its baseline setting. Its horizontal axis is update steps, not total generated tokens or wall-clock cost; rejected groups still require generation.

Token-level rather than response-level averaging

For a fixed retained batch, let N=∑b,iLb,iN=\sum_{b,i}L_{b,i} and abbreviate fb,i,t(θ)=casym(ub,i,t(θ),A^b,i)f_{b,i,t}(\theta)=c_{\rm asym}(u_{b,i,t}(\theta),\widehat A_{b,i}). Compare

L^response=1BG∑b,i1Lb,i∑tfb,i,t,L^token=1N∑b,i,tfb,i,t.\begin{aligned} \widehat L_{\rm response} &=\frac1{BG}\sum_{b,i}\frac1{L_{b,i}}\sum_tf_{b,i,t},\\ \widehat L_{\rm token} &=\frac1N\sum_{b,i,t}f_{b,i,t}. \end{aligned}

In the first expression each response has total averaging weight 1/(BG)1/(BG). In the second it has Lb,i/NL_{b,i}/N. Each token has equal averaging weight in the second, although its actual gradient still depends on its advantage, score, and clipping state. These reductions coincide for equal-length responses but generally differ otherwise.

DAPO's displayed objective uses token-level reduction, asymmetric clipping, and mixed-outcome filtering; its Section 2.3 also removes the reference KL term. We therefore do not present DAPO as merely GRPO with a larger upper clip.

Length-aware reward shaping

With maximum length Lmax⁡L_{\max} and buffer width 0<Lcache≤Lmax⁡0<L_{\rm cache}\le L_{\max}, DAPO's soft length penalty is

rlength(L)={0,L≤Lmax⁡−Lcache,Lmax⁡−Lcache−LLcache,Lmax⁡−Lcache<L≤Lmax⁡,−1,L>Lmax⁡.r_{\rm length}(L)= \begin{cases} 0,&L\le L_{\max}-L_{\rm cache},\\ \dfrac{L_{\max}-L_{\rm cache}-L}{L_{\rm cache}}, &L_{\max}-L_{\rm cache}<L\le L_{\max},\\ -1,&L>L_{\max}. \end{cases}

Adding this to a correctness reward changes what is rewarded; it is not just a numerical stabilization. Likewise, masking truncated responses changes which observed losses contribute. The binary acceptance calculation above applies to its stated binary reward model; it should not be reused unchanged for arbitrary composite rewards or masking schemes.

9. What follows from these calculations?

ConstructionWhat the calculation establishes
Leave-one-out mean, no scaling, full sequence scoreAn unbiased reward-gradient estimator at the rollout policy under conditional iid sampling
In-group mean without scalingA factor (G−1)/G(G-1)/G in that same expectation
Random group standardizationRelative reward weights; not generally the same reward-gradient direction
Clipped token ratiosA local old-policy surrogate, not an exact full-response change of measure
Sampled nonnegative KL quantityA conditional KL value identity under the specified current-token law, not automatic gradient unbiasedness
Filtering and token averagingExplicit changes to accepted sampling and response weights

GRPO replaces a learned value critic with group comparisons; it does not remove rollout generation, reward design, or the need to control update size and sampling mismatch. The baseline identities explain one component exactly. They do not give a global convergence rate or guarantee that clipped neural optimization improves true task performance.

Compared with standard offline DPO, the core difference is data use: GRPO repeatedly generates groups and scores them, whereas fixed-dataset DPO optimizes recorded preference pairs. Both can use comparative information, but their empirical objectives and sampling laws differ.

The next note will examine sequence-level ratios and soft policy-update rules. Those methods change the update itself, so their likelihood ratios and guarantees must be derived separately.

References

  1. Shao, Z., et al. (2024). DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models. Version 1, Sections 4.1.1–4.1.4, equations (3)–(4), Figure 4, and Algorithm 1. Main source for GRPO; the baseline identities and counterexample here are derived explicitly rather than attributed as the paper's theorem.
  2. DeepSeek-AI (2025). DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning. Version 1, Sections 2.2.1–2.2.2. Source for the R1-Zero reward-design example; not used to identify token-level and full-sequence likelihood ratios.
  3. Schulman, J., et al. (2017). Proximal Policy Optimization Algorithms. Clipped surrogate and original Figure 1.
  4. Yu, Q., et al. (2025). DAPO: An Open-Source LLM Reinforcement Learning System at Scale. Version 1, Sections 2.3 and 3.1–3.4, equations (8)–(13), Figure 6. The accepted-distribution calculation is a derivation for the stated rejection-sampling model.