Bring the mental model from Maximum Likelihood; this page will reuse it instead of restarting from zero.
Speculative Decoding: Lossless Multi-Token Generation
Draft several tokens with a fast model, score draft prefixes with the target model in parallel, then use modified rejection/residual sampling so the sampled distribution matches target-model decoding.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Autoregressive decoding is painfully sequential: one forward pass per token.
Speculative decoding gets around this by splitting work into two roles:
- a fast draft model proposes a chunk of k next tokens,
- the expensive target model scores the prompt plus each draft prefix in parallel.
In the full algorithm, the target produces k+1 next-token distributions: one for the current prefix, one after each draft prefix, and an extra distribution that can supply a new target token if every draft token is accepted. If draft tokens pass the target/draft probability-ratio checks, you accept a prefix of the draft and "skip ahead" in the sequence. If one fails, you reject at the first failed token and repair that position with a residual sample so the target distribution is preserved. The key promise is that this is lossless: the final distribution of generated text is exactly what you would have sampled from the target model alone.
So the win is systems-level: fewer expensive sequential target steps, same output distribution.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
Let qi be the draft distribution at position i and pi be the target distribution. This page follows Leviathan et al.'s notation where p is the target and q is the draft; Chen et al. use the opposite symbols. If the draft proposes token xi, the acceptance probability is:
If a proposed token is rejected, you sample from a residual distribution that corrects for what the draft already "used up":
This rejection/residual mechanism is what makes the method lossless: accepted tokens come from q but are filtered to match p, and rejected positions are repaired to restore the exact p distribution.
A rough intuition for speedup: if the draft is often right, you accept a long prefix of the k proposed tokens, and the target model advances several tokens per verification step.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
First check the one-token correction mechanism. Even though some samples come from the draft model, the accepted-or-repaired output should match the target distribution. Then simulate the accepted-prefix length that creates the latency upside.
import numpy as np
target_p = np.array([0.45, 0.30, 0.15, 0.10])
draft_q = np.array([0.30, 0.45, 0.20, 0.05])
rng = np.random.default_rng(0)
def residual_distribution(p, q):
repair_mass = np.maximum(0.0, p - q)
return repair_mass / repair_mass.sum()
def speculative_one_token(p, q):
draft = rng.choice(len(q), p=q)
accept_prob = min(1.0, p[draft] / q[draft])
if rng.random() < accept_prob:
return draft, True
repair = rng.choice(len(p), p=residual_distribution(p, q))
return repair, False
samples = np.zeros_like(target_p)
accepted = 0
for _ in range(200_000):
token, was_accepted = speculative_one_token(target_p, draft_q)
samples[token] += 1
accepted += int(was_accepted)
print("target distribution: ", np.round(target_p, 3))
print("speculative samples: ", np.round(samples / samples.sum(), 3))
print("draft-token acceptance:", round(accepted / samples.sum(), 3))
def expected_accepted(alpha, k):
# Expected length of consecutive acceptances (prefix), capped at k.
if alpha == 1.0:
return float(k)
return alpha * (1.0 - alpha**k) / (1.0 - alpha)
def simulate(alpha, k, trials=50000, seed=0):
rng = np.random.RandomState(seed)
total = 0
for _ in range(trials):
a = 0
for _ in range(k):
if rng.rand() < alpha:
a += 1
else:
break
total += a
return total / trials
for alpha in [0.3, 0.6, 0.85]:
for k in [2, 4, 8]:
theo = expected_accepted(alpha, k)
mc = simulate(alpha, k)
print(f"alpha={alpha:.2f} k={k:>2} E[accepted] theo={theo:.3f} mc={mc:.3f}")
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Live Concept Demo
Explore Speculative Decoding: Lossless Multi-Token Generation
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Choose what to inspect in Speculative Decoding: Lossless Multi-Token Generation. This shared fallback is an observation guide, not evidence of learning.
Use the demo to see how acceptance probability, draft length, and distribution mismatch affect expected speedup, and why verification is "free" only if your target model can score the chunk efficiently.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
Concept: Speculative Decoding: Lossless Multi-Token Generation
What is the smallest example that makes Speculative Decoding: Lossless Multi-Token Generation click without losing the math?
Object contextLLM Systems
concept:llm-systems/speculative-decodingSpeculative Decoding: Lossless Multi-Token Generation
What is the smallest example that makes Speculative Decoding: Lossless Multi-Token Generation click without losing the math?
Start with the prediction checkpoint, then compare the reveal to the mental model.
Take this moveStudy modes
Keep the object fixed; change the lens.Route back through the notebook
Carry the same object through intuition, math, code, and demo.
Draft several tokens with a fast model, score draft prefixes with the target model in parallel, then use modified rejection/residual sampling so the sampled distribution matches target-model decoding.
The next edge should feel earned: use the demo prediction here before following Long Context Engineering: RoPE Scaling, KV Compression & Memory Optimization.
After The First Pass
Turn the concept into an inspected object.
The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.Mechanism Storyboard
See the idea move before the page explains it
Draft several tokens with a fast model, score draft prefixes with the target model in parallel, then use modified rejection/residual sampling so the sampled distribution matches target-model decoding.

Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change Speculative Decoding: Lossless Multi-Token Generation should make visible.
Visual Inquiry
Make the image answer a mathematical question
Draft several tokens with a fast model, score draft prefixes with the target model in parallel, then use modified rejection/residual sampling so the sampled distribution matches target-model decoding.
Which visible object should carry the first intuition?
Pick the cue that should make Speculative Decoding: Lossless Multi-Token Generation easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
What is the smallest example that makes Speculative Decoding: Lossless Multi-Token Generation click without losing the math?
concept:llm-systems/speculative-decodingsources: leviathan-2022-speculative-decoding, chen-2023-speculative-sampling
Open the closest source note before trusting the local explanation.
2 selected-object sources shown first; 2 references total.
Audit the claim boundary, then ask from the same selected object.
Introduces speculative decoding as parallel draft-prefix scoring with modified rejection/residual sampling that preserves the target distribution.
Leviathan defines gamma draft tokens from a faster approximation model, parallel target scoring of draft prefixes, accept/reject filtering, residual sampling from norm(max(0, p - q)), and...
Checks lossless sampling under standardized sampling distributions; Chen qualifies the guarantee as within hardware numerics. Not a universal latency guarantee. Code is a toy finite-distr...
Independently grounds K-token drafts, parallel target scoring, modified rejection sampling, residual repair, and measured large-model decoding speedups.
Leviathan defines gamma draft tokens from a faster approximation model, parallel target scoring of draft prefixes, accept/reject filtering, residual sampling from norm(max(0, p - q)), and...
Checks lossless sampling under standardized sampling distributions; Chen qualifies the guarantee as within hardware numerics. Not a universal latency guarantee. Code is a toy finite-distr...
Claim Review
Draft several tokens with a fast model, score draft prefixes with the target model in parallel, then use modified rejection/residual sampling so the sampled distribution matches target-model decoding.
What is the smallest example that makes Speculative Decoding: Lossless Multi-Token Generation click without losing the math?
concept:llm-systems/speculative-decodingsources: leviathan-2022-speculative-decoding, chen-2023-speculative-sampling
Treat every claim as provisional until source support and a local witness agree.
1 structured claim check on this concept.
Run the prediction or practice transfer before asking for a grounded review.
Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 2 references and 3 local witnesses are available for inspection.
Leviathan defines gamma draft tokens from a faster approximation model, parallel target scoring of draft prefixes, accept/reject filtering, residual sampling from norm(max(0, p - q)), and proves target-distr...
Checks lossless sampling under standardized sampling distributions; Chen qualifies the guarantee as within hardware numerics. Not a universal latency guarantee. Code is a toy finite-distribution/residual che...
Leviathan 2022 supports gamma-token drafting, parallel target scoring of draft prefixes, accept/reject filtering, residual sampling from norm(max(0, p - q)), and a proof of target-distribution sampling. Chen 2023 independently supports K-token drafts, parallel scoring, modified rejection/residual sampling, and hardware-numerics-qualified preservation, with reversed p/q notation. Page math follows Leviathan; code is a toy residual/distribution plus prefix check, and demo is toy speedup only.
Reviewer: codex+oracle; reviewed 2026-05-07Practice notebook
Use the idea, then test it somewhere new
Draft several tokens with a fast model, score draft prefixes with the target model in parallel, then use modified rejection/residual sampling so the sampled distribution matches target-model decoding.
What is the smallest example that makes Speculative Decoding: Lossless Multi-Token Generation click without losing the math?
concept:llm-systems/speculative-decodingsources: leviathan-2022-speculative-decoding, chen-2023-speculative-sampling
Use one state from Speculative Decoding: Lossless Multi-Token Generation to explain what changes, why it changes, and which assumption the explanation needs.
No learner move yet; no learning state is inferred.
Write first, use only the help you need, then try a new case without it.
Use one state from Speculative Decoding: Lossless Multi-Token Generation to explain what changes, why it changes, and which assumption the explanation needs.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Write an attempt before asking the companion.
0 of 3 progressive hints opened.
This draft and any AI response do not establish mastery; a later unassisted case can.
- ObjectConceptSpeculative Decoding: Lossless Multi-Token Generation
- PredictBefore revealSpeculative Decoding: Lossless Multi-Token Generation prediction
- WitnessCompare codeSpeculative Decoding: Lossless Multi-Token Generation code witness 1
- RoomAsk groundedChecking local snapshot
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
Speculative Decoding: Lossless Multi-Token Generation
What is the smallest example that makes Speculative Decoding: Lossless Multi-Token Generation click without losing the math?
These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.
Source ids leviathan-2022-speculative-decoding, chen-2023-speculative-sampling must support the exact object, not just the surrounding topic.
Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.
Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.
The learner can state the mechanism in their own words
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:llm-systems/speculative-decoding.
- Source ids to inspect: leviathan-2022-speculative-decoding, chen-2023-speculative-sampling
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - Speculative Decoding: Lossless Multi-Token Generation Object key: concept:llm-systems/speculative-decoding Context: LLM Systems Anchor id: concept/concept-notebook/llm-systems/speculative-decoding Open question: What is the smallest example that makes Speculative Decoding: Lossless Multi-Token Generation click without losing the math? Evidence to inspect: - Source ids to inspect: leviathan-2022-speculative-decoding, chen-2023-speculative-sampling - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids leviathan-2022-speculative-decoding, chen-2023-speculative-sampling must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "Speculative Decoding: Lossless Multi-Token Generation" feel predictable rather than familiar." | assumption: Source ids leviathan-2022-speculative-decoding, chen-2023-speculative-sampling must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: leviathan-2022-speculative-decoding, chen-2023-speculative-sampling" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "Speculative Decoding: Lossless Multi-Token Generation" feel predictable rather than familiar. - Assumption to keep visible: Source ids leviathan-2022-speculative-decoding, chen-2023-speculative-sampling must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words
concept/concept-notebook/llm-systems/speculative-decoding
concept:llm-systems/speculative-decoding