Book a 30-min callBook a call

Speculative decoding explained: drafting tokens cheaply and verifying them exactly

How speculative decoding works: draft then verify, the rejection rule that keeps outputs exact, acceptance rates, Medusa, EAGLE, n-gram drafts and batching.

A small box emitting a row of four token squares toward a large box, which marks the first three with check circles and the fourth with a cross, then appends one new square of its own.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
19 min read

Questions people ask

Does speculative decoding change the model's outputs?

With the standard rejection sampling rule, no: the output follows the target model's distribution exactly, and with greedy decoding it is the same text the target would produce alone. In practice, floating-point differences between batch shapes can flip a token in rare close cases. Some variants, such as Medusa's typical acceptance or a relaxed verification mode in a serving engine, trade exactness for speed on purpose, so check which one you are running.

How many draft tokens should be proposed per step?

It depends on the acceptance rate and on how much a drafter pass costs relative to a target pass. With a high acceptance rate and a cheap drafter, longer drafts pay; with a low acceptance rate, anything past a few tokens is wasted, and the expected gain can fall as the draft gets longer. Start with a small value, sweep it on real prompts at real load, and consider an engine feature that adapts it.

Can the draft model use a different tokenizer?

Not with the standard method. The acceptance rule compares the two models' probabilities for the same token, so they need the same vocabulary. Use a smaller model from the same family, train a draft head on the target as Medusa and EAGLE do, or use a method that needs no separate model, such as prompt lookup or self-speculative decoding.

Does speculative decoding work with temperature sampling?

Yes. The rejection rule exists precisely so that sampled outputs keep the target distribution. Acceptance is usually lower when sampling than with greedy decoding: Leviathan and colleagues measured higher acceptance rates and higher speedups at temperature zero than at temperature one, and the gap grows with more random sampling settings.

Why can speculative decoding slow down a busy server?

Its speedup comes from compute that sits idle during memory-bound decoding. A server running large batches has already used that compute, so verifying extra positions per sequence adds real work, and every rejected draft token is wasted. Serving engines therefore aim speculation at light and medium load, and some adjust or switch it off as load rises.

Building something like this?