Chapter 32 of 40 · ~24 min read & lab+90 XP
Chapter 32 · Generative AI

Reasoning Models: GRPO, Verifiable Rewards (RLVR) & Test-Time Compute

How frontier reasoning models (o1/o3, DeepSeek-R1, Gemini Thinking) work under the hood: Critic-free GRPO group-relative advantage, Reinforcement Learning with Verifiable Rewards (RLVR), emergent self-correction, and Test-Time Compute scaling.

What Is It?

GRPO (Group Relative Policy Optimization) samples a group of G reasoning rollouts per prompt, scores them with objective verifiable rewards (unit tests / math answers), and reinforces above-average traces without a critic network.

Why Is It Required?

Verifiable RL + Test-Time Compute unlocked self-verifying reasoning models (DeepSeek-R1, o1/o3) that think longer on hard coding and math tasks to solve problems SFT alone cannot.

Everyday Analogy: Having a student try 8 approaches to a math olympiad problem, grading each with an answer checker, and reinforcing the habits that beat their own average.
Why ML Engineers & Data Scientists Actually Need This

GRPO + Verifiable Rewards (RLVR) is the breakthrough behind DeepSeek-R1, OpenAI o1/o3, and Gemini Thinking — unlocking emergent self-verification and AIME/IOI-level reasoning!

ML / AI Engineer

Because GRPO drops the giant Critic network and replaces learned Reward Models with exact code/math verifiers (pytest, SymPy, regex), even small research teams can now train reasoning models!

Data Scientist

Understanding Test-Time Compute explains why spending 5× more inference tokens on a smaller thinking model can outperform a 10× larger non-thinking model on hard coding and math!

Interview & Debug Edge

Hottest 2025–2026 frontier AI interview question: 'How does DeepSeek-R1's GRPO eliminate PPO's Critic network, and why does RLVR trigger emergent backtracking without human CoT labels?'

Step 0 · Test Your Gut Before Any Math!

In GRPO (Group Relative Policy Optimization), how do we compute the Advantage A_i of rollout o_i WITHOUT training a separate 70B Critic/Value network?

What You Will Master in This Chapter
  • Derive GRPO's Critic-free group-relative advantage A_i = (r_i − mean(r)) / std(r) across G sampled rollouts
  • Explain why GRPO cuts RL VRAM nearly in half compared to PPO while excelling on long reasoning chains
  • Contrast noisy human-preference Reward Models with deterministic Verifiable Rewards (RLVR: unit tests, SymPy math verifiers)
  • Explain Test-Time Compute scaling (longer thinking traces, Best-of-N verification & Process Reward Models) as the 3rd LLM scaling axis
Plain-English Symbol Decoder · Click Any Symbol Before We Begin
1 / 3
Ai=ri−mean(r)std(r)+εA_i = \frac{r_i - \text{mean}(\mathbf{r})}{\text{std}(\mathbf{r}) + \varepsilon}Say aloud:“GRPO group-relative advantage”
Plain-English Meaning
Standardized reward of rollout i relative to the other G−1 rollouts on the same prompt
Everyday Example
Pass=1, Fail=0 in 2/4 pass → +1.0 / −1.0
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Imagine a math coach who doesn't grade your handwriting style — they just ask you to try 8 different scratchpad attempts on a tough olympiad problem, check which attempts get the exact right answer (RLVR), and say: 'Do more of whatever thinking habits showed up in your winning attempts, and less of the ones in your failing attempts!' (GRPO). Over thousands of problems, the model discovers on its own that pausing, checking edge cases, and backtracking wins far more often!

1. GRPO: Deleting the Critic Network via Group Z-Scoring

Everyday Story First (Zero Math Yet!)

Click 0/4 through 4/4 Pass in the mini-lab below to compute live GRPO group advantages — and notice what happens when a prompt is too easy (4/4) or too hard (0/4)!

GRPO (Group Relative Policy Optimization): Drop the Critic Network Completely!Prompt qRollout o₁ → r = 1.0 → A₁ = +1.0 ✓Rollout o₂ → r = 0.0 → A₂ = −1.0 ✗Rollout o₃ → r = 1.0 → A₃ = +1.0 ✓A_i = (r_i − mean(r)) / std(r) — ZERO Critic LLM needed!
DeepSeek's GRPO drops the expensive Critic network completely: it samples a group of G rollouts for the same prompt and computes each rollout's advantage relative to the group mean & std!

The GRPO Objective (Shao et al. / DeepSeekMath / DeepSeek-R1)

For each prompt qq, sample a group of GG rollouts {o1,…,oG}∼πold(⋅∣q)\{o_1, \dots, o_G\} \sim \pi_{\text{old}}(\cdot|q), score each with reward rir_i, and compute: Ai=ri−mean({r1..rG})std({r1..rG})+εA_i = \frac{r_i - \text{mean}(\{r_1..r_G\})}{\text{std}(\{r_1..r_G\}) + \varepsilon} Then optimize the PPO-clipped surrogate loss + direct KL penalty to πref\pi_{\text{ref}} — with ZERO Critic model in memory!

Formula Anatomy · Click Any Colored Piece to Decode It
Anatomy of GRPO Group-Relative Advantage

A_i = (r_i − μ_group) / (σ_group + ε)

Zero-Parameter Baseline

Replaces the 70B learned Value/Critic network with the empirical mean of G rollouts!

In our example: Saves ~50% RL training VRAM!
Put it together with real numbers: If 1 out of 4 rollouts passes ([1, 0, 0, 0]), mean = 0.25, std = 0.433 → the rare winning trace gets a huge +1.73 boost while the 3 failures get −0.58!
Animated Mini-Lab • 5.5

GRPO Group Advantage Calculator (G = 4 Rollouts)

r=1
A=+1.00
r=1
A=+1.00
r=0
A=-1.00
r=0
A=-1.00

2. RLVR & Emergent 'Aha!' Self-Correction

Everyday Story First (Zero Math Yet!)

Why did DeepSeek-R1-Zero avoid Reward Hacking even during massive pure-RL runs?

RLVR (Verifiable Rewards): Unhackable Ground-Truth Math & Code Grading1. Think & Solve<think> wait, let me re-check step 2... </think>2. Deterministic Verifierpytest / SymPy exact check → r ∈ {0, 1}3. Emergent 'Aha!' MomentModel learns self-verification & backtracking!
Reinforcement Learning with Verifiable Rewards (RLVR) grades math answers and unit-tested code deterministically (reward = 1 or 0) — immune to Reward Hacking and fueling emergent self-correction!

Unhackable Verifiers Fuel Genuine Reasoning

Unlike neural Reward Models (which can be tricked by polite formatting or fluff), a Python pytest suite or SymPy math checker cannot be charmed: either the code passes all hidden tests (r = 1) or it fails (r = 0). Plus a simple Format Reward enforces <think>...</think> separation from the final answer — and out emerges spontaneous verification, backtracking, and longer thinking on harder problems!

3. Test-Time Compute Scaling: The 3rd Scaling Axis

Everyday Story First (Zero Math Yet!)

Pre-training scaling (Module 2.5) hits the internet Data Wall — Test-Time Compute unlocks a whole new log-linear accuracy curve at inference time!

The New Scaling Axis: Test-Time Compute (Thinking Tokens & Best-of-N)200 tok (35%)4K thinking tok (68%)32K thinking tok (86% ★)Log-scale Test-Time Compute → smooth accuracy climb on AIME, IOI & SWE-bench!
Modern reasoning models (o1/o3, DeepSeek-R1, Gemini Thinking) add a 3rd scaling axis: allocating more Test-Time Compute (longer thinking chains & verification) smoothly boosts hard benchmark accuracy!

Two Complementary Ways to Spend Test-Time Compute

  1. Sequential Test-Time Scaling: Letting a reasoning model generate longer internal <think> chains (2K → 16K → 32K tokens) to backtrack and verify steps.
  2. Parallel Test-Time Scaling (Best-of-N / Majority Vote): Generating NN independent solutions in parallel and picking the winner via a unit-test verifier, Process Reward Model (PRM), or consensus vote!
Walk Through With Me · Interactive Worked Example

Worked Example: Why 0/G and G/G Prompts Yield Zero GRPO Gradient

Prompt A is trivial (rewards = [1, 1, 1, 1]). Prompt B is medium (rewards = [1, 0, 1, 0]).

11. Prompt A (`[1, 1, 1, 1]`)Step 1 / 2

mean = 1.0 → every r_i - mean = 0.0 → A_i = 0 for all 4 rollouts!

Teacher's Note: Zero learning signal — modern pipelines (DAPO) filter these out dynamically!
Pause & Check · Quick Intuition Pulse

What happens to GRPO advantages A_i when ALL G rollouts for a prompt fail (r_i = 0 for all i)?

Try It YourselfStandard

Why did DeepSeek-R1 add a tiny Cold-Start SFT phase (a few thousand clean <think> examples) before GRPO, improving on pure-RL DeepSeek-R1-Zero?

“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

Yes — anywhere you can write a deterministic or rubric-verifiable checker: SQL execution equivalence, JSON schema + constraint satisfaction, formal theorem provers (Lean 4), and unit-tested multi-file software patches!

Interactive Visual Lab
Lab Challenge: Watch the 60 FPS GRPO Rollout Studio sample G=4 rollouts, verify exact answers, and compute group advantages.
Interactive Animation • 5.5 Deep Lab

GRPO Group-Advantage Rollout & Verifiable Reward (RLVR) Studio

Watch GRPO sample G = 4 reasoning traces, grade them deterministically, and compute Critic-free group advantages.

Phase 1 / 3
o₁: "391"
o₂: "381"
o₃: "391"
o₄: "391"
0%
Sample G=4 Rollouts
Intuition Takeaway: GRPO deletes PPO's giant Critic network via group z-scoring (Ai=(ri−μ)/σA_i = (r_i - \mu)/\sigma), RLVR provides unhackable math/code verification rewards, and Test-Time Compute scales reasoning accuracy smoothly with thinking tokens.
Where This Powers Real ML, Deep Learning & Generative AI

Frontier Coding & Math Reasoning (o3, DeepSeek-R1, Gemini Thinking)

Combines Cold-Start SFT + GRPO on verifiable math/code/logic tasks + Test-Time Compute scaling.

Production NumPy & PyTorch Code Patterns
import torch

# Group Relative Policy Optimization (GRPO): Critic-free group-normalized advantages
def grpo_surrogate_loss(
    logp_new: torch.Tensor,
    logp_old: torch.Tensor,
    rewards: torch.Tensor,
    clip_eps: float = 0.2,
) -> torch.Tensor:
    # Normalize verifiable rewards within each sampled group of G completions
    adv = (rewards - rewards.mean()) / (rewards.std() + 1e-6)
    ratio = torch.exp(logp_new - logp_old)
    clipped = torch.clamp(ratio, 1.0 - clip_eps, 1.0 + clip_eps)
    return -torch.minimum(ratio * adv, clipped * adv).mean()

# Example: G=4 reasoning rollouts for one math prompt (2 correct, 2 wrong)
rewards = torch.tensor([1.0, 0.0, 1.0, 0.0])
loss = grpo_surrogate_loss(torch.tensor([-4.1, -5.2, -3.9, -4.8]), torch.tensor([-4.2, -5.1, -4.0, -4.7]), rewards)
print(f"GRPO policy loss: {loss.item():.4f}")
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Thinking GRPO is completely offline like DPO.
Best Practice: GRPO is online RL — it samples fresh rollouts from the live policy πθ\pi_\theta every step and grades them on-the-fly with verifiers!
Chapter Mastery Check (+90 XP)
Score: 0 / 1
1How does GRPO eliminate the need for a separate Critic (Value) neural network during Reinforcement Learning?

Apply What You Learned — Solve Matching Coding Problems