DAPO
DAPO: An Open-Source LLM RL System at Scale Yu et al. arXiv
DAPO trains on questions with mixed outcomes and gives promising rare tokens more room to gain probability.
Why it mattered
When open-source teams tried reproducing DeepSeek-R1 with vanilla GRPO, runs routinely collapsed into repetitive, low-entropy answers after a few dozen steps — and long reasoning chains got crushed by equal-per-sequence averaging. DAPO dissected the failure modes into four surgical fixes that halved training steps to 50 points on AIME.
Core insightRaise the upper clipping bound ( while keeping ) so low-probability exploratory reasoning tokens can grow; drop the KL penalty () on verifiable math; dynamically sample until you fill
target_groupsnon-zero-variance groups; and apply a smooth length penalty nearmax_tokensinstead of a hard cliff.
Need just Clip-Higher (clip_low=0.2, clip_high=0.28), zero KL (kl_coef=0.0), and zero-variance group skipping? Managed GRPORecipe runs that from one CLI command. This interactive Trainer loop adds DAPO's custom soft overlong length ramp and Environment.sample_varied_groups() dynamic pool resampling with losses.StableReinforce(clip_low=0.2, clip_high=0.28, kl_coef=0.0) and trainer.train_step().
When to use
Reach for DAPO when vanilla GRPO plateaus early, collapses entropy, or wastes batches on all-pass/all-fail prompts during long chain-of-thought math or code RL. For short single-turn tasks with well-calibrated prompt difficulty, plain GRPO or Dr. GRPO is simpler to tune.
Step-by-step walkthrough
- 01
Combine MathEquivalence with a soft overlong penalty
Score correctness with
validators.MathEquivalence()and deduct a smooth ramp penalty as completion length approachesmax_tokensinstead of a hard truncation cliff. A smooth length ramp gives the policy a clean gradient away from runaway chains instead of an abrupt zero-reward cliff.Rubric([Scorer('math', fn=validators.MathEquivalence(), weight=0.85), Scorer('concise', fn=soft_length, weight=0.15)]) - 02
Collect full batches of varied groups via dynamic sampling
env.sample_varied_groups()keeps drawing prompt chunks under one pinned snapshot untiltarget_groupsnon-zero-variance groups are gathered. Filtering out zero-variance groups before stepping ensures every optimizer update carries real learning signal.env.sample_varied_groups(trainer, tasks=pool, target_groups=16, group_size=8, max_tokens=2048) - 03
Update with asymmetric Clip-Higher and zero KL
Pass
losses.StableReinforce(clip_low=0.2, clip_high=0.28, kl_coef=0.0)to let low-probability reasoning tokens climb while keeping downward updates bounded. Raising onlyclip_highlets low-probability exploratory tokens grow without letting negative updates destabilize the policy.trainer.forward_backward(batch, loss=losses.StableReinforce(clip_low=0.2, clip_high=0.28, kl_coef=0.0)) - 04
Track dynamic-sampling yield in grad runs watch
Log mean reward, groups_used, and true token-level Shannon entropy per step via trainer.train_step() so you spot difficulty saturation early. Watching
groups_usedcatches prompt-difficulty saturation before you burn budget on solved prompts.trainer.train_step(batch, loss=losses.StableReinforce(clip_low=0.2, clip_high=0.28, kl_coef=0.0), optim=optim.AdamW(lr='auto', objective='rl'), metrics={'reward': grad.mean_reward(groups), 'groups_used': batch.metrics['groups_used']})
Implementation
import random
import grad
from grad import Environment, Grad, Rubric, Scorer, Task, Trajectory, adapters, advantages, losses, optim, validators
client = Grad()
ds = client.datasets.from_hf("openai/gsm8k", config="main", split="train", prompt="question", answer="answer", limit=4096)
tasks = [Task(id=str(i), prompt=r["messages"][0]["content"], expected_output=r["expected_output"]) for i, r in enumerate(ds.records())]
def soft_length_score(traj: Trajectory, max_chars: int = 6000, buffer: int = 1500) -> float:
n = len(traj.text)
if n <= max_chars - buffer:
return 1.0
return max(0.0, 1.0 - (n - (max_chars - buffer)) / buffer)
env = Environment(
rubric=Rubric([
Scorer("math", fn=validators.MathEquivalence(), weight=0.85),
Scorer("length", fn=soft_length_score, weight=0.15),
]),
max_turns=1,
system_prompt="Reason carefully and place the final answer in \\boxed{...}.",
)
total_steps = 100
with client.trainers.create(
model="qwen/qwen3-8b",
name="dapo-math",
adapter=adapters.LoRA(rank=32),
total_steps=total_steps,
max_cost_usd=12.0,
) as trainer:
for step in range(1, total_steps + 1):
pool = random.sample(tasks, k=min(64, len(tasks)))
groups = env.sample_varied_groups(trainer, tasks=pool, target_groups=16, group_size=8, max_tokens=2048, temperature=1.0)
batch = grad.with_advantages(groups, advantages.GroupStd())
if not batch:
continue
trainer.train_step(
batch,
loss=losses.StableReinforce(clip_low=0.2, clip_high=0.28, kl_coef=0.0),
optim=optim.AdamW(lr="auto", objective="rl"),
metrics={"reward": grad.mean_reward(groups), "groups_used": batch.metrics["groups_used"]},
)
artifact = trainer.export(name="dapo-math").result().artifactBenchmarks
Reported results from the original paper compared against its baseline.
Models & datasets
| Model | Duration | Est. cost |
|---|---|---|
Qwen3 8Brecommendedqwen/qwen3-8b | ~35 min | ~$2.80 |
Qwen3 4Bfast smoke runqwen/qwen3-4b | ~16 min | ~$1.25 |
Qwen3 14Bqwen/qwen3-14b | ~52 min | ~$4.60 |
| Dataset | Source | Size |
|---|---|---|
| DAPO-Math-17k | Hugging Face | 17,000 competition math prompts |
| GSM8K Math Reasoning | Hugging Face | 7,473 train / 1,319 test |
Practical gotchas
- Clip-Higher is sensitive to learning rate — use
optim.AdamW(lr='auto', objective='rl')or keep when raisingclip_highto0.28. - If
sample_varied_groups()consumes most of your task pool to collecttarget_groups, your prompts are too easy or too hard; mix in intermediate-difficulty problems. - Dropping
kl_coef=0.0works cleanly on verifiable math/code, but re-enable a smallKL(trainer, coef=0.005, weights='initial')if formatting drifts.