VISUAL LESSON · 7 PICTURES

Verification, Search & Speculation: PRMs, MCTS, and Medusa

Why do Outcome Reward Models (ORMs) fail in multi-step reasoning, and how do Process Reward Models (PRMs) assign step-level credit?

Progress stays on this device · no login
BEFORE THE FIRST PICTURE

How this lesson unfolds.

Language models are transitioning from fast intuitive generators to deliberate reasoning agents. In this chapter, we master process verification, tree search, and inference acceleration.

Picture 1 of 7 · tap to inspect in full resolution
01

Why do Outcome Reward Models (ORMs) fail in multi-step reasoning, and how do Process Reward Models (PRMs) assign step-level credit?

INTUITION

Imagine grading a math exam where a student writes 5 lines of nonsense algebra but copies the correct final answer from their neighbor. An outcome judge gives 100%! A process judge inspects line 1, line 2, line 3, catching the mistake immediately on line 2. PRMs reward sound reasoning, not lucky guesses.

MATHEMATICAL STATEMENT
  1. $$r_{\text{PRM}}(y) = \prod_{t=1}^T P(\text{Valid}(s_t) \mid x, s_{<t})$$
  • Learning goalContrast Process Reward Models with Outcome Reward Models and calculate step-level probability product trajectories.
  • Helpful foundationsReward model architecture · Multi-step reasoning dynamics
  • Common trapAssuming final answer correctness proves reasoning validity; language models frequently stumble upon correct answers through compensatory errors.
  • Next connectionUse PRM step scores to drive Monte Carlo Tree Search (MCTS) in Screen 2.
✦ More context & mechanics
Conceptual Mechanics & Logic

In complex multi-step reasoning tasks:

  • Outcome Reward Model (ORM): Evaluates r(x, y_(final)).
  • Hazard: False positives (correct final answer reached via false arithmetic steps) and severe credit assignment sparsity (no guidance on which step failed).
  • Process Reward Model (PRM): Evaluates step-level transitions r_(step)(x, s₁, ṡ, s_t):

r_(PRM)(y) = ∏_(t=1)^T P(Step t is valid | x, s_(<t))

Key Advantages of PRMs:

  1. Precise Error Localization: Identifies the exact token or sentence where logic derailed.
  2. Early Pruning in Tree Search: Cuts off unpromising reasoning branches at step 2 rather than generating 500 wasted tokens.
  3. Alignment with Formal Proofs: Perfectly matches formal verification systems (Lean, Isabelle).
Concrete Numeric Walkthrough

A student attempts a 3-step proof:

  • Step 1 (Valid premises): PRM score p₁ = 0.98
  • Step 2 (Flawed algebraic leap): PRM score p₂ = 0.12
  • Step 3 (Lucky final answer): PRM score p₃ = 0.95

Comparison of Evaluation Methods:

  • ORM Verdict: Final answer is correct arrow Reward = 1.0 (False Positive Pass).
  • PRM Verdict:

Score = 0.98 × 0.12 × 0.95 = 0.1117 (Correctly Flagged as Defective)

The search harness halts generation immediately after Step 2, triggering backtracking and saving 66\% of downstream generation compute.

Real-World Usage

Foundation of modern reasoning models (OpenAI PRM800K, Qwen-Math, DeepSeek-R1).

History & Origin Story

Lightman et al. (OpenAI, 2023) published 'Let's Verify Step by Step', demonstrating that PRMs decisively outperform ORMs in mathematical reasoning.

How to Memorize & Golden Words

ORMs score the destination, PRMs score the journey: verify step by step, never reward a lucky lie.

Picture 2 of 7 · tap to inspect in full resolution
02

How does Monte Carlo Tree Search explore multi-step reasoning spaces using the Predictor Upper Confidence bound for Trees (PUCT)?

INTUITION

Imagine playing chess. You don't just pick the first move that looks good; you picture your move, then the opponent's reply, then your counter-move. MCTS explores possible thought paths like chess moves: testing the most promising ideas while occasionally checking surprising alternatives to find hidden breakthroughs.

MATHEMATICAL STATEMENT
  1. $$a^* = \arg\max_a \left( Q(s, a) + c_{\text{puct}} P(s, a) \frac{\sqrt{\sum_b N(s, b)}}{1 + N(s, a)} \right)$$
  • Learning goalCompute PUCT selection scores and execute MCTS selection, expansion, evaluation, and backpropagation phases.
  • Helpful foundationsProcess vs Outcome Verification · Multi-armed bandit algorithms
  • Common trapThinking MCTS replaces the language model; MCTS guides the language model policy to explore diverse branches methodically.
  • Next connectionAnalyze how step-by-step reasoning decays entropy in Screen 3.
✦ More context & mechanics
Conceptual Mechanics & Logic

MCTS operates across four cyclic phases:

  1. Selection: Traverse tree from root using PUCT action selection until reaching an unexpanded node.
  2. Expansion: Sample K candidate next steps from policy π_θ(s_(t+1) | s_t).
  3. Evaluation: Score the node using a Process Reward Model (PRM) or rollout policy.
  4. Backpropagation: Update visit counts N(s, a) and mean value estimates Q(s, a) back up to the root.

The PUCT Action Selection Formula:

a^* = argmax_a [ Q(s, a) + U(s, a) ]

U(s, a) = c_(puct) · P(s, a) · (√(∑_(b) N(s, b))) / (1 + N(s, a))

Where Q(s, a) is the exploitation term (mean PRM score), P(s, a) is the prior policy probability, and the denominator shrinks the exploration bonus as an action is visited more frequently.

Concrete Numeric Walkthrough

Let exploration constant c_(puct) = 2.0. Total parent visits N_(total) = 16 arrow √(N_(total)) = 4.0.

Consider two next-step reasoning thoughts:

  • Thought A (Heavily Explored):
  • Mean score: Q = 0.85, Prior probability: P = 0.60, Visits: N = 7.
  • Exploration term: U = 2.0 × 0.60 × (4.0) / (1 + 7) = 1.20 × (4.0) / (8) = 0.60.
  • PUCT Score: 0.85 + 0.60 = 1.45.
  • Thought B (Rarely Explored Diamond in the Rough):
  • Mean score: Q = 0.70, Prior probability: P = 0.40, Visits: N = 1.
  • Exploration term: U = 2.0 × 0.40 × (4.0) / (1 + 1) = 0.80 × (4.0) / (2) = 1.60.
  • PUCT Score: 0.70 + 1.60 = 2.30.

Verdict: The algorithm selects Thought B (2.30 > 1.45), choosing to explore the high-potential alternative path!

Real-World Usage

Core planning engine in AlphaGo, AlphaZero, OpenAI o1-style reasoning harnesses, and theorem-proving systems.

History & Origin Story

RocAlphaGo and AlphaZero (Silver et al., DeepMind 2016–2018) popularized PUCT, later adapted to language models by Yao et al. (Tree of Thoughts, 2023).

How to Memorize & Golden Words

Q exploits the known, U explores the new: balance prior odds with visit count to let the best thought through.

Picture 3 of 7 · tap to inspect in full resolution
03

How does generating intermediate reasoning tokens mechanically reduce downstream token entropy and unlock complex deduction?

INTUITION

Try multiplying 374 × 89 in your head in one second. It's almost impossible! But if you write down the intermediate steps: 374 × 9 = 3366 and 374 × 80 = 29920, then add them, it's easy. Generating scratchpad tokens spreads the hard math across multiple forward passes, turning a dizzying leap into easy baby steps.

MATHEMATICAL STATEMENT
  1. $$H(Y \mid X, z_1, \dots, z_K) \le H(Y \mid X)$$
  • Learning goalExplain how intermediate reasoning tokens expand computational depth and calculate Shannon entropy decay across reasoning steps.
  • Helpful foundationsShannon entropy definition · Autoregressive generation pipeline
  • Common trapAssuming chain-of-thought is just cosmetic formatting; generating tokens physically increases the total floating-point operations devoted to solving the task.
  • Next connectionAccelerate inference throughput using speculative decoding in Screen 4.
✦ More context & mechanics
Conceptual Mechanics & Logic

In standard single-shot generation, the model must map prompt x directly to final answer y:

P(y | x) = Softmax(W h_(L)(x))

Because a transformer has a constant depth L, the maximum computation allocated to derive y is strictly O(L) FLOPs.

Chain-of-Thought Compute Expansion:

By generating intermediate reasoning tokens z₁, z₂, ṡ, z_K:

P(y | x, z₁, ṡ, z_K) = ∏_(k=1)^K P(zₖ | x, z_(<k)) · P(y | x, z)

  1. Compute Scaling: Total compute expands from O(L) to O(K · L) FLOPs!
  2. Shannon Entropy Decay:

Let entropy H(Y) = -∑ P(y) ln P(y).

Without scratchpad: H(Y | X) ≫ 0 (high uncertainty, hallucinations).

With step-by-step grounding: H(Y | X, z₁, ṡ, z_K) → 0. Each token acts as an entropy sink, collapsing uncertainty before the final conclusion is drawn.

Concrete Numeric Walkthrough

A complex logic question has 4 possible answers with uniform initial uncertainty:

  • Direct Prediction (K=0):
  • Probabilities: [0.30, 0.25, 0.25, 0.20].
  • Shannon Entropy:

H₀ = -(0.30 ln 0.30 + 2 × 0.25 ln 0.25 + 0.20 ln 0.20) = 0.361 + 0.693 + 0.322 = 1.376 nats

  • Model has high entropy and guesses incorrectly.
  • After 3 Steps of CoT (K=30 tokens):
  • Step 1 eliminates options 3 & 4 arrow H₁ = 0.693 nats.
  • Step 2 verifies condition A arrow H₂ = 0.280 nats.
  • Step 3 completes deduction: probabilities become [0.98, 0.01, 0.005, 0.005].

H₃ = -(0.98 ln 0.98 + 0.01 ln 0.01 + 2 × 0.005 ln 0.005) = 0.0198 + 0.0461 + 0.0530 = 0.119 nats

Entropy decayed by 91.4\%, guaranteeing an accurate final token.

Real-World Usage

Standard prompting and alignment paradigm across all frontier reasoning systems (o1, R1, Claude 3.5 Sonnet).

History & Origin Story

Wei et al. (Google Research, 2022) published 'Chain-of-Thought Prompting Elicits Reasoning in Large Language Models'.

How to Memorize & Golden Words

Tokens are thinking time: write down the steps, collapse the entropy, reach the truth.

Picture 4 of 7 · tap to inspect in full resolution
04

How does speculative decoding achieve a 2x-3x inference speedup while preserving the exact probability distribution of the target model?

INTUITION

Imagine an executive and a speedy assistant. The assistant drafts a 5-sentence email in 2 seconds. The executive reads the entire draft in one glance: approving the first 3 sentences, crossing out sentence 4, and writing the correct sentence 4. Instead of the executive writing from scratch word by word, the draft saves 75% of their time—with zero drop in quality!

MATHEMATICAL STATEMENT
  1. $$\alpha = \min\left(1, \frac{P(x)}{Q(x)}\right), \quad P'(x) = \frac{\max(0, P(x) - Q(x))}{\sum_y \max(0, P(y) - Q(y))}$$
  • Learning goalFormulate the speculative decoding rejection sampling criterion and prove mathematical equivalence to target model sampling.
  • Helpful foundationsAutoregressive decoding · Rejection sampling fundamentals
  • Common trapBelieving speculative decoding changes the output quality; the modified rejection sampling guarantees exact mathematical equivalence to the target model.
  • Next connectionEliminate the separate draft model using Medusa multi-head speculation in Screen 5.
✦ More context & mechanics
Conceptual Mechanics & Logic

Autoregressive decoding is memory-bandwidth bound: each token requires loading all model weights from High Bandwidth Memory (HBM) into GPU SRAM.

The Speculative Protocol:

  1. Draft Phase: A small model (e.g. 124M) drafts K tokens sequentially: (x̃₁, ṡ, x̃_K).
  2. Parallel Verification: The large target model (e.g. 70B) processes all K tokens in a single forward pass, extracting true probabilities P(x) for all positions.
  3. Rejection Sampling Criterion:

For each token i ∈ [1, K], accept with probability:

αᵢ = min( 1, (P(xᵢ)) / (Q(xᵢ)) )

Where P(x) is the target model probability and Q(x) is the draft model probability.

  1. Correction on Rejection: If token j is rejected, sample from the adjusted difference distribution:

P'(x) = norm( max(0, P(x) - Q(x)) )

This recovery step guarantees that the final generated text matches the target model's exact probability distribution as if speculative decoding never occurred!

Concrete Numeric Walkthrough

A small draft model proposes token 'quantum' with draft probability Q = 0.40.

The large target model evaluates 'quantum' in its parallel forward pass:

  • Case 1 (Target Strongly Agrees): P = 0.60.
  • Acceptance probability: α = min(1, (0.60) / (0.40)) = min(1, 1.5) = 1.0 (100\% accept).
  • Case 2 (Target Skeptical): P = 0.20.
  • Acceptance probability: α = min(1, (0.20) / (0.40)) = 0.50 (50\% accept).
  • Average Tokens Per Step: With acceptance rate α = 0.80 and K=4, the system generates an average of (1 - α^(K+1)) / (1 - α) = (1 - 0.80⁵) / (1 - 0.80) = 3.36 tokens per large-model forward pass, delivering a 2.5× to 3.0× end-to-end speedup.
Real-World Usage

Standard acceleration engine in production inference servers (vLLM, Hugging Face TGI, TensorRT-LLM).

History & Origin Story

Leviathan et al. (Google Research, 2023) and Chen et al. (DeepMind, 2023) independently published speculative decoding.

How to Memorize & Golden Words

Draft fast with the small, verify once with the tall: accept with p over q, exact math guaranteed.

Picture 5 of 7 · tap to inspect in full resolution
05

How does Medusa achieve multi-token speculative acceleration without the memory and deployment complexity of a separate draft model?

INTUITION

In Greek mythology, Medusa had multiple serpent heads on a single body. In AI, instead of buying a second small dog (draft model) to scout ahead, we give the big dog multiple heads! Head 1 predicts token +1, Head 2 predicts token +2, and Head 3 predicts token +3 all at once from the same body.

MATHEMATICAL STATEMENT
  1. $$M_{i, j} = 0 \iff j \in \text{Ancestors}(i) \quad \text{else } -\infty$$
  • Learning goalArchitect Medusa non-autoregressive heads and construct tree attention masks for parallel candidate verification.
  • Helpful foundationsSpeculative Decoding Rejection Sampling · Attention masking mechanics
  • Common trapAssuming candidate trees require multiple sequential forward passes; tree attention verifies all combinatorial branches in a single forward pass.
  • Next connectionMaster memory bandwidth barriers, KV caching, and FlashAttention in Chapter 46.
✦ More context & mechanics
Conceptual Mechanics & Logic

Speculative decoding requires hosting two distinct models in VRAM, complicating load balancing.

The Medusa Architecture (Cai et al., 2024):

  1. Medusa Heads: Attach K lightweight MLP heads to the frozen base model's final hidden state h_t:

ŷ_(t+k) = MedusaHeadₖ(h_t) for k ∈ [1, K]

Each head predicts tokens at offset t+k non-autoregressively.

  1. Tree Attention Candidate Expansion: The top candidates from each head are Cartesian-product combined into a tree of candidates (e.g., 64 top paths).
  2. Tree Masked Verification: All candidates are evaluated in a single forward pass using custom attention masks that allow each branch to attend only to its ancestors:

M_(i, j) = 0 & if candidate j is an ancestor of candidate i \ -∞ & otherwise

The longest matching path is accepted, and weights update seamlessly.

Concrete Numeric Walkthrough

A model with 3 Medusa heads proposes top candidates:

  • Head 1 (offset +1): Top 2 candidates: `['is', 'was']`
  • Head 2 (offset +2): Top 2 candidates: `['a', 'the']`
  • Head 3 (offset +3): Top 1 candidate: `['great']`
  • Candidate Tree Size: 2 × 2 × 1 = 4 candidate paths:
  1. `['is', 'a', 'great']`
  2. `['is', 'the', 'great']`
  3. `['was', 'a', 'great']`
  4. `['was', 'the', 'great']`

All 4 branches are verified in a single forward pass using tree attention. The model accepts path 1 (`'is a great'`), producing 3 accepted tokens in 1 forward pass!

Real-World Usage

Integrated into high-throughput enterprise serving engines (vLLM, TensorRT-LLM, SGLang).

History & Origin Story

Tianle Cai et al. (Together AI & Princeton, 2024) introduced Medusa, eliminating auxiliary draft models.

How to Memorize & Golden Words

Multiple heads on one body, tree attention in one pass: Medusa accelerates decoding without a second model.

Picture 6 of 7 · tap to inspect in full resolution
06

How does Process vs. Outcome Reward Models (PRMs vs. ORMs) operate mathematically at scale?

INTUITION

A multi-step math solution trajectory:

  • Learning goalMaster the algebraic and geometric derivation of Process vs. Outcome Reward Models (PRMs vs. ORMs).
  • Helpful foundationsFoundations of Build Llm From Scratch · Coordinate Invariance & Geometric Projections · Radford et al. (2019), Language Models are Unsupervised Multitask Learners, OpenAI
  • Common trapAssuming Process vs. Outcome Reward Models (PRMs vs. ORMs) is an arbitrary computational trick rather than an invariant spatial law.
  • Next connectionConnects upstream foundational lemmas to modern high-dimensional computational systems.
✦ More context & mechanics
Conceptual Mechanics & Mathematical Rigor

A mathematical reasoning verification tree diagram in square 1:1 format on warm cream parchment (#fcf0db) with an 8px border.

Top section: Title in navy serif: "Outcome vs. Process Reward Models (ORMs vs. PRMs)". Subtitle: "Lightman et al. (OpenAI 2023): Granular step-level credit assignment for multi-step reasoning."

Middle section: A multi-step math solution trajectory:

Step 1: "2x + 6 = 14" ⟶ (Correct \checkmark)

Step 2: "2x = 8" ⟶ (Correct \checkmark)

Step 3: "x = 5" ⟶ (Arithmetic Error! ×)

Contrast two verifiers:

  • Outcome Reward Model (ORM): Evaluates only the final answer (x = 5 → Fail). Provides zero feedback on where the reasoning broke down! Prone to rewarding wrong paths that stumble upon the right answer.
  • Process Reward Model (PRM): Evaluates every single intermediate step independently:

Step 1: 0.99 \checkmark

Step 2: 0.98 \checkmark

Step 3: 0.02 × (Pinpoints exact error!).

Bottom section: Test-time compute: "PRMs power Best-of-N sampling and Monte Carlo Tree Search (MCTS), enabling models like OpenAI o1 to verify complex proofs."

Clear step-by-step verification markers, sharp error highlight, balanced square layout.

Invariance & Structural Proof

Every transformation preserves structural invariants while mapping coordinate spaces. When operating in high dimensions, numerical precision and computational efficiency require adhering strictly to canonical mathematical laws.

Canonical Literature Reference

Formal derivation and peer-reviewed analysis:

Radford et al. (2019), Language Models are Unsupervised Multitask Learners, OpenAI

Golden Axiom

"Process vs. Outcome Reward Models (PRMs vs. ORMs): Invariance, symmetry, and structure govern mathematical truth across continuous and discrete domains."

Picture 7 of 7 · tap to inspect in full resolution
07

How does Speculative Decoding: Drafting Fast, Verifying Parallel operate mathematically at scale?

INTUITION

Dual-lane execution timeline:

  • Learning goalMaster the algebraic and geometric derivation of Speculative Decoding: Drafting Fast, Verifying Parallel.
  • Helpful foundationsFoundations of Build Llm From Scratch · Coordinate Invariance & Geometric Projections · Radford et al. (2019), Language Models are Unsupervised Multitask Learners, OpenAI
  • Common trapAssuming Speculative Decoding: Drafting Fast, Verifying Parallel is an arbitrary computational trick rather than an invariant spatial law.
  • Next connectionConnects upstream foundational lemmas to modern high-dimensional computational systems.
✦ More context & mechanics
Conceptual Mechanics & Mathematical Rigor

An inference acceleration pipeline diagram in square 1:1 format on dark slate (#0f172a) with clean timing lanes.

Top section: Title in white sans-serif: "Speculative Decoding: Draft Fast, Verify in Parallel". Subtitle in muted cyan: "Leviathan et al. (2023): Accelerating large models using a small draft model with zero distribution shift."

Middle section: Dual-lane execution timeline:

Lane 1 (Draft Model - Small 1B SLM, Ultra-Fast):

Autoregressively generates K = 4 speculative tokens sequentially in 10ms:

[Token 1, Token 2, Token 3, Token 4].

Lane 2 (Target Model - Large 70B LLM, High-Latency):

Takes all K = 4 draft tokens at once in a SINGLE parallel forward pass (evaluating all 4 positions in 25ms):

  • Token 1: Accepted \checkmark
  • Token 2: Accepted \checkmark
  • Token 3: Rejected × (Target model samples corrected replacement Token 3*).

Result: Generated 3 verified tokens from the 70B model in the latency of a single forward pass!

Bottom section: Exact mathematical guarantee: "Modified rejection sampling guarantees that the output distribution is mathematically identical to sampling directly from the 70B model."

Crisp timing bars, clear accept/reject markers, high contrast dark theme.

Invariance & Structural Proof

Every transformation preserves structural invariants while mapping coordinate spaces. When operating in high dimensions, numerical precision and computational efficiency require adhering strictly to canonical mathematical laws.

Canonical Literature Reference

Formal derivation and peer-reviewed analysis:

Radford et al. (2019), Language Models are Unsupervised Multitask Learners, OpenAI

Golden Axiom

"Speculative Decoding: Drafting Fast, Verifying Parallel: Invariance, symmetry, and structure govern mathematical truth across continuous and discrete domains."