Answers for LLM inference engineers

Is speculative decoding lossless? Why greedy output changes, and a test that tells numerics from bugs

In exact arithmetic, yes: with the standard acceptance rule, speculative decoding returns the same greedy text and samples from the same distribution as the target model alone. On real engines, three things break that. (1) Numerics: the target checks k drafted tokens in one forward pass over k+1 rows, while ordinary decoding runs one row at a time, and the two do not round identically. Where the top two tokens are nearly tied, the choice flips and greedy output diverges from there on. This is expected and not a bug in the acceptance rule. (2) Bugs in the speculative path: open reports in llama.cpp, vLLM and SGLang (table below) show divergence where the baseline's token was a clear winner, or sampled answers that are measurably skewed. (3) Settings that are lossy by design, such as relaxed acceptance thresholds or synthetic acceptance. specdiff.py sends the same prompts to your endpoint with and without speculation and reports which of the three you have.

Published 2026-11-19 · Issue table as of 2026-11-18 · Tool version 1.0.0 (Python 3.8+, standard library only)

Why can greedy output differ with speculative decoding on?

Because the verify pass and plain decoding compute the same logits with different kernels or different launch shapes, and greedy decoding turns one flipped near-tie into a different continuation.

How do I tell a numerics flip from a real bug?

Look at how far ahead the baseline's token was at the first divergent position. A flip caused by rounding needs a near-tie: the two candidates are within about the size of the numeric noise. A clear winner that gets replaced is a bug in the speculative path, or a lossy setting.

What you observeMost likely causeWhat to do
Divergence at a position where the baseline's top two tokens are within the noise (specdiff: near-tie)Verify-pass numerics (M = k+1 vs M = 1)Accept it, or serve reproducibility-critical traffic without speculation. Test task metrics, not bytes.
Divergence where the baseline's token was clearly ahead (large-gap)Bug in the speculative path (state rollback, penalties, prefill path), or a lossy settingCheck the settings table, then the issue table; report with the specdiff JSON.
Sampled answers differ beyond chance at temperature > 0Lossy setting, or a sampling bug (e.g. padded draft trees, SGLang #43725)Same as above. Near-ties cannot move a whole distribution.
Output differs at the very first tokenThe prefill path differs between the two servers (vLLM #58973); no draft is involved yetCompare launch flags other than the speculative ones.
Same request gives different output depending on what was served beforeState shared across requests, e.g. an n-gram corpus (SGLang #50395)Restart and send the prompts in a fixed order, or use a per-request drafter.
The baseline disagrees with itselfNot speculation at all: batching, prefix cache, other trafficFix that first: vLLM batch invariance: what still breaks determinism.
No draft token was acceptedThe test proves nothing: every token came from ordinary decodingUse prompts the drafter can predict (repetition, code, copying).

Is my speculative setting meant to be lossless?

Not always. These options trade the guarantee for speed on purpose. Checked in each project's source on 2026-11-18 (vLLM 92fd8cc, SGLang 21dae9b, llama.cpp 10f173b).

EngineSettingLossless?What it does
vLLMrejection_sample_method="standard" (default)yesProbabilistic rejection sampling; the setting the documented guarantee covers.
vLLMrejection_sample_method="fly"no"FLy deliberately relaxes verification and is not distribution preserving" (docs).
vLLMrejection_sample_method="synthetic"noAccepts drafts "with a decaying probability calibrated to synthetic_acceptance_rate" (config docstring): a benchmarking mode.
SGLang--speculative-accept-threshold-single / -acc below 1.0noRelaxed acceptance for EAGLE-family and DFlash verification. 1.0 is the default; rejection-sampling mode refuses other values.
SGLangrepetition_penalty ≠ 1 with EAGLE, EAGLE3, STANDALONE, NEXTNnoThe code applies "a relaxed version of penalties for speculative decoding"; output differs from plain decoding (#49403, open).
llama.cpp--spec-synth-len, --spec-synth-ratesno"benchmarking only": synthetic acceptance replaces verification entirely (server-context.cpp). Measured below.
llama.cpp--spec-draft-p-minyesStops drafting when the draft's top probability is below P. It changes what gets drafted, not how the target verifies.

specdiff.py: test your own endpoint

Run the target twice, once without and once with speculation, then point the script at both. It needs nothing beyond Python 3.8. Download specdiff.py.

# vLLM: same model, same flags, only the speculative config differs
vllm serve MODEL --port 8000
vllm serve MODEL --port 8001 --speculative-config '{"method":"ngram","num_speculative_tokens":4,"prompt_lookup_max":4}' \
    --per-request-spec-decode-metrics summary

# SGLang
python -m sglang.launch_server --model-path MODEL --port 30000
python -m sglang.launch_server --model-path MODEL --port 30001 --speculative-algorithm NGRAM

# llama.cpp
llama-server -m target.gguf --port 8080
llama-server -m target.gguf --port 8081 -md draft.gguf --spec-type draft-simple

curl -O https://erimaki-kobo.github.io/en/spec-decode-lossless-check/specdiff.py
python specdiff.py --base http://localhost:8000/v1 --spec http://localhost:8001/v1 --json report.json

What it does:

  1. Greedy test. Eight built-in prompts (or yours with --prompts file.jsonl) at temperature 0, sent twice to the baseline and once to the speculative endpoint, one request at a time so batching stays out of the picture. For each pair it reports the first divergent token, the baseline's logprob gap between its own token and the one the speculative side chose, and the drafted/accepted counts.
  2. Near-tie threshold from your own data. On the tokens both sides agree on, the largest logprob difference is the numeric noise of your stack. A divergence counts as a near-tie when the baseline's gap is at most max(0.05, 4 × that noise) nats, and as large-gap otherwise, including when the other token is not even in the baseline's top-k. Override with --tie-threshold.
  3. Sampling test. 200 samples per endpoint (--samples) at temperature 1 for prompts with short answers of several tokens, then a chi-square test of homogeneity, plus total variation distance as an effect size. The first token comes from prefill on both sides, so the test looks at whole answers, whose later tokens go through verification. Small cells are pooled so the test stays valid. With many distinct answers TV is biased upward even when nothing is wrong; read the p-value.
  4. Did speculation run? Draft and accepted counts come from vLLM's metrics.speculative_decoding (needs --per-request-spec-decode-metrics), SGLang's sglext.spec_tokens_details (the script sends return_spec_tokens_details) and llama-server's timings.draft_n / draft_n_accepted. If nothing was accepted, the verdict is inconclusive.
  5. Bad logprobs are caught. llama.cpp #27972 (open) reports llama-server returning logprob 0.0 with empty top_logprobs for every token when speculation is on. If the speculative side does that, the script warns and classifies from the baseline's logprobs only. Our build at 10f173b returned real logprobs with speculation on.
VerdictExitMeaning
NO_DIFFERENCE_FOUND0Greedy outputs identical, sampled answers consistent, drafts accepted.
SUSPECTED_BUG1A large-gap divergence, or a distribution difference at p < 0.001.
NEAR_TIE_DIVERGENCE3Every divergence began at a near-tie: numerics.
INCONCLUSIVE_*4The baseline is not reproducible on its own, or no draft token was accepted.
–2Could not run (connection, model id).

Use --completions for models without a chat template, --extra '{"chat_template_kwargs":{"enable_thinking":false}}' to pass engine-specific fields, --skip-sample for the greedy test only. Both endpoints must serve the same weights; the script cannot check that.

What did the test find on a real engine?

On llama.cpp's CPU backend, draft-model speculation matched plain decoding token for token; n-gram speculation on a Q4_0 target flipped one near-tie; the benchmarking-only synthetic mode skewed the sampled distribution by a wide margin.

Setup: llama.cpp built from 10f173b (2026-11-18), CPU, 1 thread, llama-server with -np 1, /v1/completions. The target is a 4-layer Llama-architecture model with random weights (256 hidden, vocabulary 516, made with make_toy_gguf.py), so the text is nonsense, but every token goes through llama.cpp's real decode and verify kernels. Eight prompts × 256 greedy tokens; sampling: 600 samples per endpoint of 3-token answers for two prompts.

TargetSpeculationGreedy: identicalDrafts acceptedMax |Δlogprob| on matching tokensSampling (p-value)Verdict
Q4_0draft-simple, draft = same file, n_max 88 / 81656 / 16621.9e-60.73, 0.91no difference
Q4_0ngram-mod7 / 8 (diverged at token 148, gap 0.018 nats)61 / 1280.030–near-tie
F32ngram-mod8 / 837 / 3172.1e-5–no difference
Q4_0draft-simple + --spec-synth-len 48 / 81382 / 38031.9e-61.3e-37, 1.9e-15suspected bug (lossy by design)

Which engines and methods are known to break greedy equivalence?

As of 2026-11-18, every major engine has at least one open report. "Class" is our reading of the report: numerics means divergence at near-ties from verify-pass arithmetic; bug means output that is wrong beyond rounding; design means a deliberate relaxation.

EngineReportMethod / conditionWhat happensClassState
llama.cpp#25618draft-mtp, draft-dspark; quantized target (Q4_K_M), VulkanGreedy text differs from plain decoding; bf16 target matches; n-gram matches on the same Q4 targetnumerics (path-dependent quantized compute)open
llama.cpp#27407draft-simple and DFlash2, CUDA (RTX 3090 Ti), IQ2_M targetDeterministic near-tie flips under batched verification ("a bit-exactness concern only")numericsclosed 2026-10-09
llama.cpp#31472draft-dflash, draft-dspark on qwen35moe (Gated DeltaNet) targets; CPU and SYCLDiffers on 7 of 8 prompts, including with 100% acceptancenumerics or recurrent-state handling (not isolated)open
llama.cpp#27972llama-server, any spec type (reported with draft-mtp, Vulkan)logprob 0.0 and empty top_logprobs for every tokenbug (reporting only; tokens unaffected)open
vLLM#54506Any method; MTP on a hybrid MoE model, TP4Verify pass (M = k+1) and decode (M = 1) differ in bits; RFC, no fix proposednumericsopen
vLLM#62304n-gram on Qwen3.5 (Gated DeltaNet), v0.31.0Wrong greedy output when drafts are partly accepted; GDN state misses the last accepted token; reproduced with weights insensitive to reduction orderbugopen
vLLM#54928DFlash2 on Qwen3.8-27B with thinking, TP4Diverges at generated token 30, including with K = 1 and --enforce-eagernot isolatedopen
vLLM#58973V2 speculative path, DFlash2 or DSpark drafters, Qwen3-4BThe first greedy token differs: target prefill picks a different RMSNorm autotune configurationnumerics (prefill path)open
vLLM#52071Pipeline parallelism with --no-async-schedulingWrong output or a CUDA fault; async scheduling avoids itbugopen
SGLang#45525DSPARK on DeepSeek-V4-FlashVerify and decode give different logits and next tokens for the same prefixnot isolatedopen
SGLang#49403EAGLE family with repetition_penalty ≠ 1Penalty applied to one token per verify stepdesignopen
SGLang#50395NGRAM with --enable-deterministic-inferenceOutput depends on earlier requests (shared n-gram corpus); EAGLE3 and no-spec are bit-identicalnumerics (tree layout)open
SGLang#43725NGRAM at temperature > 0, CUDAToken id 0 sampled far too often (0.538 instead of 0.0485 in the report) when the corpus has few candidatesbug (distribution)open
SGLang#39597DFLASH with FlashInfer autotuneGreedy output changes across server restarts; --disable-flashinfer-autotune fixes itnumericsopen

States read on 2026-11-18. A closed issue is not necessarily a fixed one: #27407 was filed as a documentation request with no fix claimed.

FAQ

Is speculative decoding lossless?
The algorithm is: with the standard acceptance rule, greedy output and the sampling distribution equal the target's. Implementations are lossless only up to floating-point rounding, which can flip near-tied tokens, and only when the speculative path has no bugs and no relaxed settings are on.
Why does my output change at temperature 0 when I turn on speculative decoding?
Most often a near-tie flipped because the verify pass computes several tokens at once with different rounding. Once one token differs, the rest of the greedy continuation differs too. If the baseline's token was clearly ahead at the first difference, suspect a bug instead.
Does n-gram speculation avoid the problem?
Not reliably. It adds no draft model, but the target still verifies in batches. In llama.cpp #25618 n-gram matched plain decoding on a Q4 target; in our CPU run an n-gram setup flipped one near-tie on Q4_0. vLLM #62304 and SGLang #50395 report n-gram-specific problems.
Does a low acceptance rate mean lower quality?
No. Acceptance affects speed only. Quality changes come from numerics, bugs or lossy settings, none of which show up in the acceptance rate.
Can I trust logprobs with speculative decoding on?
Check them. vLLM does not guarantee stable logprobs, and llama.cpp #27972 reports all-zero logprobs from llama-server with speculation. specdiff.py detects the all-zero case.

Limitations

Sources