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 rewards longer wrong responses (each bad token gets a smaller penalty), and dividing advantage by overweights trivial or near-impossible questions.
Core insightUse unnormalized group-centered advantages (no division by ) and normalize the policy gradient by a constant max-length denominator instead of each response's own token length .
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 ( without ) and normalizes the clipped policy gradient at the batch-token level instead of dividing each response by its own length . For an exact constant 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
- 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") - 02
Select advantage='dr_grpo' on managed GRPORecipe
GRPORecipe(advantage='dr_grpo', kl_coef=0.0)removes group standard-deviation division () and aggregates token gradients across the batch instead of normalizing each completion by — 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) - 03
Launch and monitor completion length + accuracy live
Launch on 1× H100 and track
reward,mean_tokens, andeval_pass_at_1ingrad runs watch dr-grpo-mathto verify incorrect traces stay concise.grad runs watch dr-grpo-math
Implementation
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.
Models & datasets
| Model | Duration | Est. 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 |
| Dataset | Source | Size |
|---|---|---|
| GSM8K Math | Hugging Face | 7,473 train / 1,319 test |
| MATH Benchmark | Hugging Face | 7,500 train / 5,000 test |
Practical gotchas
- Server-managed
GRPORecipeuses batch-token normalization (1 / sum(weights)) rather than per-sequence averaging; if you need the paper's exact fixed-constant denominator , run interactiveTrainerwithadvantages.GroupMean()andlosses.PPO(scale=1.0 / (len(batch) * max_tokens)). - Keep
kl_coef=0.0on verifiable math to match Dr. GRPO's R1-Zero setup, or add a smallkl_coef=0.01if output formatting drifts. - Compare mean completion length on incorrect vs. correct eval responses — Dr. GRPO keeps incorrect traces noticeably shorter than vanilla GRPO.