GRPO loss variants explained: advantages, length bias, DAPO, Dr. GRPO and soft clipping
GRPO made reinforcement learning for reasoning models cheap by dropping the value network. Its loss hides two biases, one from response length and one from reward scaling. This article works through both with numbers and shows how the main variants fix them.
- Reading time
- 15 min
- Sections
- 8
- Code examples
- 2
- Tables
- 3
- Sources
- 9
- Published
- 23 Nov 2026
- What changed
- TRL 1.18 ships with a menu of GRPO losses
- Why it matters
- If you train with GRPO today, the loss type is a real hyperparameter, not a detail.
- What to do
- Set the loss type explicitly
Group Relative Policy Optimization (GRPO) is the reinforcement learning method behind many of today's reasoning models. It was introduced in the DeepSeekMath paper in 2024 as a lighter alternative to PPO. Instead of training a separate value network to judge each answer, GRPO samples several answers to the same question and scores each one against the group's average.
That simple idea hides details that matter a great deal at scale. How you normalise rewards and how you average the loss over tokens decide which answers get pushed up or down, and by how much. Several follow-up papers showed that the original choices introduce biases, especially toward long wrong answers. Open-source trainers now ship these fixes as configuration options, and the defaults have changed.
This article explains the GRPO objective step by step, shows the two biases with worked numbers, and compares the main variants: DAPO, Dr. GRPO and SAPO.
What happened
TRL 1.18 ships with a menu of GRPO losses (13 to 19 November 2026)
Hugging Face's TRL library published version 1.18.0 on PyPI on 13 November 2026, followed by patch releases 1.18.1 on 17 November and 1.18.2 on 19 November. In the current source, the GRPOConfig class lists eight loss formulations: grpo, dr_grpo, dapo, bnpo, cispo, sapo, luspo and vespo. The default is dapo, and the help text describes the original grpo aggregation as "not recommended due to length bias". The default KL coefficient beta is 0.0, so no reference model is loaded unless you ask for one, and reward scaling defaults to per-group standard deviation, with options for batch-level scaling or none.
The TRL documentation also describes agent training inside the GRPO trainer, where the model calls Python tools or stateful environments during generation and learns from the outcome, and it documents importance sampling corrections for the mismatch between a vLLM inference engine and the training engine. Those features make the choice of loss more important, because agent rollouts are long and vary widely in length.
How GRPO turns rewards into a training signal
GRPO works in four steps, as the TRL documentation lays them out.
1. Generate a group. For each prompt q, sample G completions o₁ … o_G from the current policy. TRL's default is G = 8.
2. Score and normalise. Compute a reward rᵢ for each completion, for example 1 if a maths answer is correct and 0 if not. The advantage of completion i is
Âᵢ = (rᵢ − mean(r)) / std(r)
and every token in completion i gets the same advantage. This is the "group relative" part: an answer is good only relative to its siblings. No value network is needed, which saves the memory and compute of a second large model.
3. Optionally penalise drift. A KL term, estimated per token as π_ref/π_θ − log(π_ref/π_θ) − 1, can keep the policy near a reference model. TRL sets its weight β to 0 by default, citing studies that found the term not essential.
4. Take a policy-gradient step. Each token contributes a term based on the probability ratio between the new and old policy, multiplied by the advantage. With several updates per batch, PPO's clipped surrogate bounds the ratio to [1 − ε, 1 + ε], with ε = 0.2 by default in TRL.
An analogy helps. A teacher grading on a curve does not need an absolute standard for every question. She compares each student's answer to the class average on that question. GRPO grades each answer against the other answers to the same prompt.
Bias one: dividing by the standard deviation
Dividing by std(r) gives each group unit variance. That sounds harmless, but with binary rewards the standard deviation depends on how hard the question is. Take G = 4 and rewards of 0 or 1. TRL computes the standard deviation with Bessel's correction (dividing by G − 1) and adds 1e-4 to avoid division by zero.
| Rewards in group | Mean | Std | Advantages with std scaling | Advantages without scaling |
|---|---|---|---|---|
| 1, 0, 0, 0 (hard) | 0.25 | 0.50 | +1.50, −0.50, −0.50, −0.50 | +0.75, −0.25, −0.25, −0.25 |
| 1, 1, 0, 0 (medium) | 0.50 | 0.58 | ±0.87 | ±0.50 |
| 1, 1, 1, 0 (easy) | 0.75 | 0.50 | +0.50, +0.50, +0.50, −1.50 | +0.25, +0.25, +0.25, −0.75 |
| 0, 0, 0, 0 (unsolved) | 0.00 | 0.00 | 0, 0, 0, 0 | 0, 0, 0, 0 |
Std scaling doubles the advantages of the hard and easy groups (0.75 becomes 1.50) but raises those of the medium group by a smaller factor of about 1.73 (0.50 becomes 0.87). Questions that are almost always solved or almost never solved therefore get relatively more weight. The paper "Understanding R1-Zero-Like Training: A Critical Perspective", which introduced Dr. GRPO, calls this a question-level difficulty bias and recommends not scaling. TRL exposes this as scale_rewards=False, and warns that update sizes then depend directly on the raw reward scale. A middle path, from the "Tricks or Traps" study known as Lite PPO, takes the mean per group but the standard deviation over the whole batch (scale_rewards="batch").
The last row shows a separate problem. When every completion gets the same reward, all advantages are zero and the group teaches nothing. For hard tasks early in training this can waste most of a batch. The DAPO paper addresses it with dynamic sampling, which over-samples prompts and filters out groups whose answers are all right or all wrong.
Bias two: averaging over tokens
The second bias comes from how per-token losses are averaged. Let lᵢ,ₜ be the loss term for token t of completion i. The four main choices are:
- Original GRPO: L = −(1/G) Σᵢ (1/|oᵢ|) Σₜ lᵢ,ₜ. Average over tokens within each completion, then over completions.
- DAPO: L = −(1 / Σᵢ|oᵢ|) Σᵢ Σₜ lᵢ,ₜ. One average over all tokens in the batch. TRL normalises by the active tokens in the global accumulated batch.
- BNPO: like DAPO but over the local batch only, so results can vary slightly with per-device batch size.
- Dr. GRPO: L = −(1/(L·G)) Σᵢ Σₜ lᵢ,ₜ, where L is a constant, recommended to be the maximum completion length.
A worked example
Take a group of two completions. Completion A is correct, 20 tokens long, with advantage +1. Completion B is wrong, 200 tokens long, with advantage −1. Look at the weight each token gets in the loss.
| Loss type | Weight per token in A (correct, 20 tokens) | Weight per token in B (wrong, 200 tokens) | Ratio A to B |
|---|---|---|---|
| Original GRPO | 1/(2 × 20) = 0.025 | 1/(2 × 200) = 0.0025 | 10 to 1 |
| DAPO | 1/220 = 0.0045 | 1/220 = 0.0045 | 1 to 1 |
| Dr. GRPO, L = 512 | 1/(512 × 2) = 0.00098 | 1/(512 × 2) = 0.00098 | 1 to 1 |
Under the original loss, each token of the long wrong answer is penalised ten times less than each token of the short right answer is rewarded. Summed over the sequence, both completions get the same total weight of 0.5, so a long wrong answer costs no more in total than a short one, and each of its tokens is barely touched. TRL's help text summarises the effect: the original aggregation tends to prefer shorter completions when the advantage is positive and longer ones when it is negative. Over many steps that can let wrong answers grow longer, a pattern often seen as reasoning traces that ramble.
DAPO's token-level average gives every token the same weight within a batch, so long wrong answers receive a penalty proportional to their length. Dr. GRPO goes one step further. With DAPO, the per-token weight still depends on how many tokens happen to be in the batch: a batch full of long answers gives each token less weight. Dividing by a fixed constant removes that dependence, so the gradient scale is the same from batch to batch.
Here is the calculation in a few lines of Python, so you can try other lengths:
import numpy as np
def token_weights(lengths, kind, L_max=512):
G, n = len(lengths), np.array(lengths)
if kind == "grpo": return 1 / (G * n)
if kind == "dapo": return np.full(G, 1 / n.sum())
if kind == "dr_grpo": return np.full(G, 1 / (L_max * G))
for k in ("grpo", "dapo", "dr_grpo"):
print(k, token_weights([20, 200], k))
# grpo [0.025 0.0025], dapo about [0.0045 0.0045], dr_grpo about [0.00098 0.00098]
Clipping and off-policy corrections
Clip-higher and the soft gate
The PPO clip bounds the probability ratio x = π_θ / π_old to [1 − ε, 1 + ε]. For a token with positive advantage, once x passes 1 + ε, the gradient is zero. With ε = 0.2, a rare but good token with old probability 0.01 can rise only to 0.012 before learning stops for that step, while a common token at 0.5 can rise to 0.6. The DAPO paper argued this limits exploration and proposed a separate, larger upper bound, which it called clip-higher. TRL exposes this as epsilon_high, and its help text notes that DAPO recommends 0.28.
SAPO, proposed by the Qwen team, replaces the hard cut-off with a smooth gate. Instead of the clipped ratio, each token's term uses
f(x) = σ(τ(x − 1)) · 4/τ
where σ is the sigmoid and τ is a temperature. The gradient weight this produces is f′(x) = 4σ(τ(x − 1))(1 − σ(τ(x − 1))). At x = 1, exactly on-policy, σ = 0.5 and the weight is 4 × 0.5 × 0.5 = 1, the same as plain policy gradient. As x moves away from 1 the weight decays smoothly instead of dropping to zero at a cliff. With τ = 1 the weight is 0.79 at x = 2, so the decay is gentle; a larger τ makes it sharper. SAPO uses a slightly higher temperature for negative advantages than positive ones, and TRL's defaults are τ_pos = 1.0 and τ_neg = 1.05, so bad tokens are suppressed a little more strictly.
| Variant | Advantage | Token averaging | Clipping | Main fix |
|---|---|---|---|---|
| GRPO (DeepSeekMath) | group mean and std | per sequence, then per group | symmetric, ε | none; the baseline |
| DAPO | group mean and std | per token over the batch | clip-higher; dynamic sampling | length bias, exploration, empty groups |
| Dr. GRPO | group mean, no std | sum divided by a constant | symmetric | length and difficulty bias |
| SAPO | group-relative | per sequence | smooth sigmoid gate | gradient cliffs at the clip edge |
One more source of bias: the inference engine
Most GRPO pipelines generate rollouts with a fast inference engine such as vLLM and train with a separate engine. TRL's documentation explains that the two can produce slightly different probabilities because of precision and kernel differences. The samples then come from an inference policy, not the training policy, so an on-policy method quietly becomes off-policy. TRL offers importance sampling corrections: truncated importance sampling clips the ratio between the training and inference probabilities into a range, and masked importance sampling drops samples whose ratio falls outside it, at either token or sequence level. The documentation also lists engineering fixes used elsewhere, such as running the model's output head in FP32 in the inference engine.
Continue learning
How this article connects
5 pages link to or from it. Drag to turn, click a dot to open it.
What it means in practice
If you train with GRPO today, the loss type is a real hyperparameter, not a detail. For tasks where response lengths vary widely, such as long reasoning or multi-turn agent rollouts, the original sequence-averaged loss can reward the wrong behaviour. Token-level averaging (DAPO) or constant normalisation (Dr. GRPO) is the safer default, and TRL now defaults to DAPO.
Reward scaling deserves the same attention. With binary rewards, per-group std scaling shifts weight toward questions the model almost always or almost never solves. That can be useful, since those are the questions with the rarest signal, but it is a choice you should make on purpose. Track the fraction of groups with zero variance; if it is high, your data is too hard or too easy and much of your compute is wasted.
The GRPO simulation lets you see group advantages change as rewards change, and the PPO page explains the clipped objective that GRPO inherits. For a recent application of these ideas, see RL on expert-built tasks with LoRA adapters.
What to do now
- Set the loss type explicitly. Write
loss_typein your config rather than relying on a default that may change between releases, and record it with each run. - Prefer token-level or constant normalisation. Use DAPO or Dr. GRPO when response lengths vary, and keep the original loss only to reproduce older results.
- Decide on reward scaling deliberately. Compare per-group std scaling, batch scaling and no scaling on a small run, and watch which questions gain or lose weight.
- Monitor completion length by reward. Plot the mean length of correct and incorrect completions over training; a rising length for wrong answers is the classic sign of length bias.
- Count empty groups. Log the share of groups where all rewards are equal, and filter or resample those prompts so that batches carry signal.
- Try clip-higher for exploration. If entropy collapses early, raise
epsilon_highaboveepsilon, starting from the 0.28 value the DAPO paper recommends. - Correct for engine mismatch. When generating with vLLM, enable importance sampling correction and compare training and inference log-probabilities on a sample of tokens.
- Keep G large enough. With G = 4 and binary rewards, a group has only five possible outcomes; larger groups give finer-grained advantages at the cost of more generation.
Risks and open questions
Variants interact. Loss normalisation, reward scaling, clipping and KL weight all change gradient size. Changing two at once makes it hard to tell which one helped.
Paper results do not always transfer. Most comparisons use maths benchmarks with binary rewards. Agent tasks with partial credit, tool errors and long multi-turn rollouts may behave differently.
Constant normalisation shifts the learning rate. Dividing by L × G instead of the token count changes the gradient scale, so a learning rate tuned for one loss type may be wrong for another.
Reward hacking is untouched by these fixes. None of these variants protects against a reward function that can be gamed. Length bias fixes can even make hacking easier to see, since lengths stop drifting for other reasons.
Watch next: whether sequence-level methods such as LUSPO and VESPO, already listed in TRL, outperform token-level losses on agent training, and how widely truncated or masked importance sampling becomes standard practice.
Frequently asked questions
Why does GRPO not need a value network?
It estimates how good an answer is by comparing it with other answers to the same prompt. The group mean acts as the baseline that a value network would otherwise predict, which saves the memory and compute of a second large model.
What exactly is length bias?
In the original GRPO loss each completion's token losses are averaged over its own length. A long completion therefore spreads its total weight thinly over many tokens, so each token of a long wrong answer is penalised less than each token of a short one.
Is DAPO a different algorithm or just a different loss?
The DAPO paper proposes several changes together: token-level loss averaging, a higher upper clip bound, dynamic sampling to avoid empty groups, and handling of overlong responses. In TRL, loss_type="dapo" selects the token-level averaging, and the clip bound is a separate setting.
Should I keep the KL penalty?
TRL defaults to β = 0, which removes the reference model and its memory cost, citing studies that found the term not essential. A small KL weight can still help if the policy drifts in ways your reward does not capture.
Does any of this matter for small experiments?
Yes, if your completions vary in length or your rewards are binary. The biases are systematic, so they show up as steady drifts in length or in which prompts the model improves on, even in short runs.
Summary
GRPO replaces PPO's value network with a simple comparison: each answer's advantage is its reward minus the group mean, usually divided by the group's standard deviation. The original loss then averages token losses within each completion, which under-penalises long wrong answers, and the std division shifts weight toward very hard and very easy questions. DAPO fixes the length bias by averaging over all tokens and adds clip-higher and dynamic sampling; Dr. GRPO removes both biases with constant normalisation and no std scaling; SAPO replaces the hard clip with a smooth gate. Current trainers expose all of these as options, so treat the loss type, reward scaling and clipping as hyperparameters to set and monitor. For more background, see the TRL and reinforcement learning pages and the training and alignment topic.
Sources
- Code Hugging Face: TRL GRPO Trainer documentation
- Code GitHub: TRL GRPOConfig source
- Code PyPI: trl release history
- Paper arXiv: DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models
- Paper arXiv: DAPO: An Open-Source LLM Reinforcement Learning System at Scale
- Paper arXiv: Understanding R1-Zero-Like Training: A Critical Perspective
- Paper arXiv: Soft Adaptive Policy Optimization
- Paper arXiv: Part I: Tricks or Traps? A Deep Dive into RL for LLM Reasoning
- Web John Schulman: Approximating KL Divergence
Cite this article
Kelahmet, Ö. C. (2026, November 23). GRPO loss variants explained: advantages, length bias, DAPO, Dr. GRPO and soft clipping. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/grpo-loss-normalisation-dapo-dr-grpo
BibTeX
@online{kelahmet2026grpo,
author = {Kelahmet, {\"O}zer Cem},
title = {{GRPO loss variants explained: advantages, length bias, DAPO, Dr. GRPO and soft clipping}},
year = {2026},
month = {nov},
url = {https://www.ozercemkelahmet.com/articles/grpo-loss-normalisation-dapo-dr-grpo}
}Version historyfirst version
- Published
Factual corrections are listed here with what changed. Wording and formatting edits are not listed.