SPECULATIVE DECODING
A draft that guesses wrong costs more than it saves
Wrenpost runs an open model on its own GPUs to suggest replies to its support team, with a draft model distilled on English support replies. On developer questions full of curl and JSON, the draft agrees with the target 6% of the time (α = 0.06). The server drafts k = 4 tokens per round, and a draft pass costs a tenth of a target pass. Compared with plain decoding, generation is:
Plain decoding runs the large model once per token, and each run is bound by memory: it reads every weight, and the request’s KV cache, to produce one token (see Transformers, just enough). Speculative decoding has a small draft model propose k tokens, then runs the target once over all of them. Scoring k + 1 positions costs about the same as scoring one, because the weights are read once either way.
The target keeps drafts while they pass a test and stops at the first one that fails. Then it emits one token of its own from the same pass. A round always emits between 1 and k + 1 tokens. How many depends on one number: the acceptance rate α.
# vLLM-style config: a draft model and a fixed k, chosen on a chat benchmark
speculative_config = {
"model": "draft-distilled-on-support-replies",
"num_speculative_tokens": 4,
}
# Developer traffic: alpha ~ 0.06, so each round yields ~1.06 tokens
# and costs 1 + 4 * 0.1 = 1.4 target passes: 0.76x plain decoding.# Measure the acceptance rate on your own traffic (shadow run or the server's
# accepted/proposed counters), then choose k:
def choose_k(alpha, c, k_max=8):
best_k, best = 0, 1.0 # k = 0: speculation off
for k in range(1, k_max + 1):
tokens = k + 1 if alpha == 1 else (1 - alpha ** (k + 1)) / (1 - alpha)
s = tokens / (1 + k * c) # Leviathan et al., Theorem 3.8
if s > best:
best_k, best = k, s
return best_k
# Re-measure per traffic class; alpha below c means no k can win. Watch the first invariant. SPECULATE · SUPPORT REPLIES expects 2.35× plain. SPECULATE · CURL AND JSON turns red on the first step: the same draft, the same k, and fewer tokens per pass of time than plain decoding. FIX: MEASURE α, PICK k runs a shadow measurement first, finds α near 0.06, and turns speculation off on that traffic while keeping k = 6 on support replies. BROKEN VERIFY keeps the first invariant green and turns the second red: it is fast because it accepts every draft, and its output is the draft model’s.
Leviathan, Kalman and Matias (ICML 2023) define the acceptance rate β at one position as the chance a draft token is kept, and α as its average. Treating positions as independent, a round with k drafts emits
E(tokens per round) = (1 − αk+1) / (1 − α)
which is k + 1 when α = 1 and 1 when α = 0. With c the time of a draft pass divided by the time of a target pass, a round costs 1 + k·c, and the speed-up over plain decoding is E / (1 + k·c) (their Theorem 3.8). Two things follow. Each extra draft token adds c to every round but adds less and less to E, since it counts only if every token before it was accepted, so there is a best k. And if α ≤ c, no k helps (the converse of their Corollary 3.9): speculation should be off.
α is not a property of the draft alone. It depends on the target, the draft, the traffic, and the sampling settings. Leviathan et al. report α between 0.5 and 0.9 for drafts a couple of orders of magnitude smaller than the target, that “for all models, the sharper the adjusted distribution, the higher the α values” (argmax sampling against temperature 1), and α ≈ 0.2 even for a bigram model on English–German translation. Their drafts had c below 0.05; a larger draft, or a draft running on the same busy GPU, costs more.
On support replies the draft is good: α = 0.79. Find a k and a draft cost c at which this same well-matched draft still makes decoding slower than plain.
GOAL: expected speed below 1.00× plain on support replies
The test is rejection sampling. The draft proposes x with probability q(x); the target’s probability for it is p(x). Keep x with probability min(1, p(x)/q(x)). If you reject it, sample a replacement from norm(max(0, p − q)): only the tokens the draft under-proposed. The kept path gives min(p(x), q(x)), the replacement path gives the rest of p(x), and the sum is p(x) for every token. Chen et al. (2023) derived the same modified rejection sampling and used it to speed up a 70B model 2 to 2.5× in a distributed setup. The “emitted vs target p” row in the sim is that sum, computed exactly. vLLM’s documentation puts it as “theoretically lossless up to the precision limits of hardware numerics”, for its standard rejection sampler.
So the speed-up is safe and the slowdown is silent. A wrong draft never makes the answer worse; it makes it later.
Write chooseK(alpha, c, kMax). It returns an integer from 0 to kMax: the number of draft tokens per round that gives the highest expected speed, or 0 to turn speculation off. A round with k drafts yields (1 − αk+1) / (1 − α) tokens on average (k + 1 when α = 1) and costs 1 + k·c target passes of time; plain decoding (k = 0) is 1 token per pass. Return 0 when no k is faster than plain. Where two choices are equally fast, either is accepted. The grader tries α from 0 to 1, including α = 1, and c from 0.01 to 0.5.
What the sim simplifies. Each toy position draws from the same six-token table, so α is the same everywhere and the text reads as word salad; in a real model α varies token by token (boilerplate and closing brackets are easy, names and numbers hard), and the formula uses the average. A verify pass costs exactly one target pass here. That holds when decode is memory-bound, at small batches. At large batches the target’s arithmetic is no longer free: Liu et al. (2026) measured speculative decoding in vLLM at realistic batch sizes and found verification by the target takes most of the execution time. Measure the speed-up on your own serving load, not only α.
In practice you read α off the server: vLLM logs the draft acceptance rate with the accepted and drafted token counts (the Hook’s numbers come from that line), and its draft length is num_speculative_tokens. Measure it per kind of traffic (support chat, code, each language), set k per kind, and turn speculation off where α is below c.
Self-hosted serving with vLLM, SGLang, TensorRT-LLM or llama.cpp, where you configure a draft model, an EAGLE or Medusa head, or n-gram lookup and a draft length. Symptoms: tokens per second that improved on a chat benchmark and not in production, a draft acceptance rate far below the one you tuned on, and latency that got worse after a traffic mix changed (more code, a new language, a higher temperature).
“How does speculative decoding speed up generation without changing the output?” Explain draft-then-verify in one target pass, why a verify over k + 1 positions costs about one decode step (memory-bound decode), and the rejection-sampling rule that keeps the output distribution the target's. Then give the expected tokens per round, (1 − α^(k+1)) / (1 − α), divide by 1 + k·c, and say when it loses: low α, a costly draft, or large batches where the verify pass is no longer free.