Reinforcement Learning2025

Dr. GRPO

Understanding R1-Zero-Like Training (Dr. GRPO) Liu et al. arXiv

Dr. GRPO keeps long mistakes from getting a lighter penalty per token.

Why it mattered

Why do GRPO-trained reasoning models suddenly start rambling for 4,000 tokens whenever they're stuck on a problem? Dr. GRPO caught two subtle math bugs baked into GRPO: dividing loss by sequence length ∣yi∣|y_i| rewards longer wrong responses (each bad token gets a smaller penalty), and dividing advantage by std⁡(r)\operatorname{std}(r) overweights trivial or near-impossible questions.

Core insight

Use unnormalized group-centered advantages Ai=ri−mean⁡(r)A_i = r_i - \operatorname{mean}(r) (no division by std⁡(r)\operatorname{std}(r)) and normalize the policy gradient by a constant max-length denominator Lmax⁡L_{\max} instead of each response's own token length ∣yi∣|y_i|.

GRPORecipe(advantage='dr_grpo', validator='math', kl_coef=0.0) runs Dr. GRPO server-side in one CLI or SDK call: it computes unbiased mean-only advantages (ri−mean⁡(r)r_i - \operatorname{mean}(r) without / σ/\,\sigma) and normalizes the clipped policy gradient at the batch-token level instead of dividing each response by its own length ∣yi∣|y_i|. For an exact constant Lmax⁡L_{\max} denominator or custom Python rubrics, drop down to interactive Trainer with advantages.GroupMean() and losses.PPO(scale=...).

When to use

Use Dr. GRPO as your default critic-free RL objective whenever you notice GRPO inflating response length on wrong answers or overweighting trivial prompts. It costs the same compute as GRPO and only changes advantage scaling and token loss normalization.

Step-by-step walkthrough

  1. 01

    Import verifiable math prompts into a versioned dataset

    Pull GSM8K server-side with client.datasets.from_hf() so every record carries its prompt and reference answer for deterministic server-side math grading.

    client.datasets.from_hf("openai/gsm8k", config="main", split="train", prompt="question", answer="answer", limit=2560, name="gsm8k-grpo")
  2. 02

    Select advantage='dr_grpo' on managed GRPORecipe

    GRPORecipe(advantage='dr_grpo', kl_coef=0.0) removes group standard-deviation division (Ai=ri−mean⁡(r)A_i = r_i - \operatorname{mean}(r)) and aggregates token gradients across the batch instead of normalizing each completion by 1/∣yi∣1/|y_i| — eliminating both GRPO biases automatically.

    GRPORecipe(model="qwen/qwen3-8b", validator="math", advantage="dr_grpo", group_size=8, max_tokens=1024, kl_coef=0.0, max_steps=80)
  3. 03

    Launch and monitor completion length + accuracy live

    Launch on 1× H100 and track reward, mean_tokens, and eval_pass_at_1 in grad runs watch dr-grpo-math to verify incorrect traces stay concise.

    grad runs watch dr-grpo-math

Implementation

train.py
from grad import Grad, adapters
from grad.recipes import GRPORecipe

client = Grad()
ds = client.datasets.from_hf(
    "openai/gsm8k", config="main", split="train", prompt="question", answer="answer", limit=2560, name="gsm8k-grpo"
)

recipe = GRPORecipe(
    model="qwen/qwen3-8b",
    validator="math",
    advantage="dr_grpo",
    group_size=8,
    max_tokens=1024,
    kl_coef=0.0,
    clip_low=0.2,
    clip_high=0.2,
    max_steps=80,
    system_prompt="Solve step by step and put the final answer in \\boxed{...}.",
    adapter=adapters.LoRA(rank=32),
)

run = client.runs.create(dataset=ds, name="dr-grpo-math", recipe=recipe, max_cost_usd=10.0).wait()
print(run.artifact.ref, run.eval_report)

Benchmarks

Reported results from the original paper compared against its baseline.

AIME 2024 pass@1Qwen2.5-Math-7B zero-RL (Dr. GRPO vs. GRPO)
+4.1 pts
GRPO (7B)39.2%
Dr. GRPO (7B)43.3%
MATH-500 pass@1Qwen2.5-Math-7B zero-RL (Dr. GRPO vs. GRPO)
+3.0 pts
GRPO (7B)75.6%
Dr. GRPO (7B)78.6%

Models & datasets

ModelDurationEst. cost
Qwen3 8Brecommendedqwen/qwen3-8b
~24 min~$1.90
Qwen3 4Bfast smoke runqwen/qwen3-4b
~12 min~$0.95
Qwen3.5 9Bqwen/qwen3.5-9b
~28 min~$2.30
DatasetSourceSize
GSM8K MathHugging Face7,473 train / 1,319 test
MATH BenchmarkHugging Face7,500 train / 5,000 test

Practical gotchas

  • Server-managed GRPORecipe uses batch-token normalization (1 / sum(weights)) rather than per-sequence 1/∣yi∣1/|y_i| averaging; if you need the paper's exact fixed-constant denominator 1/(B⋅Lmax⁡)1 / (B \cdot L_{\max}), run interactive Trainer with advantages.GroupMean() and losses.PPO(scale=1.0 / (len(batch) * max_tokens)).
  • Keep kl_coef=0.0 on verifiable math to match Dr. GRPO's R1-Zero setup, or add a small kl_coef=0.01 if output formatting drifts.
  • Compare mean completion length on incorrect vs. correct eval responses — Dr. GRPO keeps incorrect traces noticeably shorter than vanilla GRPO.

grad primitives