Skip to content
sinc-LLMBook a 15-minute call
Page signal: 10 sections as samples, joined by sinc reconstruction; computed from this page's text.

Speculative Decoding for LLM Serving: Draft, Verify, and Ship

A plain guide to speculative decoding for engineers who serve LLMs: how the draft and verify loop works, why output stays exact, and how to pick a method.

Quick Answer & Verified Key Facts

Direct Answer: Speculative decoding proposes drafting 3 to 5 tokens per step, tuning length based on acceptance rate and drafting cost, with best gains when acceptance is high and drafter is cheap. Suitable for input-grounded tasks like summaries and code edits, it can yield 2x to 4x speedups.

On this page

Speculative decoding speeds up LLM text output by letting a cheap drafter guess several tokens and the big model check them all in one pass. A smart accept and reject rule keeps the output the same as the big model alone. The gain depends on how often guesses are right, how cheap the drafter is, and how busy your GPUs are.

By Mario AlexandreLLM Performance & Reliability

Speculative decoding in one paragraph

A large language model writes text one token at a time. Each new token needs a full pass through the model. As the Leviathan et al. paper puts it, decoding K tokens takes K serial runs of the model. That serial chain is the main reason long answers feel slow. Speculative decoding breaks the chain. A cheap drafter guesses a few tokens ahead. The big model, called the target, then checks all of those guesses in one pass. Good guesses are kept. The first bad guess is fixed, and the rest are thrown away. Then the loop starts again.

The key point is that the check costs about the same as making one token. So if the drafter is right a lot, you get several tokens for the price of one target pass. If the drafter is wrong, you still get at least one good token from that pass. You never get fewer tokens than plain decoding would give you per target pass.

This guide is for engineers who run models in production. It covers the loop, the math, and the knobs. It also covers the main drafter types, how batch size changes the picture, and how to turn the feature on in vLLM and Hugging Face Transformers. For the wider set of speed levers, see our guide to LLM latency optimization.

Why decoding is slow in the first place

To see why speculation works, you need to know where the time goes. Each decode step reads the full set of model weights from GPU memory. The Medusa paper says each step necessitates moving the full model parameters from High-Bandwidth Memory (HBM) to the accelerator's cache. The Hugging Face assisted generation post makes the same point in plain terms. It says the bottleneck in the forward pass comes from loading the model layer weights into the computation cores of your device, not from performing the computations themselves.

So at small batch sizes, the GPU is mostly waiting on memory. Its math units sit idle much of the time. That idle math is a free resource. If you feed the model five tokens instead of one, the weights are still read once. The extra math fits in the gap. The DeepMind speculative sampling paper states this as its core finding. The latency of parallel scoring of short continuations, generated by a faster but less powerful draft model, is comparable to that of sampling a single token from the larger target model.

That is the whole trick. You trade spare math for fewer serial steps. This also tells you when the trick stops working. If the GPU is already busy with math, there is no spare room. We come back to this in the batch size section below.

This speedup is about the decode phase, the time between tokens. It does not shorten the prefill phase, where the model reads your prompt. If your users complain about the wait before the first word, look at prefill and queueing instead. Our page on time to first token vs throughput explains how those two numbers differ.

The draft and verify loop, step by step

Here is one round of the loop. The names follow the Leviathan paper. The target model is Mp. The drafter is Mq. The draft length is gamma, the number of guesses per round.

  1. The drafter runs gamma times in a row. Each run adds one guessed token. This is cheap because the drafter is small.
  2. The target model runs once on the prompt plus all gamma guesses. In that one pass it scores every position at the same time. It also produces a score for one extra position past the last guess.
  3. Each guess is checked in order, from left to right. Each one is kept or rejected by a random test, described below.
  4. At the first rejected guess, the loop stops. The target picks a fresh token for that spot from a fixed up distribution.
  5. If every guess passes, the target adds one bonus token from the extra position it scored.
  6. The kept tokens go to the user. The next round starts from the new end of the text.

So each round makes at least one token and at most gamma plus one tokens. The paper sums up the idea in its abstract. The target runs in parallel on the outputs of the approximation models, potentially generating several tokens concurrently, and without changing the distribution.

There is one more nice property. The paper says the method can accelerate existing off-the-shelf models without retraining or architecture changes. You do not touch the target weights. You only add a drafter and a new decode loop.

How rejection sampling keeps the output exact

Speed would be worthless if it changed what the model says. The accept rule is what makes the method safe. It works on the two models' probabilities for the guessed token.

Call the target's probability for a token p(x). Call the drafter's probability q(x). The rule works like this.

  • If p(x) is at least q(x), keep the token. The target likes it at least as much as the drafter did.
  • If p(x) is less than q(x), keep it with chance p(x) divided by q(x). Otherwise, reject it.
  • On a rejection, draw a new token from a fixed up distribution. The paper writes it as the adjusted distribution p0 (x) = norm(max(0, p(x) − q(x))). In words, take the target's odds, subtract the drafter's odds, drop anything below zero, and rescale so it sums to one.

This rule has a proof behind it. The Leviathan paper shows that tokens sampled via speculative sampling from p(x) and q(x) are distributed identically to those sampled from p(x) alone. The drafter changes how fast you get tokens. It does not change which tokens you get, in a statistical sense. The DeepMind paper reached the same result at the same time. It says its modified rejection sampling scheme preserves the distribution of the target model within hardware numerics.

Note the phrase "within hardware numerics." Real GPUs round numbers. The vLLM docs say differences in hardware numerical precision may lead to slight discrepancies in the output distribution. They also run a test that confirms that greedy sampling with speculative decoding matches greedy sampling without it. So in practice, think of it as exact in math and very close on real chips.

Some modes give up exactness on purpose to gain speed. The vLLM docs say their FLy verifier deliberately relaxes verification and is not distribution preserving. Medusa also offers a looser rule, covered below. If you need the exact target output, stay with the standard rejection sampler.

Acceptance rate and the expected tokens formula

The single most useful number in speculative decoding is the acceptance rate. The Leviathan paper calls the chance of keeping one guess beta. Beta changes from token to token. The paper then takes the average and names it alpha, written as α = E(β). Alpha is a property of your target, your drafter, your prompts, and your sampling settings together.

If you assume each guess passes with the same chance alpha, the count of tokens per round follows a simple pattern. The paper calls it a geometric variable, with success probability 1 − α and cap gamma plus one. From that, it gets a closed form for the expected count. The paper labels it E(# generated tokens) in its Equation 1. Here it is in plain text:

E[tokens per target pass] = (1-alpha^(gamma+1)) / (1-alpha)

Read it this way. When alpha is near zero, the result is near one. You get one token per pass, the same as plain decoding. When alpha is near one, the result is near gamma plus one. You get every guess plus the bonus token.

Worked example: tokens per pass (illustrative arithmetic)

These numbers are illustrative arithmetic from the formula above. They are not measurements. The inputs are alpha and gamma only.

  • Inputs: alpha = 0.8, gamma = 4.
  • Step 1: alpha to the power 5 is 0.8 x 0.8 x 0.8 x 0.8 x 0.8 = 0.32768.
  • Step 2: 1 minus 0.32768 is 0.67232.
  • Step 3: 1 minus alpha is 0.2.
  • Step 4: 0.67232 divided by 0.2 is 3.3616.

So with these inputs, each target pass yields about 3.36 tokens on average. Plain decoding yields 1.0. Now drop alpha to 0.6 with the same gamma. Alpha to the power 5 is 0.07776. One minus that is 0.92224. Divide by 0.4 and you get about 2.31 tokens per pass. A small drop in alpha costs a lot of tokens.

Draft cost and the walltime speedup

Tokens per pass is only half the story. The drafter is not free. The paper adds a second input for this. Definition 3.7. Let c, the cost coefficient, be the ratio between the time for one run of the drafter and one run of the target. A drafter that takes one twentieth of the target's time has c = 0.05.

Theorem 3.8 in the paper gives the expected improvement factor in total walltime. It divides the tokens per pass by the time cost of one round. One round costs gamma drafter runs plus one target run:

speedup = (1-alpha^(gamma+1)) / ((1-alpha) * (gamma*c + 1))

This formula assumes you have spare compute to run the wider target pass. That holds at small batch sizes. It fails when the GPU is already full, as we cover later.

Worked example: speedup by draft length (illustrative arithmetic)

The table below is illustrative arithmetic from Theorem 3.8. The inputs are listed in each row. None of these are measured results from any system.

alpha c gamma Tokens per pass Round cost (gamma x c + 1) Speedup
0.8 0.05 2 2.44 1.10 2.22x
0.8 0.05 4 3.36 1.20 2.80x
0.8 0.05 8 4.33 1.40 3.09x
0.8 0.05 10 4.57 1.50 3.05x
0.6 0.05 2 1.96 1.10 1.78x
0.6 0.05 4 2.31 1.20 1.92x
0.6 0.05 5 2.38 1.25 1.91x
0.8 0.20 3 2.95 1.60 1.85x
0.8 0.20 4 3.36 1.80 1.87x
0.8 0.20 5 3.69 2.00 1.84x

Three lessons fall out of this small grid.

First, alpha matters most. Going from 0.6 to 0.8 lifts the best speedup from about 1.9x to about 3.1x in this example.

Second, draft cost caps the gain. With alpha at 0.8, moving c from 0.05 to 0.20 drops the best case from about 3.1x to under 1.9x.

Third, the best gamma moves with alpha and c. High alpha and a cheap drafter favor long drafts. Low alpha or a costly drafter favor short ones. Past the peak, extra guesses mostly get thrown away, and each one still costs drafter time.

Choosing the draft length

The draft length is the number of tokens the drafter guesses per round. The Leviathan paper calls it gamma. In vLLM the knob is num_speculative_tokens. The docs describe it as the number of speculative tokens to propose per step.

The paper gives a clear rule. Given c and alpha, the optimal γ is the one maximizing the walltime improvement. You can do that by hand with the table method above. Plug in your measured alpha and c. Try gamma from 1 to 10. Pick the peak.

In practice, a few habits help.

  • Start short. Three to five tokens is a safe first try for a separate draft model. Long drafts waste work when alpha is low.
  • Measure alpha on real traffic. Alpha on a benchmark can differ from alpha on your prompts. Code, chat, and long summaries all behave in different ways.
  • Re-tune when you change the prompt mix, the temperature, or the drafter. Each of those moves alpha.
  • Watch for drift by task. EAGLE-2's authors found that the acceptance rate of draft tokens is also context-dependent. One fixed gamma will be too long for some requests and too short for others.

Some tools tune gamma for you. Hugging Face Transformers adjusts the draft length at run time. Its blog post explains that the original heuristic increases it by 2 if ALL tokens match and decreases it by 1 otherwise. vLLM also lists dynamic and adaptive modes that size the work per request. Their docs describe these as giving higher gain than the base method in their own table. Treat that as a reason to test, not as a promise.

Choosing a draft model

A classic setup uses a second, smaller model as the drafter. The choice of drafter decides both alpha and c. You want high alpha and low c, and those pull against each other.

Bigger drafters guess better. In the Leviathan tests, the authors note: "As expected we see that α increases" with the size of the approximation model. But bigger drafters also cost more time per guess. The same paper found that among its T5 drafters, T5-small, with a good balance of c and alpha, gave the best speedup. The smallest useful model won, not the biggest.

Hugging Face gives two practical rules for picking an assistant model.

  • Same tokenizer, ideally. Their post says the assistant must have the exact same tokenizer as your model. Without that, every token would need to be decoded and re-encoded, often on the CPU. A later Hugging Face feature relaxes this rule. Their universal assisted generation post says "it is now possible to accelerate inference from any decoder or Mixture of Experts model" with a small assistant. It notes that when the "assistant and target tokenizers use different vocabularies it's necessary to handle the discrepancies between them." That translation step costs time, so a shared tokenizer is still the faster setup.
  • Much smaller. They suggest access to an assistant model that is at least an order of magnitude smaller than your model (the bigger the difference, the better).

That points to a simple search order.

  1. Look for a small model in the same family as your target, trained on similar data, with the same tokenizer.
  2. Check whether the target ships its own draft parts, such as multi-token prediction heads. vLLM notes that MTP is best when the target model has native MTP support.
  3. Look for a trained EAGLE or Medusa head for your exact target model.
  4. If none of these exist, try a model free method such as n-gram lookup.

The wrong drafter can make things worse. Hugging Face warns that slow assistants can tip the balance, resulting in a net slowdown. Always compare against plain decoding on the same hardware and prompts.

A drafter is also more memory on the GPU. It needs its own weights and its own KV cache. On a tight card, that memory may be worth more as extra batch room. Our guide to KV cache memory in long context serving shows how to size that cache. If you are thinking about a smaller target model too, our page on LLM quantization covers the accuracy side.

Medusa heads: drafting without a second model

A separate drafter has a real cost in ops work. The Medusa authors point to the challenges associated with acquiring and maintaining a separate draft model. You need a small model with the same tokenizer. You must keep it in sync when the target changes. You must host it next to the target.

Medusa takes another path. It works by adding extra decoding heads to predict multiple subsequent tokens in parallel. Each head is a small layer on top of the target model. Head one guesses the next token after the usual next token. Head two guesses the one after that, and so on. The target model's own hidden state feeds all the heads, so the drafter is almost free to run.

Medusa also changes how guesses are checked. Each head can offer more than one guess, so the result is a tree of possible paths. In the paper's words, using a tree-based attention mechanism, Medusa constructs multiple candidate continuations and verifies them simultaneously in each decoding step. The target picks the longest path that passes.

There are two training modes.

  • Medusa-1 trains only the heads. The paper says it is directly fine-tuned on top of a frozen backbone LLM, enabling lossless inference acceleration. The target weights do not change.
  • Medusa-2 trains the heads and the target together. This gives better guesses, but it needs care so the target keeps its skills.

The paper reports that Medusa-1 can achieve over 2.2x speedup without compromising generation quality, while Medusa-2 further improves the speedup to 2.3 to 3.6x. Those are the authors' results on their models and tests.

One caveat matters for exactness. Medusa also offers a typical acceptance scheme to boost the acceptance rate while maintaining generation quality. That rule is looser than strict rejection sampling. It aims to keep quality, not to keep the exact target distribution. If you need exact output, check which accept rule your stack uses.

EAGLE, EAGLE-2, and EAGLE-3

The EAGLE line of work is now one of the most common model based drafters. vLLM's docs call EAGLE a strong general-purpose model-based method.

EAGLE drafts from hidden features

The first EAGLE paper starts from one idea. It says autoregression at the feature (second-to-top-layer) level is more straightforward than at the token level. Instead of guessing words, a small EAGLE head guesses the target model's next hidden state. It then turns that state into a token with the target's own output layer. To deal with noise in that guess, EAGLE also feeds in the token from one step ahead.

The reported result is strong. For LLaMA2-Chat 70B, EAGLE achieved a latency speedup ratio of 2.7x to 3.5x, doubled throughput, while maintaining the distribution of the generated text. That last part means EAGLE keeps the exact rejection rule.

EAGLE-2 adds a dynamic draft tree

The EAGLE-2 paper noticed that a fixed tree of guesses wastes work. Some contexts are easy and some are hard. EAGLE-2 builds a context-aware dynamic draft tree instead. It can do this because, as the authors found, the confidence scores from the draft model approximate acceptance rates with small errors. So the drafter can spend its budget on the branches most likely to pass.

The authors report EAGLE-2 speedup ratios of 3.05x to 4.26x. According to the same abstract, that is 20%-40% faster than EAGLE-1.

EAGLE-3 switches to direct token prediction

The EAGLE-3 paper found that feeding EAGLE more training data gave only small gains. It traced this to the feature guessing step. So EAGLE-3 abandons feature prediction in favor of direct token prediction. It also fuses features from several layers of the target, not just the top one.

The authors report that EAGLE-3 achieves a speedup ratio up to 6.5x, with about 1.4x improvement over EAGLE-2. They also give a serving result. In the SGLang framework, EAGLE-3 achieves a 1.38x throughput improvement at a batch size of 64. That number is lower than the single stream speedup, and it is the more useful one for busy servers. It shows the gain shrinks under load but does not vanish.

Lookahead decoding: no drafter at all

Lookahead decoding takes a different route. Its authors call it an exact, parallel decoding algorithm that accelerates LLM decoding without needing auxiliary models or data stores. There is no draft model and no trained head.

The target model makes its own guesses. It runs a fixed point Jacobi iteration over a window of future tokens. Along the way it stores short n-grams in a pool. Promising n-gram candidates are then checked by a separate verify branch in the same pass. The paper notes it is compatible with memory-efficient attention such as FlashAttention. The paper says the method allows trading per-step log(FLOPs) to reduce the number of total decoding steps. In plain words, each step does more math, but you need fewer steps.

The authors report that their implementation can speed up autoregressive decoding by up to 1.8x on MT-bench and 4x with strong scaling on multiple GPUs in code completion tasks. The extra math per step means lookahead depends even more on spare GPU compute than draft model methods do.

Prompt lookup and n-gram decoding

Prompt lookup decoding is the simplest drafter of all. The project README sums it up in one line. We modify speculative decoding where we replace the draft model with simple string matching in the prompt to generate candidate token sequences.

Here is how it works. Take the last few tokens the model just wrote. Search the prompt for the same short run of tokens. If you find it, guess that the model will next copy whatever followed that run in the prompt. Hand those tokens to the target to check, like any other draft.

This works well when the output repeats the input. The README explains that in tasks like summarization, document QA, multi-turn chat, and code editing, there is high n-gram overlap between LLM input (prompt) and LLM output. Think of entity names, quoted phrases, or code that the model copies while editing.

The README reports that this results in significant speedups (2x to 4x) in input-grounded tasks. It also notes the method can be used with any decoder model without model changes or external datastore, and with both greedy and sampling techniques.

vLLM ships the same idea as its n-gram method. It also has a suffix decoding method that matches against prior responses too. vLLM's docs rate both as low to medium gain at low QPS and medium gain at high QPS. Their main plus is that they add almost no work during peak traffic.

Batch size changes everything

Most speedup numbers in papers come from one request at a time. Production servers rarely look like that. They group many requests into each step with continuous batching. Batch size is the biggest reason a lab speedup fails to show up in prod.

Recall the core trick. Speculation uses spare math while the GPU waits on memory. At batch size 1, there is a lot of spare math. As the batch grows, the GPU does more useful work per weight read. The spare math shrinks. Now each rejected guess burns compute that a real request could have used.

For this reason, the MagicDec paper notes that the conventional wisdom suggests that its efficacy is limited to small batch sizes. The vLLM docs reflect the same view. They pitch the feature as a way to reduce inter-token latency under medium-to-low QPS (queries per second), memory-bound workloads.

MagicDec adds an important twist. It argues that SD can achieve speedup even for a high throughput inference regime for moderate to long sequences. The reason is that the bottleneck moves. MagicDec first identifies the bottleneck shifts with increasing batch size and sequence length. With long contexts and big batches, reading the KV cache starts to cost more than reading the weights. A normal drafter has to read its own large KV cache too, so it does not help much.

So MagicDec uses a draft model with a sparse KV cache to address the KV bottleneck, which scales with both sequence length and batch size. The drafter looks at only part of the context, so it stays cheap. The target still checks every token with full attention, so output stays exact. The authors report up to 2.51x speedup for Llama3.1-8B when serving batch sizes ranging from 32 to 256 on their hardware and tasks.

What this means for you:

  • Short prompts and big batches: expect small gains, or none. Test before you ship.
  • Low traffic, latency first: this is where speculation shines. Single user tools, coding helpers, and voice agents fit here.
  • Long contexts and big batches: a sparse KV drafter can still pay off. A plain small drafter may not.
  • Traffic that swings during the day: model free methods like n-gram add little load at peak. vLLM also lists dynamic modes for workloads with fluctuating QPS.

Reported speedups, with attribution

The table below lists headline numbers as each source reported them. Each comes from a different model, task, and hardware setup. Do not compare rows as if they were one benchmark. Treat them as a rough map of what each family has shown.

Method Source Reported result Setting the source names
Speculative decoding Leviathan et al. 2X to 3X, identical outputs T5-XXL vs standard T5X
Speculative sampling Chen et al. 2 to 2.5x decoding speedup Chinchilla 70B, distributed setup
Medusa-1 Cai et al. over 2.2x frozen backbone heads
Medusa-2 Cai et al. 2.3 to 3.6x heads trained with backbone
EAGLE Li et al. 2.7x to 3.5x latency LLaMA2-Chat 70B
EAGLE-2 Li et al. 3.05x to 4.26x three LLM series, six tasks
EAGLE-3 Li et al. up to 6.5x; 1.38x throughput SGLang at batch size 64 for the second figure
Lookahead decoding Fu et al. up to 1.8x; 4x MT-bench; code with multiple GPUs
MagicDec Chen et al. up to 2.51x Llama3.1-8B, batch 32 to 256
Prompt lookup README 2x to 4x input-grounded tasks
Assisted generation Hugging Face up to 3x with INT8, up to 2x otherwise model fits in GPU memory

The Hugging Face post also says you can reduce latency up to 10x in commodity hardware. That top figure applies when models do not fit in your GPU and are relying on memory offloading. Most data center serving does not run that way.

vLLM's docs offer the best single caveat for this whole table. Real gains depend on your model family, traffic pattern, hardware, and sampling settings. They also point to a script for this. For reproducible measurements in your environment, use examples/features/speculative_decoding/spec_decode_offline.py or their benchmark CLI.

Turning it on in vLLM

This server supports several drafters behind one setting. The docs say to use --speculative-config to pass speculative decoding settings as a JSON object on the CLI. Our guide to LLM inference engines compares vLLM with other servers if you have not picked one yet.

A separate draft model looks like this, adapted from the vLLM docs:

vllm serve <target-model> \
  --speculative-config '{"method": "draft_model", "model": "<draft-model>", "num_speculative_tokens": 5}'

The n-gram drafter needs no second model:

vllm serve <target-model> \
  --speculative-config '{"method": "ngram", "num_speculative_tokens": 4, "prompt_lookup_min": 2, "prompt_lookup_max": 5}'

The same keys are accepted from Python via LLM(..., speculative_config={...}). Common method values listed in the docs include draft_model, ngram, suffix, mtp, eagle3, and dflash. For an EAGLE head, set the method to the EAGLE type and point model at the trained head for your exact target.

A few tips for a first rollout:

  • Pin your vLLM version. Then read the docs page that matches the version you run.
  • Keep the standard rejection sampler unless you have tested a lossy one on your evals.
  • Log acceptance per request. vLLM lists per-request acceptance metrics in its docs. Low acceptance on a route is a sign to turn speculation off there.
  • Load test at your real peak QPS, not just one request at a time.

Turning it on in Hugging Face Transformers

Hugging Face calls this feature assisted generation. You load a second, smaller model and pass it to generate. The Hugging Face post shows the core line:

outputs = model.generate(**inputs, assistant_model=assistant_model)

A shared tokenizer is the simplest setup, as covered above. The post notes that low temperatures are, therefore, more favorable to your assistant model. High temperature sampling makes the drafter's guesses miss more often, which cuts the gain.

Prompt lookup is even easier in Transformers. The README says to simply add prompt_lookup_num_tokens=10 to your model.generate(...) call. No second model is needed.

One limit is worth knowing. At the time of the release of this blog post, assisted generation is limited to a batch size of 1. Newer Transformers versions may differ, so check the current docs. Either way, Transformers generate is best for tests and single user tools. For multi user serving, a server like vLLM is the usual choice.

A decision table for picking a method

Use this table as a first guess. It blends the reported results above with vLLM's own qualitative ratings. Your own tests should have the final say.

Your situation First method to try Why
Low traffic, latency matters most, a small same family model exists Separate draft model vLLM rates it high gain at low QPS; easy to reason about
Target ships native MTP heads MTP vLLM says MTP is best when the target has native support
A trained EAGLE head exists for your exact target EAGLE-3 or EAGLE Highest reported speedups; keeps the exact distribution
You can train small heads but not a full drafter Medusa-1 Heads train on a frozen target; lossless
Output copies a lot from the prompt, such as RAG answers or code edits N-gram or prompt lookup No extra model; README reports 2x to 4x on input-grounded tasks
Repeated answers across many requests Suffix decoding vLLM notes it matches against prior responses
High QPS with short prompts Off, or n-gram only Little spare compute; measure before you enable
High QPS with long contexts Sparse KV drafter, per MagicDec KV cache becomes the main cost at large batch and length
Spare GPUs, no drafter available Lookahead decoding Exact and needs no extra model; scales with more compute

How to measure the gain on your own stack

You do not need a big lab to test this. A careful A/B run on one GPU node will tell you most of what you need. Here is a simple plan.

  1. Pick a fixed set of real prompts. Use a mix that matches your traffic, by task and by length.
  2. Fix the sampling settings. Use the same temperature and top p you run in prod. Acceptance is very sensitive to these.
  3. Run plain decoding first. Record time to first token, time per output token, and tokens per second for the whole server.
  4. Turn on one method with a short draft length. Record the same numbers, plus the acceptance rate.
  5. Sweep draft length from short to long. Stop when time per output token stops falling.
  6. Repeat at two or three load levels, from light to your real peak.
  7. Check output quality on your evals. With the standard sampler it should match, but this is a cheap guard against config mistakes.

Use the formula from earlier as a sanity check. If you know alpha and c, you can predict roughly where the peak should be. If your measured gain is far below the prediction, the GPU is likely compute bound at that load, or the drafter is slower than you think.

Speculation is one lever among many. Batching, caching, quantization, and routing all change the same budget. Our guide to model cascades and routing covers a different way to cut cost and wait time. If you want help designing and testing a serving stack like this, see the sinc-LLM solutions page.

Key points to remember

  • Speculative decoding trades spare GPU math for fewer serial decode steps.
  • The standard accept rule keeps the output distribution exact, up to float rounding.
  • Acceptance rate and draft cost set the gain. The Leviathan formulas let you predict it.
  • The best draft length rises with acceptance and falls with draft cost.
  • Model based drafters, such as EAGLE, Medusa, and small draft models, give the biggest reported gains.
  • Model free drafters, such as n-gram lookup and lookahead, are easy to turn on and need no training.
  • Gains shrink as batch size grows, except where long contexts make the KV cache the main cost.
  • Always measure on your own prompts, sampling settings, and load.

Frequently asked questions

Does speculative decoding change the output of the model?

No, not with the standard rejection sampler. The method accepts or rejects each draft token with a rule that keeps the final text distributed exactly like the target model's own output. The vLLM team tests that greedy output matches with and without speculation. Tiny gaps can still come from floating point math and batch effects. Some opt-in verifiers, such as vLLM's FLy mode or Medusa's typical acceptance, relax this rule on purpose.

What is a good acceptance rate for speculative decoding?

There is no single good number, because the payoff also depends on draft cost. As an illustrative example from the Leviathan formula, an acceptance rate of 0.8 with four draft tokens yields about 3.36 tokens per target pass. At 0.6 the same setup yields about 2.31. If the draft model is slow, even a high rate may not help. Measure acceptance on your own prompts and compute the speedup, rather than chasing a fixed target.

How many draft tokens should I propose per step?

Start small, often three to five tokens, and tune from there. The best draft length rises when acceptance is high and the drafter is cheap. It falls when acceptance is low or drafting is costly. The Leviathan paper picks the length that maximizes expected walltime gain. vLLM exposes this as num_speculative_tokens, and Hugging Face tunes it at run time with a simple add two, drop one rule.

Does speculative decoding help at large batch sizes?

Less than at small batch sizes, in the usual case. With big batches the GPU becomes busy with math, so extra verify work is no longer free. The MagicDec paper found that for moderate to long sequences, the KV cache becomes the main cost, and a draft with a sparse KV cache can still give gains at batch sizes from 32 to 256. vLLM pitches the feature at medium to low QPS.

Which draft model should I choose?

Pick a model from the same family that shares the exact tokenizer, and that is at least ten times smaller. Hugging Face's assisted generation post asks for the shared tokenizer and suggests the size gap. Its newer universal mode can pair models with different tokenizers, at some extra cost. Then test acceptance on real prompts. If no good small model exists, try a trained head such as EAGLE or Medusa, or a model free method such as n-gram prompt lookup. Model free methods need nothing extra to load.

What is the difference between EAGLE and Medusa?

Both add small trained parts to the target model instead of a separate draft model. Medusa adds extra decoding heads that each guess a later token, then checks a tree of guesses at once. EAGLE drafts from the target model's hidden features. EAGLE-2 adds a dynamic draft tree, and EAGLE-3 switches to direct token prediction with fused features from several layers. Each paper reports its own speedups on its own test set.

When should I use prompt lookup or n-gram decoding?

Use it when the output copies a lot from the input. Good fits are summaries, document question answering, multi-turn chat, and code edits. The drafter is just string matching in the prompt, so there is no model to train or host. The project README reports 2x to 4x on input-grounded tasks. For open-ended writing, where little text repeats, the gain is often small.

Sources

  1. Hugging Face: Universal Assisted Generation: Assisted generation with a drafter that uses a different tokenizer.
  2. Leviathan, Kalman, Matias: Fast Inference from Transformers via Speculative Decoding (ICML 2023): The original method, the acceptance rate alpha, the expected tokens formula, and the walltime analysis.
  3. Chen et al.: Accelerating Large Language Model Decoding with Speculative Sampling: Parallel method from DeepMind, with results on Chinchilla 70B.
  4. Cai et al.: Medusa, Simple LLM Inference Acceleration Framework with Multiple Decoding Heads: Extra decoding heads plus tree attention, with Medusa-1 and Medusa-2 training modes.
  5. Li et al.: EAGLE, Speculative Sampling Requires Rethinking Feature Uncertainty: Feature level drafting from the target model's hidden states.
  6. Li et al.: EAGLE-2, Faster Inference of Language Models with Dynamic Draft Trees: Context aware draft trees built from draft confidence.
  7. Li et al.: EAGLE-3, Scaling up Inference Acceleration via Training-Time Test: Direct token prediction with multi-layer feature fusion, plus a batch 64 throughput result.
  8. Fu et al.: Break the Sequential Dependency of LLM Inference Using Lookahead Decoding: Exact parallel decoding with no draft model or data store.
  9. Chen et al.: MagicDec, Breaking the Latency-Throughput Tradeoff for Long Context Generation with Speculative Decoding: How batch size and sequence length change the bottleneck, and sparse KV drafts.
  10. vLLM documentation: Speculative Decoding: Methods, the speculative config schema, and lossless test notes.
  11. Prompt Lookup Decoding README: String matching in the prompt as the drafter.
  12. Hugging Face: Assisted Generation, a new direction toward low-latency text generation: The assistant_model API, tokenizer rule, and draft length heuristic in Transformers.
Original source record

Skip to content

sinc-LLMAboutBlogServices