speculative-decoding -- draft k tokens, verify them in one pass

Writing one word at a time barely uses a graphics card. The machine has to haul the whole model out of memory for each word, and there is almost nothing for it to calculate while it waits. Speculation fills that idle capacity: a small, fast model writes a guess at the next few words, and the big model checks them all in a single pass, which costs it barely more than producing one word would have. Words the big model agrees with are kept and were effectively free; at the first disagreement it writes its own word and the rest of the guess is thrown away. Guess badly, or use a helper that is not cheap enough, and you have paid for the guessing and gained nothing.

Interactive page: how a small draft model buys tokens from a big target model without changing what the big model would have said. Anchor: the decode-time companion to prefill-vs-decode (which shows why one forward per token is the bottleneck) sampling (whose accept/reject test this one extends).

What it shows

Plain decode emits one token per forward pass of the big model, one after another -- and a single token is a skinny matrix-vector product, so the hardware spends most of its time waiting on memory rather than doing math. Speculation spends that idle width instead:

So a round always yields at least 1 and at most k+1 tokens. Accepted proposals are green, the rejected one is red, and the tail after it is struck through and thrown away untested -- that discarded draft compute is the price of the trade.

The economics panel is the point of the page: mean accepted length per round is everything. It shows tokens produced, target forwards spent, and the resulting tokens per target forward against the baseline of 1.00 (plain decode), plus the net rate once each drafted token is charged a fraction of a target forward. Drag the agreement down and the cost up and the verdict flips to SLOWER than not speculating -- a bad draft is worse than no draft.

Drag the draft-agreement and draft-cost handles on the canvas; the counters, accepted lengths and verdict move under your hand. Hover any proposal for its draft probability q, its target probability p, the ratio, and the exact comparison that decided it. The run is generated from a seeded generator, so one URL replays one exact run.

Interactions

#Contract itemHere
1scrub / steptransport steps the four phases of a round (propose · verify · accept test · commit), autoplays and loops; ?step=N
2hover-to-inspectany proposal chip → q, p, p/q, the drawn uniform, the verdict and why; the discarded tail says it was never tested
3direct manipulationcanvas handles for draft agreement and draft cost, with the accepted lengths and the tokens-per-forward counter live under the drag
4live animationthe verify phase sweeps the one-forward bracket across all k+1 positions each frame
5resize the problemk (draft length) and rounds steppers

A/B compare renders a weak draft (agreement 0.25) against a strong one (0.95). Challenge mode asks for >2.00 tokens per target forward, and then for a configuration where speculation actually loses.

Render tier

T1 (Canvas2D token chips, probability bars, and the tokens-per-forward gauge; no heatmap needed).

Wiring

layout.mount + controls (k, quality, cost, rounds, seed) transport over rounds × 4 phase records (autoplay, loop) + animate (the verify sweep via api.t) + onPointer handle drags (routed through controls.set, committed non-silently on release so the deep link syncs) hover. URL hooks: ?step, ?k, ?quality, ?cost, ?rounds, ?seed, ?hover=x,y, ?play=1. All randomness comes from tensor.js rng(seed) / seededRandn(seed,...), so a given URL reproduces the same run exactly. Source: page.js.