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 , let . For a fixed reward and a prompt-only baseline, the earlier score calculation gives
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 be a prompt, including its task context, in a finite prompt set. Its distribution 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 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:
Assume differentiable positive probabilities on the same valid response support. For , the group sampling law at iteration is
Thus responses are independent conditional on the prompt, not necessarily marginally. A batch consists of independent groups from . Conditional on this batch, all sampled tokens, rewards, old-policy likelihoods, and computed advantages remain fixed during its optimizer updates.
Write for the number of scored response tokens, for a prefix, and
These response log-probabilities are sums, not length averages. An average over token losses, introduced later, is a separate weighting choice.
Let be a bounded deterministic scorer, fixed throughout one rollout/update cycle, and set . A learned reward model can supply ; 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.
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 , define the expected reward
Finite support permits differentiation under the sum. The likelihood-ratio identity and score identity give
As in the policy-gradient baseline derivation, subtracting a fixed prompt-only 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 and . Then
To prove this, write . For , conditional independence and the zero-score identity imply
Consequently,
Averaging over proves the claim. Averaging over , with fixed, gives the same factor for .
Next define the leave-one-out baseline
The other responses are conditionally independent of , so
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- standard deviation
With outcome supervision, the same is assigned to every scored token in response . This is the construction in DeepSeekMath, Section 4.1.2. It is a group-relative weight, not automatically an estimate of the prefix-specific .
For a nonconstant group,
Using divisor instead multiplies these advantages by . Adding a stabilizer to the denominator is another specified variant: . It does not satisfy the unit-second-moment identity exactly. We use the explicit zero-variance branch above, so no undefined appears.
A binary-reward group
Suppose and counts successes. Conditional on , let
For , put . Since ,
For example, gives
The sole failure receives a larger negative weight than each success's positive weight. For or , 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
Thus the supply of nonzero reward updates depends on both and the current success probability. It can be small for very hard or nearly solved prompts.
Why random normalization changes the gradient
The denominator depends on all rewards, including . 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 , probabilities , and rewards . The ordinary reward gradient is
Take and let denote the th coordinate vector. Distinct rewards give normalized advantages in reward order, regardless of the reward gap; equal responses give zero. Since , each unordered distinct pair contributes , and has probability . Hence
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 , 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
For a batch , write the reward surrogate as
The population surrogate averages the corresponding single-group expression under . Because this is the old-policy sampling law, it is held fixed when we differentiate with respect to . Only the current-policy probabilities inside the surrogate change.
The clipping mechanism can be read directly:
For positive advantage, the sample's incentive to increase its ratio flattens above . For negative advantage, its incentive to decrease the ratio flattens below . The sampled objective does not impose hard bounds on all token probabilities or guarantee improvement in expected reward.
At , every ratio is one and lies in the unclipped interval. Differentiating the empirical reward surrogate gives
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 can prevent even a response-independent baseline from canceling. The reason is that need not be zero.
The old policy is also not the reference:
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 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 , abbreviate and . Both are positive normalized token distributions. DeepSeekMath's equation (4) uses the nonnegative sampled quantity
To establish nonnegativity, set and apply . Equality holds at . Next, when the token is sampled from , its expectation is
This is a conditional token-KL value identity. If instead, generally after moves. For a fixed prefix and full support, the corrected identity is
Even an on-policy value identity is not automatically an unbiased gradient identity when differentiation treats samples as fixed. Let . Direct differentiation gives
To differentiate its on-policy expectation, the sampling distribution contributes a score term:
The last equality uses . 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- 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
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
Input: Initial policy ; reference ; prompt law ; fixed scorer ; group size ; batch size ; clipping parameter ; penalty coefficient ; rollout rounds ; inner updates ; learning rates .
Output: Updated policy .
- Freeze the scorer and reference. Specify the actual generation distribution, stopping rule, response-token masks, standard-deviation convention, and zero-variance handling.
- For do
- Snapshot the rollout policy . Independently sample for .
- For each , sample and cache old-policy and reference token log-probabilities.
- Score each completed response with . Compute and , using zero advantages when .
- Set . Keep all sampled tokens, rewards, cached probabilities, advantages and masks fixed.
- For do
- Teacher-force the recorded responses under . Sum or average only where specified in ; exclude prompt and deterministic padding tokens.
- Compute token ratios and the clipped reward terms, then subtract the sampled reference penalty. Update .
- End for. Set and collect fresh groups for the next round.
- End for.
- Return .
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 be the final token of step in response , for , and let be its process score.
Assume at least one step score is available in the group. Pool its step scores and define
using zero normalized scores if . The token weight is then
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 , with and :
Choosing a larger upper threshold postpones the positive-advantage plateau. At a particular old token probability , that plateau begins at , 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 and continue sampling until enough accepted groups have accumulated. With the acceptance probability derived in Section 3, the accepted law is
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 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 without further correction. Even without explicit filtering, normalized GRPO already gives zero reward contribution to constant groups.
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 and abbreviate . Compare
In the first expression each response has total averaging weight . In the second it has . 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 and buffer width , DAPO's soft length penalty is
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?
| Construction | What the calculation establishes |
|---|---|
| Leave-one-out mean, no scaling, full sequence score | An unbiased reward-gradient estimator at the rollout policy under conditional iid sampling |
| In-group mean without scaling | A factor in that same expectation |
| Random group standardization | Relative reward weights; not generally the same reward-gradient direction |
| Clipped token ratios | A local old-policy surrogate, not an exact full-response change of measure |
| Sampled nonnegative KL quantity | A conditional KL value identity under the specified current-token law, not automatic gradient unbiasedness |
| Filtering and token averaging | Explicit 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
- 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.
- 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.
- Schulman, J., et al. (2017). Proximal Policy Optimization Algorithms. Clipped surrogate and original Figure 1.
- 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.



