▤ BLOG/VLLM-SPECDECODE.TXT ×

I made vLLM's speculative decoding cost model 11× more accurate. It didn't necessarily make inference faster.

What happened when a substantially better GPU cost estimate met a greedy adaptive-verification policy, continuous batching, and a hard CUDA Graph boundary.

PROJECT LOG · LLM INFERENCE · VLLM / SPECULATIVE DECODING / CUDA

I've spent the last few weeks looking into vLLM's speculative decoding implementation, specifically how it decides how many draft tokens to verify. The interesting part? I managed to reduce the cost model's prediction error by around 11×, but when I actually tested it in serving, throughput sometimes got worse. Here's what I found.

Some background

Speculative decoding speeds up LLM inference by having a smaller draft model predict the next few tokens, which the larger model then verifies in a single forward pass. If all 5 draft tokens are accepted, you essentially generate 5 tokens for roughly the cost of one verification step. vLLM's DSpark implementation uses something called adaptive verification. The drafter proposes 7 tokens per request, but verifying all 7 isn't necessarily optimal.

Since tokens are accepted sequentially, the 7th token is only useful if the previous 6 are accepted. So instead of verifying everything, vLLM ranks the draft tokens by their probability of being accepted and chooses a verification budget that maximizes:

Expected accepted tokens / Estimated step cost

I was interested in the denominator. How accurately does vLLM actually estimate the cost of a verification step?

How vLLM estimates cost

Since vLLM can't know how long a step will take before executing it, it profiles the model at startup. For different token counts, it runs synthetic batches, measures their execution times, and stores the results in a lookup table. During serving, it uses this table to estimate the cost of different verification budgets.

The problem is that these synthetic batches assume every request has 8,192 tokens of history. Actual requests obviously don't all look like that. Some might have 300 tokens of context, while others might have 12,000. This matters because of the KV cache: during attention, the model needs to read the cached keys and values from previous tokens. Longer sequences mean more GPU memory traffic, even if the number of new tokens being verified stays the same. So I wanted to see how much error this fixed-history assumption introduces.

Benchmarking the cost model

I ran experiments on an H100 using vLLM 0.28, MiniCPM5-2B, and its DSpark drafter. With 32 requests, vLLM's lookup table predicted a step time of 6.66 ms, regardless of context length.

The actual measurements were quite different:

Context length Actual step time
512 tokens 3.25 ms
8,192 tokens ~6.66 ms
12,288 tokens 8.43 ms

The table was reasonably accurate around the context length it profiled, but significantly overestimated shorter contexts and underestimated longer ones. Fortunately, the relationship between execution time and total context length was approximately linear, so I used a simple correction:

Estimated time = table[n] + k × (actual history − profiled history)

Here, k represents the additional cost per token of cached history. For MiniCPM5-2B, I measured k ≈ 0.014 µs/token, which is close to what you'd expect from the size of the KV cache divided by the H100's memory bandwidth. With this one correction, the prediction error on held-out context lengths dropped by approximately 11×.

There was also a benchmarking mistake I made early on that was pretty interesting. Initially, I ran everything without CUDA graphs and couldn't observe any meaningful dependence on context length. Turns out the CPU overhead of launching hundreds of small GPU operations was hiding the memory-access cost I was trying to measure. Once I enabled CUDA graphs, the relationship became much clearer.

Did this improve serving throughput?

This is where things got interesting. I compared stock vLLM against the corrected cost model using paired serving benchmarks.

Concurrency Throughput change
64 requests −0.37%
64 requests, 64-token context −3.6%
128 requests +2.1%

At 128 concurrency, the corrected model won 17 out of 20 paired runs. So despite having a much more accurate cost model, I was actually making serving slower at lower concurrency.

The reason is that estimating cost accurately and making good scheduling decisions are two different problems. Adaptive verification is greedy: it chooses the budget that maximizes expected accepted tokens per unit of cost for the current step. With the corrected estimates, the policy sometimes selected smaller verification budgets. These were more efficient for the individual step, but they also meant that requests needed additional decoding steps to finish. The overhead of those extra steps could outweigh whatever was saved. In other words, optimizing the efficiency of each step doesn't necessarily optimize end-to-end throughput.

Why did it improve at 128 concurrency?

The improvement at 128 concurrency came from something else entirely: CUDA graph boundaries. vLLM captures CUDA graphs for steps with up to 512 tokens. Above that limit, execution falls back to eager mode, which is significantly slower. With 128 requests verifying 8 tokens each, the maximum verification batch is 1,024 tokens, well beyond the graph limit. The stock cost model consistently selected budgets above 512, while the corrected model selected exactly 512 tokens on roughly 25% of steps, allowing those steps to use CUDA graphs.

The difference was pretty substantial:

  • Corrected model at 512 tokens: ~7.7 ms per step
  • Stock model at ~971 tokens: ~18 ms median per step

So most of the 2.1% improvement wasn't because the model had a more accurate estimate of KV-cache costs. It was because the new estimates happened to push the policy across a very important execution boundary. This also suggests that the policy should explicitly account for CUDA graph boundaries rather than relying on a generic cost estimate to capture them.

What happened with the vLLM PR

I shared my measurements on vLLM issue #52057, which discusses improving the speculative decoding cost model and eventually supporting online cost estimation. Shortly afterwards, PR #62960 was opened with a similar context-length correction, along with two additional improvements.

1. Separating the cost of requests and draft tokens

Previously, the lookup table effectively priced each additional draft token as if it were an entirely new request with 8,192 tokens of history. But adding a draft token to an existing request is very different from adding a new request. The PR separates these costs, so the model can estimate the incremental cost of verifying additional draft tokens.

2. Explicitly accounting for the CUDA graph limit

Instead of hoping the estimated cost captures the performance cliff at 512 tokens, the policy models that boundary directly. This lets it decide whether verifying additional tokens beyond the graph limit is actually worth the extra execution cost.

During review, a code owner raised an interesting question: is the cost of verifying additional draft tokens actually linear? I ran another set of experiments to test this, varying the number of requests, tokens per request, and context lengths. For MiniCPM5-2B, an additional verified token generally cost around 2–5 µs, with very little dependence on context length. A linear approximation achieved a median error of just 0.9%. The worst errors, around 10%, came from discontinuities at specific token counts rather than general nonlinearity. For comparison, the original fixed-history cost model overestimated costs by 45–224% at short contexts. So the linear approximation looks pretty reasonable, at least for this model.

There was also another issue discovered during the PR discussion. The synthetic batches used to measure the incremental draft-token cost were being reconstructed incorrectly in current vLLM, which meant the resulting measurements were effectively the same across different request counts. Another contributor identified this, and a separate fix (#64878) addresses it. The current plan is to combine these changes in a follow-up PR. I'll also be benchmarking the combined implementation on a dense model at 128 concurrency, where the CUDA graph boundary should be particularly relevant.

A few things I learned

1. Benchmarking GPU workloads is surprisingly easy to get wrong. CUDA graphs, warmup order, and even GPU clock drift all affected my measurements at different points. At one point, I thought I had found a 28% performance improvement. After fixing the warmup procedure, that dropped to 0.21%. So before trusting a performance result, it's worth making sure you're actually measuring the execution regime you care about.

2. A better cost model doesn't automatically mean a better policy. This was probably the most interesting finding for me. Even if we could predict verification cost perfectly, a greedy policy could still make decisions that hurt overall throughput. The more interesting question now is whether we can improve the budget-selection policy itself, and how much additional performance is realistically available.

3. Contributing to open source doesn't necessarily mean starting with a PR. I initially just wanted to understand why the cost model was inaccurate. Posting the measurements led to a discussion with other contributors, additional experiments, and eventually changes being worked into the implementation. It's been pretty cool seeing how quickly an investigation can turn into something useful upstream.

All the benchmark scripts, measurements, and results are available here:

github.com/adixg/vllm-specdecode-cost-model