Speculative decoding lab
Explore when a draft model helps—or hurts—under explicit acceptance and latency assumptions.
Study guide & lesson outline
LEARNING CONTRACTUnderstand → implement → investigate
Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.
- Understand: state assumptions, shapes/units and a counterexample.
- Implement: reproduce a numerical example and inspect boundaries.
- Investigate: compare one alternative under a matched budget.
01Configure
02Add your input
Choose settings, load an example, or paste your own input.
03Inspect results
Choose settings, load an example, or paste your own input.
The display may be truncated; the exported JSON report contains all computed results.
How to interpret this
Illustrative standard draft/verify cycle. Each round proposes γ tokens, accepts a prefix under an independent constant acceptance probability α, and emits that prefix plus one correction/bonus token. Round cost is γ × draft latency + one verification latency. The verifier cost is user-entered and may grow with γ in reality. No actual model runs; no claim about output quality. KV work, communication, batching and scheduling are excluded.
E[emitted] = 1 + α + … + α^γ. Speedup = E[emitted] × baseline latency / (γ × draft latency + verification latency). A speedup below 1 means slower than the entered baseline.
Method references
Assumptions, implementation & acceptance
Expected emissions 1+α+…+α^γ assume independent identical acceptance and a fixed verifier latency. This latency simulator is distinct from exact rejection-sampling correctness.
Reviewed counting units, statistical assumptions and numerical examples. Provider accounting and actual GPU allocation still require external measurement.
Before running: predict a boundary case
Expected emissions 1+α+…+α^γ assume independent identical acceptance and a fixed verifier latency. This latency simulator is distinct from exact rejection-sampling correctness.
Hint: isolate the assumption
Keep the baseline input fixed, change one parameter or boundary, and compare both the numerical result and the claimed units. A passing example verifies this fixture only.
Minimal executable example
Save the example and linked modules in one folder. Use Node.js 22 or newer, then run node speculative-decoding.mjs. npm install gpt-tokenizer@4.1.0
import {encode as rawEncode} from 'gpt-tokenizer/encoding/cl100k_base';
import {promptDiff,inspectDataset,chunkDocument,compareScores,estimateVRAM,samplingLab,speculativeLab} from './research-core.mjs';
const encode=s=>rawEncode(s,{disallowedSpecial:new Set()});
const result=speculativeLab(4,1,3,40,30,100,42);
console.log(result.expected,result.observed); // 5 5, under independent acceptance modelTest and transfer
Expected emissions 1+α+…+α^γ assume independent identical acceptance and a fixed verifier latency. This latency simulator is distinct from exact rejection-sampling correctness.
Record input, code version, expected result and observed result in the notebook below. Then construct a counterexample that violates the assumption above and explain why the original conclusion no longer follows.
Download complete kit (.tar.gz) · Complete reference kit and regression checksPredict, test and keep evidence
Before revealing an answer, predict one result. After the exercise, record the discrepancy and a transfer test. Saved locally across language editions.
Open notebook / export / clear →The mathematical review scope is recorded per lesson. It does not establish empirical paper reproduction; report suspected errors in your notes. Review scope