On this page
A compute cluster has 14 workers with 12 available slots each and one slot per job. How many concurrent jobs fit? The product is 168. A deterministic checker marks 168 right and 148 wrong in microseconds, with zero human raters and no learned reward model drifting out of distribution.
That single shift drives Reinforcement Learning with Verifiable Rewards (RLVR): replace a learned preference scorer with an executable check whenever correctness can be tested by code, symbolic math, a SQL engine, or a theorem prover.[1] Tülu 3 popularized the RLVR name, and DeepSeek-R1 scaled rule-based rewards inside a multi-stage reasoning pipeline.[1][2]
Replacing a neural reward model with code does not eliminate reward hacking; it aims optimization pressure straight at your parser rules and rollout infrastructure. A loose parser rewarding \boxed{168} anywhere invites multi-box answer spraying, an unisolated code sandbox invites test exfiltration, and an async rollout loop that drops observation masks or loses policy-version tracking silently corrupts gradients.

Where RLVR fits in post-training
RLVR complements SFT, RLHF, and DPO rather than replacing them:
| Method | Supervision signal | Best-fit task scope |
|---|---|---|
| SFT | Reference demonstration tokens (cross-entropy) | Base formatting, syntax, and distilled teacher traces |
| RLHF | Learned scalar reward from preference pairs[3] | Open-ended quality (tone, clarity, nuanced helpfulness) |
| DPO | Offline chosen vs. rejected preference pairs[4] | Direct preference alignment without online rollouts |
| RLVR | Executable programmatic checks | Exact verifiable properties (math, code, SQL, proofs) |

Designing executable verifiers
In minimal outcome-only form, a verifiable reward returns 1 if completion passes verification for prompt and 0 otherwise:
Variants adjust scale and auxiliary terms: Tülu 3 scored pass, fail, and for missing EOS under PPO,[1] while DeepSeek-R1-Zero summed accuracy and <think>...</think> format rewards.[5] Keep format credit strictly smaller than correctness so spotless wrong answers never outrank correct ones.
Outcome blindness and infrastructure quarantine
Outcome grading scores only the final extracted answer, not the reasoning trace: a lucky shortcut ("97 ends in 7, so it is prime. \boxed{Yes}") earns the same 1.0 as a valid divisibility check, while a 40-step proof with one arithmetic slip on line 39 gets 0.0. (Process supervision, such as learned Process Reward Models[6] or tactic checkers, localizes mid-trace errors when step labels exist.[7])
Verifiers across math, code, SQL, and formal proofs
- Math and exact decimals: Normalize equivalent forms (
0.5vs1/2) viaFraction(Decimal(...))(or SymPy with strict timeouts as in Math-Verify[8]) to eliminate binary float drift. Require one canonical\boxed{...}field so multi-box guesses score0.0, and validate the reference before inspecting the candidate so corrupted labels raise for quarantine. - Sandboxed code: Execute untrusted code inside microVMs (Firecracker) or user-space kernels (gVisor) with read-only mounts, no egress networking, wall-clock timeouts (sleeping processes burn zero CPU), and gold answers kept outside the child process.[9][10] Guard against Python's
bool-subclasses-inttrap (True == 1), and hold out hidden test cases against lookup-table memorization. - SQL and theorem provers: Without
ORDER BY, SQL row order is unspecified,[11] so compare multisets (Counter) to enforce duplicate andNULLcounts without punishing valid orderings. In Lean 4, inspect#print axiomsto rejectsorryAxand unauthorized axioms.[12]
import re
from decimal import Decimal
from fractions import Fraction
NUM_RE = re.compile(r"-?[0-9]{1,20}(?:\.[0-9]{1,20})?")
def extract_single_boxed(text: str) -> str | None:
if len(text) > 4096 or text.count(r"\boxed") != 1:
return None
m = re.findall(r"\\boxed\{(-?[0-9]{1,20}(?:\.[0-9]{1,20})?)\}", text)
return m[0] if len(m) == 1 else None
def parse_exact(val: int | str) -> Fraction:
if NUM_RE.fullmatch(str(val)) is None:
raise ValueError(f"Invalid reference: {val!r}")
return Fraction(Decimal(str(val)))
def verify_math(resp: str, truth: int | str, tol: str = "0") -> float:
exp, eps = parse_exact(truth), parse_exact(tol)
ans = extract_single_boxed(resp)
return 0.0 if ans is None else float(abs(Fraction(Decimal(ans)) - exp) <= eps)
for name, r, t, tol in [("correct", r"14*12=168. \boxed{168}", 168, "0"),
("ambiguous", r"\boxed{168} or \boxed{148}", 168, "0"),
("in_tol", r"\boxed{50.36}", "50.35", "0.01"),
("out_tol", r"\boxed{50.361}", "50.35", "0.01")]:
print(f"{name:9s}: reward={verify_math(r, t, tol)}")correct : reward=1.0
ambiguous: reward=0.0
in_tol : reward=1.0
out_tol : reward=0.0from collections import Counter
import json, sqlite3, subprocess, sys
def code_verifier(code: str, cases: list[tuple[tuple[int, ...], int]]) -> float:
for inputs, expected in cases:
runner = code + f"\nimport json\nprint(json.dumps(solve(*{inputs!r})))\n"
try:
proc = subprocess.run([sys.executable, "-I", "-c", runner], capture_output=True, text=True, timeout=1.0)
except subprocess.TimeoutExpired:
return 0.0
if proc.returncode != 0: return 0.0
try: val = json.loads(proc.stdout)
except json.JSONDecodeError: return 0.0
if type(val) is not int or val != expected: return 0.0 # reject bool (True == 1)
return 1.0
def sql_verifier(query: str, expected_rows: list[tuple]) -> float:
conn = sqlite3.connect(":memory:")
conn.execute("CREATE TABLE jobs (slots INT)")
conn.executemany("INSERT INTO jobs VALUES (?)", [(4,), (None,), (7,), (None,)])
try: rows = conn.execute(query).fetchall()
except sqlite3.Error: return 0.0
finally: conn.close()
return float(Counter(rows) == Counter(expected_rows))
allowed = {"Classical.choice", "propext", "Quot.sound"}
cases = [((14, 12), 168), ((8, 12), 96)]
print("code good/bad/bool:", code_verifier("def solve(a,b): return a*b", cases),
code_verifier("def solve(a,b): return a+b", cases), code_verifier("def solve(a,b): return True", [((1,1),1)]))
exp = [(4,), (None,), (7,), (None,)]
print("sql order/distinct:", sql_verifier("SELECT slots FROM jobs ORDER BY slots DESC", exp),
sql_verifier("SELECT DISTINCT slots FROM jobs", exp))
print("proof valid/sorryAx:", float({"Classical.choice"} <= allowed), float({"sorryAx"} <= allowed))code good/bad/bool: 1.0 0.0 0.0
sql order/distinct: 1.0 0.0
proof valid/sorryAx: 1.0 0.0Open-ended writing, architectural judgment, and nuanced safety tone still lack exact executable rules and belong to RLHF/DPO or human review.
Group Relative Policy Optimization (GRPO)
RLVR defines the reward source; PPO and GRPO define the policy update. Standard PPO trains a separate critic , doubling model and optimizer state.[13] DeepSeekMath introduced GRPO to drop the critic completely, and DeepSeek-R1 scaled it across reasoning post-training.[14][2]
For each prompt , sample completions , verify each, and normalize against the group mean and population standard deviation:
With rollouts where four hit 168 () and four miss (), mean 0.5 and std 0.5 assign to passes and to misses. Uniform groups ([1,1,1,1] or [0,0,0,0]) receive guarded (zero comparative reward gradient, though an enabled KL term still emits gradients).
GRPO optimizes a PPO-clipped token surrogate over included generated tokens , regularized by per-token KL estimator ():[14]
Here compares the current policy to the frozen rollout policy. Note two practical distinctions: evaluating on tokens sampled from matches reverse KL in value in expectation, whereas differentiating on fixed sampled tokens yields the forward KL gradient in expectation and therefore differs from differentiating full categorical reverse KL; and trainers such as TRL GRPOTrainer and DAPO[15][16] expose global active-token averaging, decoupled upper/lower clip thresholds, optional , and dynamic filtering of zero-variance groups under a hard generation cap (at a 1% pass rate with , only of groups are mixed).
import torch
def group_adv(r: torch.Tensor) -> torch.Tensor:
std = r.std(correction=0)
return torch.zeros_like(r) if std == 0 else (r - r.mean()) / std
def clip_surr(ratio: torch.Tensor, adv: torch.Tensor, eps: float = 0.2) -> torch.Tensor:
return torch.minimum(ratio * adv, ratio.clamp(1.0 - eps, 1.0 + eps) * adv)
rewards = torch.tensor([1., 0., 0., 1., 0., 1., 0., 1.], dtype=torch.float64)
adv = group_adv(rewards)
logits = torch.zeros(8, dtype=torch.float64, requires_grad=True)
ref_lp = logits.detach().log_softmax(dim=0)
for step in range(1, 11):
old_lp = logits.detach().log_softmax(dim=0)
lp = logits.log_softmax(dim=0)
kl = ((ref_lp - lp).exp() - (ref_lp - lp) - 1.0).mean()
loss = -clip_surr((lp - old_lp).exp(), adv).mean() + 0.05 * kl
logits.grad = None; loss.backward()
with torch.no_grad():
logits -= 0.4 * logits.grad
p_pass = logits.softmax(dim=0)[rewards == 1].sum().item()
if step in (1, 5, 10):
print(f"step={step:2d} | pass_prob={p_pass:.4f} | kl={kl.item():.5f}")
grads = []
for rv, av in [(1.3, 1.0), (0.7, -1.0), (0.7, 1.0), (1.3, -1.0)]: r = torch.tensor(rv, requires_grad=True)
clip_surr(r, torch.tensor(av)).backward()
grads.append(r.grad.item())
print("clip grads [0, 0, 1, -1]:", grads)step= 1 | pass_prob=0.5250 | kl=0.00000
step= 5 | pass_prob=0.6218 | kl=0.02050
step=10 | pass_prob=0.7284 | kl=0.11546
clip grads [0, 0, 1, -1]: [0.0, 0.0, 1.0, -1.0]| Dimension | PPO | GRPO |
|---|---|---|
| Baseline value | Learned critic network | Group mean reward over rollouts |
| Extra model state | Critic parameters, optimizer states, activations | No critic network; rollout buffer still required |
| Primary failure mode | Critic value drift | Zero-variance groups yield zero reward advantage |
| Best fit | Dense or sparse rewards with small batch sizes | Verifiable tasks where rollouts are cheap to grade |
Note also that trainer class names (such as TRL's GRPOTrainer) hide critical objective choices: always log the exact loss reduction (per-response mean vs. global active-token mean, which eliminates length bias across uneven responses), clipping thresholds, advantage normalization, and KL differentiation convention alongside benchmark numbers.[16]
RLVR training systems: rollouts, masks, and async weight sync
Scaling RLVR to multi-turn coding, SQL, and tool-use agents exposes four systems failure modes that corrupt training even when verifier and GRPO math are exact.[17]

Token-in-token-out (TI-TO) rollouts
Never decode sampled token IDs to chat text and re-tokenize them in the trainer. BPE tokenizers are not round-trip injective across turn edges, so re-tokenizing shifts merges and makes the trainer evaluate on different token IDs than the sampler emitted. Token-in-token-out (TI-TO) carries raw sampled response_ids and behavior logprobs directly from inference to trainer, appending tokenized observations as integer IDs.[18]
Observation loss_masks in multi-turn trajectories
In multi-turn trajectories, model actions ([11, 12]) interleave with sandbox observations ([90]) and repair actions ([21, 22]). Observation 90 must remain in context for downstream attention, yet must carry loss_mask = 0 so policy gradients and KL penalties apply only to model-generated action tokens (loss_mask = 1). Unmasked environment stdout trains the policy to predict tool errors and corrupts importance ratios.
Async rollout staleness and off-policy correction
Synchronous RL stalls the cluster behind slow sandboxes or long traces. Asynchronous RL (AReaL,[19] SkyRL[20]) overlaps persistent rollout workers with trainer updates under an aggregate staleness budget. With lag , mini-batch , and max_staleness_steps , the controller enforces at step :
Since groups are already consumed, at most groups sit buffered or in flight simultaneously (individual stragglers can still finish with lag , so monitor the full lag histogram alongside filtered zero-variance groups).[21] Keep the original sampling behavior logprobs as and pair PPO clipping with truncated importance sampling; even at zero lag, FSDP trainer kernels and vLLM inference kernels (or MoE routing) drift slightly without behavior logprobs.[22]
import numpy as np
masks = np.array([1, 1, 0, 1, 1], dtype=bool)
lp = np.array([-0.2, -0.4, 0.0, -0.6, -0.8], dtype=np.float32)
def masked_nll(x, m): return float(-np.mean(x[m]))
obs_mut, act_mut = lp.copy(), lp.copy()
obs_mut[2], act_mut[4] = -99.0, -1.2
print(f"nll: base={masked_nll(lp, masks):.2f} | obs_mut={masked_nll(obs_mut, masks):.2f} | act_mut={masked_nll(act_mut, masks):.2f}")
B, S = 1, 2
for step, grp, started, acc, run in [(1,"A",1,2,1), (2,"B",1,3,1), (3,"C",2,3,1), (4,"L",1,4,0)]:
out = acc - (step - 1) * B + run
assert acc + run <= (S + step) * B and out <= B * (S + 1)
print(f"step={step} group={grp} lag={step - started} outstanding={out}")nll: base=0.50 | obs_mut=0.50 | act_mut=0.60
step=1 group=A lag=0 outstanding=3
step=2 group=B lag=1 outstanding=3
step=3 group=C lag=1 outstanding=2
step=4 group=L lag=3 outstanding=1Actor-to-inference weight synchronization
After each optimizer step, updated weights must reach inference replicas cleanly:[23]
| Sync transport | Mechanism | Tradeoff |
|---|---|---|
| NCCL broadcast / RDMA | Pause disaggregated vLLM replicas; broadcast tensors over GPU links | Fastest step sync at scale; requires coordinated pause/finish handshake |
| CUDA IPC handles | Colocated trainer/sampler share GPU memory (/sleep, /wake_up) | Zero network copy; couples rollout and train GPU counts |
| Shared disk / object store | Trainer saves files; replicas reload from storage | Simple isolation, but disk I/O stalls frequent RL steps |
Safe sync pauses generation (preserving in-flight KV if resuming paused turns, while salting prefix-cache keys by policy version so stale KV blocks never leak across versions),[20] broadcasts weights, verifies every replica finished its handshake and reports the target version (quarantining stragglers), and only then resumes. Keep ephemeral sampler sync separate from durable training checkpoints (which persist optimizer moments, LR schedulers, and prompt cursors).
DeepSeek-R1 pipeline, reward hacking, and distillation
Multi-stage reasoning pipeline and emergent behaviors
DeepSeek-R1-Zero applied pure GRPO with accuracy and format rewards directly to DeepSeek-V3-Base, rising from 15.6% to 71.0% pass@1 on AIME 2024 (86.7% with 64-sample majority voting; 77.9% in the expanded report), proving strong reasoning emerges without human demonstrations, though traces mixed languages and hurt readability.[5][2] DeepSeek-R1 resolved those issues across four stages:
- Cold-start SFT: Fine-tune DeepSeek-V3-Base on several thousand curated, readable reasoning traces so RL begins from clean formatting in the target language.
- Reasoning RL (GRPO): Scale verifiable math, coding, science, and logic RL with an accuracy reward plus a language-consistency reward.
- Rejection sampling + SFT: Filter roughly 600k verified reasoning traces plus 200k general non-reasoning samples and fine-tune the base model from scratch on all 800k examples.
- Final RL: Combine rule-based reasoning rewards with preference reward models (grading helpfulness and harmlessness) to balance reasoning and general assistant utility.
Under terminal verifiable rewards, models spontaneously lengthen chains of thought and exhibit self-verification, backtracking, and extended test-time compute. Still, always run controlled baselines and track pass@1 / pass@k: Shao et al. found that on Qwen2.5-Math-7B even random rewards raised MATH-500 by 21.4 points (vs 29.1 for ground truth), whereas Llama 3 and OLMo 2 saw weak or negative gains, showing how strongly pretraining priors interact with RLVR clipping.[24]
Reward hacking and degenerate failure modes
Adversarially test every parser and reward weight before burning GPU hours. Giving independent credit to formatting tags teaches spotless wrong answers: watch a broken reward function that pays 0.7 for any \boxed{...} integer outrank a plain-text correct answer (0.3), while a correctness-first rule scores the wrong box 0.0:
import re
def boxed_int(text: str) -> int | None:
if text.count(r"\boxed") != 1:
return None
m = re.findall(r"\\boxed\{([0-9]{1,20})\}", text)
return int(m[0]) if len(m) == 1 else None
def broken_reward(text: str, expected: int) -> float:
return 0.7 if boxed_int(text) is not None else (0.3 if str(expected) in text else 0.0)
def strict_reward(text: str, expected: int) -> float:
return 1.0 if boxed_int(text) == expected else 0.0
wrong_boxed, right_plain = r"The answer is \boxed{148}.", "The answer is 168."
print(f"broken_prefers_wrong={broken_reward(wrong_boxed, 168) > broken_reward(right_plain, 168)} | strict_wrong={strict_reward(wrong_boxed, 168)}")broken_prefers_wrong=True | strict_wrong=0.0
Harden your RLVR pipeline against four recurring failure modes:
- Format gaming and trailing loopholes: Enforce single-box extraction, keep format credit strictly subordinate to correctness, and validate full structure (for example, checking total line count on a 3-bullet rule rather than
sum(line.startswith("- ")) == 3). - Held-out generalization checks: Hold fresh test suites out of optimization prompts so lookup-table memorization is caught immediately.
- Truncation cliffs: Monitor truncation rates and evaluate soft overlong penalties near the context cap so long traces finish cleanly instead of cutting off before the final answer.[15]
- General capability drift: Heavy reasoning RL can erode instruction following or inflate unnecessary refusals; evaluate reasoning, instruction adherence, and refusal slices side by side before promoting a checkpoint.
RLVR and distillation work in sequence
RLVR discovers high-reward reasoning trajectories through online exploration; distillation transfers filtered teacher traces into smaller, cheaper students via SFT without running online RL on the student:
| Dimension | RLVR | Distillation |
|---|---|---|
| Supervision origin | Executable checks on the policy's own rollouts | Filtered teacher traces or teacher logits |
| Optimization objective | Policy gradient (GRPO / PPO) maximizing verifier score | Cross-entropy / KL matching teacher targets |
| Core dependency | Reliable verifiers, nonzero rollout variance, clean weight sync | Capable teacher and curated training mixture |
| Primary risk | Verifier loopholes, zero-variance collapse, off-policy drift | Inheriting teacher blind spots |
DeepSeek-R1 distilled ~800k curated samples into smaller Qwen and Llama students: distilled Qwen2.5-32B reached 72.6% pass@1 on AIME 2024 versus 47.0% for direct RLVR on the same 32B base model.[5] Use RLVR to push the frontier teacher, then distill into fast, low-cost students.