Inference Engineeringsimulator

Speculative decoding simulator

A large model generates one token per forward pass, and most of that pass is spent reading weights. Speculative decoding adds a small, fast draft model that guesses the next few tokens. The large model then checks all of the guesses in a single pass, which costs about the same as generating one token.

Faster than plain decoding

Each run yields 3.36 tokens for 1.2 target steps. The best γ here is 8, at 3.09×.

Speedup over plain decoding2.8×Expected, at γ = 4
0×1×2×3×2.557.510Draft tokens per run γSpeedup (×)Plain decoding (1×)γ = 4

Draft, target and runs

How often the target accepts one draft token. Leviathan et al. define it as the expected chance a draft token passes, and assume it is the same for every token.

How many tokens the draft model proposes before the target checks them.

Time of one draft step divided by time of one target step. 0.05 means the draft is 20 times faster.

The same seed gives the same accepted and rejected tokens.

Runs, one at a time

Each draft token is accepted with chance α. The run keeps the tokens before the first rejection, drops the rest, and the target always adds one more: a resampled token after a rejection, or a bonus token when all 4 were accepted.

  1. Run 1Draft proposes 4, target checks them in one pass, 2 kept, then the target adds 1 (resampled). +3 tokens.

    • d1 accepted
    • d2 accepted
    • d3 rejected
    • d4 discarded
    • resampled
  2. Run 2Draft proposes 4, target checks them in one pass, 4 kept, then the target adds 1 (bonus). +5 tokens.

    • d1 accepted
    • d2 accepted
    • d3 accepted
    • d4 accepted
    • bonus
  3. Run 3Draft proposes 4, target checks them in one pass, 4 kept, then the target adds 1 (bonus). +5 tokens.

    • d1 accepted
    • d2 accepted
    • d3 accepted
    • d4 accepted
    • bonus
  4. Run 4Draft proposes 4, target checks them in one pass, 4 kept, then the target adds 1 (bonus). +5 tokens.

    • d1 accepted
    • d2 accepted
    • d3 accepted
    • d4 accepted
    • bonus
  5. Run 5Draft proposes 4, target checks them in one pass, 4 kept, then the target adds 1 (bonus). +5 tokens.

    • d1 accepted
    • d2 accepted
    • d3 accepted
    • d4 accepted
    • bonus
  6. Run 6Draft proposes 4, target checks them in one pass, 0 kept, then the target adds 1 (resampled). +1 token.

    • d1 rejected
    • d2 discarded
    • d3 discarded
    • d4 discarded
    • resampled
  7. Run 7Draft proposes 4, target checks them in one pass, 1 kept, then the target adds 1 (resampled). +2 tokens.

    • d1 accepted
    • d2 rejected
    • d3 discarded
    • d4 discarded
    • resampled
  8. Run 8Draft proposes 4, target checks them in one pass, 4 kept, then the target adds 1 (bonus). +5 tokens.

    • d1 accepted
    • d2 accepted
    • d3 accepted
    • d4 accepted
    • bonus
  9. Run 9Draft proposes 4, target checks them in one pass, 3 kept, then the target adds 1 (resampled). +4 tokens.

    • d1 accepted
    • d2 accepted
    • d3 accepted
    • d4 rejected
    • resampled
  10. Run 10Draft proposes 4, target checks them in one pass, 3 kept, then the target adds 1 (resampled). +4 tokens.

    • d1 accepted
    • d2 accepted
    • d3 accepted
    • d4 rejected
    • resampled

After 10 runs: 39 tokens for 12 target steps, a measured 3.25×. The expected value is 2.8×; short traces vary around it.

What it shows

Speculative decoding is only worth it if the draft model guesses well and costs little. Two numbers decide that: how often drafts are accepted (α) and the draft’s cost compared with the target’s (c).

The tool computes expected tokens per run and the speedup, plots speedup against draft length γ, and lets you step through a seeded trace of runs.

How to read it

  • α is the chance one draft token is accepted, assumed equal for every token. c is the draft step time divided by the target’s.
  • “Tokens per target pass” is (1 − α^(γ+1)) ÷ (1 − α). Speedup divides it by γc + 1.
  • The chart shows speedup for each γ. The line at “Plain decoding (1×)” is break-even; below it, speculation is slower.
  • “Guaranteed speedup” appears only when α is above c. Otherwise speculation may lose time.
  • Trace chips: ✓ accepted, ✗ rejected, – discarded (drafted after a rejection), ↻ resampled, + bonus. A short trace will not match the expected value.
  • Real acceptance varies with the text, so measure α on your own prompts.

Questions

Does speculative decoding change what the model writes?

Not in distribution. The acceptance rule from Leviathan et al. and Chen et al. makes the sampled tokens follow exactly the target model’s distribution, whatever the draft model proposes. A poor draft costs speed, not quality.

What is a good acceptance rate?

It depends on how well the draft model matches the target on your text. Code and structured output are easier to predict than open-ended prose. Measure it on real traffic: count accepted draft tokens over proposed ones for a representative set of prompts.

Why is there a best draft length?

Each extra draft token adds cost but is accepted only if every earlier one was. The chance of reaching the k-th token falls as α^k, so the extra tokens you gain shrink while the cost per token stays constant. Past the best γ, longer drafts slow you down.

Why does the cost coefficient matter so much?

Every run pays γ draft steps before the target can check anything. If the draft is half the size of the target (c = 0.5), four draft tokens cost three target steps before the check, and the gain disappears unless acceptance is very high. That is why drafts are usually tiny models, or lightweight heads attached to the target.

Is the target check really as cheap as one step?

Roughly, when decoding is memory-bound: checking several tokens reuses the same weight read, so it costs only a little more arithmetic. If the batch is large enough that the GPU is compute-bound, the check is no longer free and speculation helps less. The paper counts this extra work as a separate increase in operations.

Sources

Explore further

  • EAGLESpeculative decoding that drafts from the target model’s own features instead of a separate small model.

Last updated

More tools

All tools

Your first senior-level
lesson is free.

Choose a course, open a free lesson, and explore an idea you’ve wanted to understand.