Paper notes

DAPO: An Open-Source Reasoning RL System and the Four Tricks That Keep GRPO Stable on Long Chains of Thought

DAPO, open-sourced by ByteDance Seed and partners, adds Clip-Higher, dynamic sampling, token-level loss and overlong reward shaping to GRPO and reaches 50 on AIME 2024 (avg@32) from a Qwen2.5-32B base, against 30 for naive GRPO. Code checks the mechanisms and numbers behind each trick.

Published Updated 14 min read

On this page
  1. Why this paper matters
  2. Baseline: GRPO
  3. The four DAPO tricks
  4. Setup and results
  5. Checking it with code
  6. Limitations and what to keep in mind
  7. What to take from this paper
  8. Further reading
  9. FAQ

Why this paper matters

OpenAI o1 and DeepSeek-R1 made “train long chains of thought with reinforcement learning” the mainstream, but the paper points out that their technical reports leave out key details, so the community struggles to reproduce them. The authors tried it on a Qwen2.5-32B base: with the original GRPO recipe they got only 30 on AIME 2024, far below the 47 DeepSeek reported, and their analysis found entropy collapse, reward noise and training instability in naive GRPO.

This paper (ByteDance Seed, Tsinghua AIR and others, posted in March 2025) open-sources the algorithm, the training code (built on verl) and the dataset (DAPO-Math-17K) at once, and splits the improvements into four tricks that can be understood and reused separately. It is good reading for today’s open reasoning-RL recipes (see Reasoning RL) and the natural next stop after the original GRPO paper.

Baseline: GRPO

For each question qq sample a group of answers {oi}i=1G\{o_i\}_{i=1}^{G}, standardize the rewards RiR_i inside the group to get the advantage A^i,t=Ri−mean({Ri})std({Ri})\hat A_{i,t}=\frac{R_i-\mathrm{mean}(\{R_i\})}{\mathrm{std}(\{R_i\})}, and update with a PPO-style clipped objective. The paper stresses that GRPO uses a sample-level loss: average over the tokens within each answer first, then across answers. The reward is rule-based: +1+1 if the answer is equivalent to the reference, −1-1 otherwise.

The four DAPO tricks

The DAPO objective is:

JDAPO=E[1∑i=1G∣oi∣∑i=1G∑t=1∣oi∣min⁡(ri,tA^i,t, clip(ri,t,1−εlow,1+εhigh)A^i,t)]s.t.0<#{oi correct}<G\begin{aligned} \mathcal J_{DAPO}&=\mathbb E\left[\frac{1}{\sum_{i=1}^{G}|o_i|}\sum_{i=1}^{G}\sum_{t=1}^{|o_i|}\min\Big(r_{i,t}\hat A_{i,t},\ \mathrm{clip}\big(r_{i,t},1-\varepsilon_{low},1+\varepsilon_{high}\big)\hat A_{i,t}\Big)\right] \\ &\text{s.t.}\quad 0<\#\{o_i\ \text{correct}\}<G \end{aligned}

with ri,t=πθ(oi,t∣q,oi,<t)/πθold(oi,t∣q,oi,<t)r_{i,t}=\pi_\theta(o_{i,t}\mid q,o_{i,<t})/\pi_{\theta_{old}}(o_{i,t}\mid q,o_{i,<t}). The four tricks map to a few changes in this formula, and the paper also removes the KL penalty: a long-chain-of-thought reasoning model’s distribution is expected to drift far from the initial model anyway, so the constraint is unnecessary.

TrickProblem the paper points outWhat it does
Clip-HigherEntropy drops too fast and low-probability tokens cannot riseRaise the upper bound εhigh\varepsilon_{high} to 0.28, keep the lower bound εlow\varepsilon_{low} at 0.2
Dynamic samplingPrompts with accuracy 1 keep growing and the gradient weakensOversample, drop prompts with accuracy 0 or 1, fill the batch
Token-level lossSample-level averaging under-weights tokens of long answersNormalize by the total token count of the batch
Overlong reward shapingGood answers that get truncated are punished, noisy rewardMask the loss of truncated samples first, then a soft penalty

Clip-Higher. The PPO upper bound is multiplicative: with ε=0.2\varepsilon=0.2 and a positive advantage, a token with old probability 0.01 can rise to at most 0.012 after one update, while for a token at 0.9 the cap is 1.08 (already above 1, so it barely constrains). The paper’s evidence is that the up-clipped tokens have very low mean probability (below 0.2, Figure 3a), so the upper bound mostly stops low-probability exploration tokens and entropy falls quickly. A looser upper bound raises the policy’s entropy and gives more diverse samples (Figure 2); the lower bound is not raised because that would push those tokens’ probabilities to 0 and collapse the sampling space.

Dynamic sampling. When all answers in a group get the same reward, the advantage and gradient are zero. The paper observes that the share of prompts with accuracy 1 keeps rising during training (Figure 3b), fewer prompts in a batch carry signal and the gradient gets noisier. DAPO oversamples and drops prompts with accuracy 0 or 1 until the batch has only prompts with gradients. The paper argues this need not slow training: in a synchronous RL system generation time is dominated by long-tail samples, and the same performance is reached in fewer steps (Figure 6).

Token-level loss. Sample-level averaging gives every answer the same weight, so each token in a long answer contributes less. Two consequences: useful reasoning patterns in good long answers are learned slowly, and long answers often contain gibberish and repetition that the sample-level loss fails to penalize, so entropy and answer length grow unhealthily (Figure 4). The token-level loss gives every token the same weight regardless of the length of the answer it appears in.

Overlong reward shaping. Training usually sets a maximum generation length and truncated answers get a penalty by default, but a sound reasoning process may be penalized only for being too long, which adds noise. DAPO first uses “overlong filtering”, masking the loss of truncated samples, which clearly stabilizes training (Figure 5), and then adds a soft penalty: inside [Lmax−Lcache,Lmax][L_{max}-L_{cache},L_{max}] the longer the answer, the heavier the penalty.

Rlength(y)={0,∣y∣≤Lmax−Lcache(Lmax−Lcache)−∣y∣Lcache,Lmax−Lcache<∣y∣≤Lmax−1,Lmax<∣y∣R_{length}(y)=\begin{cases}0, & |y|\le L_{max}-L_{cache}\\[2pt] \dfrac{(L_{max}-L_{cache})-|y|}{L_{cache}}, & L_{max}-L_{cache}<|y|\le L_{max}\\[2pt] -1, & L_{max}<|y|\end{cases}

Setup and results

ItemSetting
Base model and frameworkQwen2.5-32B, verl
DataDAPO-Math-17K: 17K prompts whose answers are rewritten as integers for rule-based grading
OptimizationAdamW, constant learning rate 1×10−61\times10^{-6}, linear warm-up over the first 20 rollout steps
Batches512 prompts per step, 16 answers each; mini-batch 512, so 16 gradient updates per rollout step
LengthExpected maximum 16,384 tokens plus a 4,096-token soft-penalty zone, generation cap 20,480
Clippingεlow=0.2\varepsilon_{low}=0.2, εhigh=0.28\varepsilon_{high}=0.28
EvaluationAIME 2024 repeated 32 times and averaged (avg@32), temperature 1.0, top-p 0.7

Table 1 of the paper adds the tricks one by one, raising AIME 2024 avg@32 from 30 to 50 (DeepSeek-R1-Zero-Qwen-32B: 47):

ConfigurationAIME 2024 avg@32
Naive GRPO30
+ Overlong filtering36
+ Clip-Higher38
+ Soft overlong punishment41
+ Token-level loss42
+ Dynamic sampling (DAPO)50

Checking it with code

The code works through the mechanisms behind the four tricks in PyTorch: (1) automatic differentiation shows at which ratios the clipped objective has zero gradient, comparing symmetric clipping (εhigh=0.2\varepsilon_{high}=0.2) with Clip-Higher (0.28); (2) the ratio cap on the probability after one update; (3) the probability that a group of 16 answers is all right or all wrong, and whether the advantage really is 0 then; (4) how much gradient weight a long answer gets under sample-level and token-level normalization; (5) the values of the soft overlong penalty; (6) the per-step increments of Table 1. This checks mechanisms and arithmetic and does not retrain a 32B model, so the paper’s entropy curves and AIME scores are not reproduced here.

import torch

G = 16  # samples per prompt (paper setting)


def objective(logp, logp_old, adv, lo, hi):
    """Per-token clipped objective, Eq. (8): bounds 1-lo and 1+hi."""
    r = (logp - logp_old).exp()
    return torch.min(r * adv, r.clamp(1 - lo, 1 + hi) * adv)


print("1) Token gradient (w.r.t. log-prob), ratio = new / old probability")
print("ratio   A=+1 [0.2,0.2]  A=+1 [0.2,0.28]  A=-1 [0.2,0.2]")
for ratio in (0.7, 0.8, 0.9, 1.1, 1.2, 1.25, 1.3):
    row = []
    for adv, hi in ((1.0, 0.2), (1.0, 0.28), (-1.0, 0.2)):
        logp = torch.tensor(ratio).log().requires_grad_()
        objective(logp, torch.tensor(0.0), adv, 0.2, hi).backward()
        row.append(logp.grad.item())
    print(f"{ratio:4.2f} {row[0]:12.2f} {row[1]:15.2f} {row[2]:15.2f}")

print("\n2) Ratio cap after one update: p_old * (1 + eps_high)")
for p in (0.01, 0.1, 0.5, 0.9):
    print(f"p_old={p:<5} eps=0.20: {p * 1.2:.4f}   eps=0.28: {p * 1.28:.4f}")

print("\n3) Dynamic sampling: P(all right or all wrong), G=16")
for acc in (0.05, 0.2, 0.5, 0.8, 0.95, 0.99):
    zero = acc**G + (1 - acc) ** G
    print(f"accuracy {acc:4.2f}: P(zero advantage) = {zero:7.4f}, "
          f"prompts per useful one = {1 / (1 - zero):.2f}")
rewards = torch.ones(G)  # an all-correct group: zero advantage, no gradient
print("all-correct group advantages:",
      ((rewards - rewards.mean()) / (rewards.std() + 1e-6)).abs().max().item())

print("\n4) Loss weights: answers of 100 / 2000 tokens, A = +1 / -1")
lens = torch.tensor([100.0, 2000.0])
# mean within each answer, then across answers: weight per token
sample_level = (1 / lens) / 2
# average over all tokens together
token_level = torch.full((2,), 1 / lens.sum().item())
for name, w in (("sample-level", sample_level), ("token-level", token_level)):
    share = (w * lens)[1] / (w * lens).sum()
    print(f"{name:12s} per-token weight {w[0]:.6f} / {w[1]:.6f}, "
          f"long answer share {share:.1%}")

print("\n5) Soft overlong punishment: L_max = 20480, L_cache = 4096")
L_max, L_cache = 20480, 4096
for n in (16000, 16384, 17408, 18432, 19456, 20480, 21000):
    if n <= L_max - L_cache:
        r = 0.0
    elif n <= L_max:
        r = ((L_max - L_cache) - n) / L_cache
    else:
        r = -1.0
    print(f"length {n:5d}: penalty {r:+.2f}")

print("\n6) Paper Table 1: AIME 2024 avg@32 as techniques are added")
steps = [("Naive GRPO", 30), ("+ Overlong Filtering", 36),
         ("+ Clip-Higher", 38), ("+ Soft Overlong Punishment", 41),
         ("+ Token-level Loss", 42), ("+ Dynamic Sampling", 50)]
for (_, prev), (name, score) in zip(steps, steps[1:]):
    print(f"{name:28s} {score}  ({score - prev:+d})")
print(f"total {steps[-1][1] - steps[0][1]:+d} over naive GRPO")

Output (CPU, under 2 seconds):

1) Token gradient (w.r.t. log-prob), ratio = new / old probability
ratio   A=+1 [0.2,0.2]  A=+1 [0.2,0.28]  A=-1 [0.2,0.2]
0.70         0.70            0.70            0.00
0.80         0.80            0.80           -0.80
0.90         0.90            0.90           -0.90
1.10         1.10            1.10           -1.10
1.20         1.20            1.20           -1.20
1.25         0.00            1.25           -1.25
1.30         0.00            0.00           -1.30

2) Ratio cap after one update: p_old * (1 + eps_high)
p_old=0.01  eps=0.20: 0.0120   eps=0.28: 0.0128
p_old=0.1   eps=0.20: 0.1200   eps=0.28: 0.1280
p_old=0.5   eps=0.20: 0.6000   eps=0.28: 0.6400
p_old=0.9   eps=0.20: 1.0800   eps=0.28: 1.1520

3) Dynamic sampling: P(all right or all wrong), G=16
accuracy 0.05: P(zero advantage) =  0.4401, prompts per useful one = 1.79
accuracy 0.20: P(zero advantage) =  0.0281, prompts per useful one = 1.03
accuracy 0.50: P(zero advantage) =  0.0000, prompts per useful one = 1.00
accuracy 0.80: P(zero advantage) =  0.0281, prompts per useful one = 1.03
accuracy 0.95: P(zero advantage) =  0.4401, prompts per useful one = 1.79
accuracy 0.99: P(zero advantage) =  0.8515, prompts per useful one = 6.73
all-correct group advantages: 0.0

4) Loss weights: answers of 100 / 2000 tokens, A = +1 / -1
sample-level per-token weight 0.005000 / 0.000250, long answer share 50.0%
token-level  per-token weight 0.000476 / 0.000476, long answer share 95.2%

5) Soft overlong punishment: L_max = 20480, L_cache = 4096
length 16000: penalty +0.00
length 16384: penalty +0.00
length 17408: penalty -0.25
length 18432: penalty -0.50
length 19456: penalty -0.75
length 20480: penalty -1.00
length 21000: penalty -1.00

6) Paper Table 1: AIME 2024 avg@32 as techniques are added
+ Overlong Filtering         36  (+6)
+ Clip-Higher                38  (+2)
+ Soft Overlong Punishment   41  (+3)
+ Token-level Loss           42  (+1)
+ Dynamic Sampling           50  (+8)
total +20 over naive GRPO

How to read these numbers:

  1. Clip-Higher frees only a small band. With a positive advantage, a token at ratio 1.25 has zero gradient under symmetric clipping and still has gradient with εhigh=0.28\varepsilon_{high}=0.28; at 1.30 both are zero. On the negative-advantage side (lower bound 0.2) both settings are identical: ratio 0.70 already has no gradient. So Clip-Higher changes only the upper boundary.
  2. The ratio cap is multiplicative. For a token at old probability 0.01 the cap goes from 0.0120 to 0.0128, about 6.7% more in relative terms and only 0.0008 in absolute terms; for a token at 0.9 both caps exceed 1 and clipping does nothing. This agrees with the paper’s argument, and shows that going from 0.2 to 0.28 is a mild change. Its effect on entropy is what the paper observed in its 32B runs and is not reproduced here.
  3. All-right or all-wrong groups are common, especially at the ends. With G=16G=16, a prompt with accuracy 5% or 95% has a 44% chance that the whole group has zero advantage, and at accuracy 99% it is 85%, which takes about 6.7 times as many samples to get one prompt with a gradient; at accuracy 50% it almost never happens. The code also confirms that an all-correct group has exactly zero advantage. The real cost in training depends on the distribution of prompt accuracies, which is not computed here.
  4. Sample-level and token-level normalization differ a lot. For two answers of 100 and 2000 tokens with advantages +1+1 and −1-1, sample-level normalization gives each token of the long answer one twentieth of the weight of a token of the short one, with 50% of the total weight each; token-level normalization gives the long answer 95.2% (2000/2100).
  5. The soft penalty is a straight slope. Beyond 16,384 tokens it falls linearly, 0.25 for every extra 1,024 tokens, reaching −1-1 at 20,480 where it meets the penalty for hard truncation.
  6. The increments of Table 1. The six steps add +6, +2, +3, +1 and +8, in total +20; dynamic sampling has the largest increment. But each row is a single number with no seed variance, and the size of an increment depends on the order of adding, so they should not be read as independent contributions.

Limitations and what to keep in mind

  • Verified only on math. The dataset is integer-answer problems that can be graded by rule. The paper says the method can be transferred to other tasks but does not test it on any.
  • No error bars in Table 1. One number per row, no seed variance, and cumulative addition means the contributions cannot be attributed independently.
  • The comparison is not like for like. Against the 47 of DeepSeek-R1-Zero-Qwen-32B the data, framework and hyperparameters all differ, and “half the training steps” is the paper’s own comparison.
  • Cost is moved around. Dynamic sampling oversamples; the paper argues total training time is barely affected, which relies on the system being synchronous and generation time being dominated by long-tail samples.
  • Monitoring matters more than any single trick. The paper itself stresses watching response length, reward, entropy and mean probability together, and notes that training reward often correlates poorly with validation accuracy, which signals overfitting.
  • The code here checks mechanisms and arithmetic only and does not reproduce 32B-scale training.

What to take from this paper

  1. For reproducing reasoning RL, details are everything. The same GRPO, naively implemented, scores only 30 on Qwen2.5-32B.
  2. The upper and lower clip bounds need not be symmetric. A multiplicative upper bound favors high-probability tokens by construction, and loosening it leaves room for exploration.
  3. Samples without gradients still cost something. All-right or all-wrong prompts occupy the batch without contributing signal, and dynamic sampling spends the budget on prompts that do.
  4. How the loss is normalized decides whose voice is loud. Whether tokens of long answers get diluted directly shapes the course of entropy and length.
  5. Do not treat truncation as a wrong answer. Punishing truncated samples adds noise to good reasoning.
  6. Watch the curves, not only the endpoint. Entropy, length, reward and mean probability are the dashboard that tells whether training has gone off course.

Further reading

FAQ

What problem does each of the four DAPO tricks solve?
Clip-Higher raises only the upper clipping bound (from 0.2 to 0.28) to ease entropy collapse. Dynamic sampling drops prompts whose answers are all right or all wrong so every prompt in the batch has an effective gradient. The token-level loss gives every token the same weight whether it sits in a long or a short answer. Overlong reward shaping stops giving truncated answers a flat penalty, first masking them and then penalizing length linearly, which reduces reward noise.
Why does Clip-Higher raise only the upper bound?
The paper's argument is that the upper bound limits the growth of low-probability exploration tokens. The bound is multiplicative, so a token at probability 0.01 can rise to at most 0.012 in one update, while for a token at 0.9 the cap already exceeds 1 and barely constrains it. The lower bound stays at 0.2 because raising it would push those tokens' probabilities to 0 and collapse the sampling space.
Why filter prompts that are all right or all wrong?
In GRPO a group whose rewards are all equal has zero advantage and zero gradient. The paper observes that the share of prompts with accuracy 1 keeps growing during training, so fewer prompts in a batch carry signal and the gradient variance grows. Dynamic sampling oversamples and drops such prompts until the batch is full, which makes the sampling cost dynamic.
How should the 50 points on AIME 2024 be read?
It is the average accuracy over 32 repeated evaluations (avg@32, temperature 1.0, top-p 0.7) of Qwen2.5-32B after reinforcement learning. The paper says it beats DeepSeek-R1-Zero-Qwen-32B at 47 with half the training steps. Each row of Table 1 is a single number with no seed variance, and the training data and recipe differ from the baseline's, so the contribution of each trick is only a rough guide.