Reinforcement Learning2025

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 insight

Raise the upper clipping bound (εhigh=0.28\varepsilon_{\text{high}} = 0.28 while keeping εlow=0.20\varepsilon_{\text{low}} = 0.20) so low-probability exploratory reasoning tokens can grow; drop the KL penalty (β=0\beta = 0) on verifiable math; dynamically sample until you fill target_groups non-zero-variance groups; and apply a smooth length penalty near max_tokens instead 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

  1. 01

    Combine MathEquivalence with a soft overlong penalty

    Score correctness with validators.MathEquivalence() and deduct a smooth ramp penalty as completion length approaches max_tokens instead 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)])
  2. 02

    Collect full batches of varied groups via dynamic sampling

    env.sample_varied_groups() keeps drawing prompt chunks under one pinned snapshot until target_groups non-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)
  3. 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 only clip_high lets 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))
  4. 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_used catches 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

train.py
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().artifact

Benchmarks

Reported results from the original paper compared against its baseline.

AIME 2024 pass@1Qwen2.5-32B RL (DAPO vs. vanilla GRPO baseline)
+20.0 pts
Vanilla GRPO (32B)30%
DAPO (32B)50%
Training convergence speedTraining efficiency vs. DeepSeek-R1-Zero-Qwen-32B baseline (50% fewer steps)
2.0× faster
Baseline RL schedule1×
DAPO schedule2×

Models & datasets

ModelDurationEst. 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
DatasetSourceSize
DAPO-Math-17kHugging Face17,000 competition math prompts
GSM8K Math ReasoningHugging Face7,473 train / 1,319 test

Practical gotchas

  • Clip-Higher is sensitive to learning rate — use optim.AdamW(lr='auto', objective='rl') or keep η∈[10−5,2.5×10−5]\eta \in [10^{-5}, 2.5 \times 10^{-5}] when raising clip_high to 0.28.
  • If sample_varied_groups() consumes most of your task pool to collect target_groups, your prompts are too easy or too hard; mix in intermediate-difficulty problems.
  • Dropping kl_coef=0.0 works cleanly on verifiable math/code, but re-enable a small KL(trainer, coef=0.005, weights='initial') if formatting drifts.

grad primitives