RL with verifiable rewards (GRPO)
Reinforcement learning where a program, not a person, scores each answer (tests pass, result matches). GRPO makes it cheap: sample a group of answers per prompt and reinforce those that beat the group average.
Analogy: A student who tries each exercise eight times and checks every attempt against the answer key: no tutor explains anything, but the approaches that beat their own average stick.
How it works
- Any task a program can check qualifies: code against unit tests, math answers, JSON, SQL, tool calls.
- The check is objective and nearly free: no labelers, and no learned reward model to fool.
- GRPO needs no critic: the group mean replaces PPO's value model, usually as large as the policy.
- Keep prompts the model solves ~10–90% of the time; all-pass or all-fail groups give zero advantage.
- Still read samples: a loose verifier gets gamed, like
WHERE 1=0matching empty gold results.
Check yourself
Answer to mark it learned; your answers aren't scored.
Your GRPO run on text-to-SQL lifts held-out accuracy from 52% to 68%. Reading samples, you find many "wins" are WHERE 1=0 on questions whose gold answer is an empty set. What do you do?
Go deeper
Full explanation
RLVR trains a model with reinforcement learning where the reward comes from a program: unit tests pass, the math answer matches, the JSON validates, the SQL returns the expected rows. The check is objective and nearly free, so you can grade millions of attempts with no labelers and no learned reward model to fool.
The loop: sample several answers per prompt, score each with the verifier, and raise the probability of the tokens in the high-scoring ones.
GRPO (Group Relative Policy Optimization, from DeepSeekMath, 2024) is the default algorithm. PPO needs a critic, a value model usually as large as the policy, to judge whether an answer was better than expected. GRPO drops it: it samples a group of G answers (commonly 8–64) and uses each one's reward minus the group mean, divided by the group's standard deviation, as its advantage. Answers that beat their siblings get reinforced. A KL term (optional in newer recipes) keeps the policy near the reference.
DeepSeek-R1-Zero applied GRPO straight to a base model with only accuracy and format rewards, no SFT, and long chains of thought, self-checking and backtracking emerged on their own.
It isn't only for math: extraction with gold fields, text-to-SQL, code and tool calls all qualify if a program can check the output.
Code GRPO on GSM8K with a rule-based reward (TRL)
import re
from datasets import load_dataset
from trl import GRPOConfig, GRPOTrainer
MODEL = "Qwen/Qwen2.5-1.5B-Instruct" # any small instruct model
ds = load_dataset("openai/gsm8k", "main", split="train")
ds = ds.map(lambda r: {
"prompt": r["question"] + "\nThink step by step, then end with 'Answer: <number>'.",
"answer": r["answer"].split("####")[-1].strip(), # gold number only
})
def final_number(text: str) -> str | None:
m = re.search(r"Answer:\s*(-?[\d,.]+)", text)
return m.group(1).replace(",", "").rstrip(".") if m else None
# Extra dataset columns ("answer") reach reward functions as kwargs
def correctness(completions, answer, **kwargs):
return [1.0 if final_number(c) == a.replace(",", "") else 0.0
for c, a in zip(completions, answer)]
def format_ok(completions, **kwargs):
return [0.1 if "Answer:" in c else 0.0 for c in completions]
args = GRPOConfig(
output_dir="grpo-gsm8k",
num_generations=8, # group size G: advantage = reward vs group mean
max_completion_length=512,
learning_rate=1e-6,
beta=0.0, # KL weight; recent recipes often drop it
)
trainer = GRPOTrainer(model=MODEL, reward_funcs=[correctness, format_ok],
args=args, train_dataset=ds)
trainer.train()Real example
A data team has 6,000 (question, gold SQL) pairs over its warehouse. Reward: 1 if the generated query returns the same rows as the gold query on a snapshot DB, else 0. Their SFT'd 7B model scores 52% execution accuracy. They drop questions it solves 8/8 or 0/8 times (zero advantage, wasted compute), keep 3,900, and run GRPO with G = 8. Held-out accuracy reaches 68%, until someone reads samples: 9% of the "wins" were WHERE 1=0 on questions whose gold answer was an empty set. They remove those questions, add a non-empty check and retrain: 66%, and real.
Trade-offs +4 · −4
+ You gain
- No human labels: quality scales with compute wherever an answer can be checked.
- A rule-based reward is much harder to game than a learned reward model; DeepSeek avoided neural rewards for R1's reasoning for that reason.
- GRPO is lighter than PPO: no policy-sized critic, and with rule rewards no reward model either.
- Optimizes the metric you ship on: tests passed, execution accuracy, schema validity.
− You pay
- Only works where outputs are checkable; open-ended quality still needs preferences or judges.
- Rollouts dominate cost: G long generations per prompt, plus sandboxes to run code safely.
- Mostly sharpens what the model can already do: if it never solves a task, there is no signal.
- Policies exploit any gap in the verifier (reward hacking), and responses tend to keep growing.
Use it when
You have thousands of tasks with programmatically checkable outputs, an open model that solves some but not all of them, and prompting plus SFT have plateaued on the metric you care about.
Avoid it when
Open-ended quality with no verifier (use DPO & preference optimization or a judge), tasks the model solves ~0% of the time (no signal), or before trying SFT on good examples, which is cheaper.
Numbers to know 4
- DeepSeek-R1-Zero: AIME 2024 pass@1 rose from 15.6% to 71.0% with pure RL (86.7% with majority voting).
- GRPO group size: commonly 8–64 samples per prompt; TRL's default is 8.
- Rule of thumb: keep prompts the model solves ~10–90% of the time; all-pass or all-fail groups give zero advantage.
- GRPO was introduced in DeepSeekMath (Feb 2024); the term RLVR was coined in AI2's Tülu 3 (Nov 2024).
Common pitfalls 4
- Trusting the reward curve: policies learn to special-case tests, print expected output or exploit lenient parsers. Read samples often and keep a held-out check the policy never trains on.
- Training on prompts that are always or never solved: zero advantage, pure wasted rollouts. Filter by measured pass rate first.
- Ignoring length: responses grow until truncated, and truncated answers score 0. Track length, raise the limit or penalize overlong outputs.
- Rewarding guessable outputs: on yes/no or multiple choice a lucky guess earns full reward, so the model learns to guess. Prefer free-form answers.
Interview questions 3
Answer out loud first, then reveal.
How does GRPO differ from PPO, and why does it matter?Show answer
Both are policy-gradient methods with a clipped update and a KL anchor; the difference is the baseline. PPO trains a value model, usually as big as the policy, to estimate expected reward: double the trainable memory and a second network that can destabilize training. GRPO samples a group of answers per prompt and uses the group's mean and standard deviation instead. It's simpler and cheaper, and with a verifier as the reward the only large models are the policy and the reference. The cost is G rollouts per prompt, and no signal when the whole group agrees.
You're asked to apply RLVR to an internal task. How do you set it up?Show answer
I start with the verifier, because the policy will optimize exactly what it checks and nothing else; I validate it against a few hundred hand-labelled outputs for false positives. Then I measure the SFT model's pass rate per task and keep the ones it solves sometimes. I run GRPO with TRL or veRL on a small model first, with a held-out set graded by a stricter check than training uses. During training I read samples, track length and KL, and stop at the first sign of reward hacking. If plain SFT gets most of the gain, I ship that instead.
What did DeepSeek-R1-Zero show, and what are its limits?Show answer
That reasoning behaviours, long chains of thought, self-verification and backtracking, can emerge from pure RL on a strong base model with only rule-based rewards: AIME pass@1 went from 15.6% to 71%. The limits: R1-Zero's outputs were hard to read and mixed languages, so R1 added cold-start SFT and more stages. And later work suggests RLVR mostly sharpens sampling toward paths the base model could already find rather than creating new capability, so the base model still sets the ceiling.