Speeding Up Large Model Inference on 8 GPUs with Speculative Decoding
This article explains why autoregressive decoding is slow, how speculative decoding accelerates it without changing output distributions, and how to estimate the speedup with a simple formula. It covers test results on 8 GPUs with tensor parallelism for single-concurrency latency and 64-concurrency throughput, along with practical guidance on draft model selection, speculation length, memory budgeting, scheduler integration, and evaluation methodology.
1. Why Autoregressive Decoding Is Slow
Large language models generate text token by token. For every token produced, the model executes a full forward pass, reading all model weights and the historical KV cache. On models with large parameter counts, this step is primarily limited by memory bandwidth, and the compute units spend most of their time waiting. As a result, the generation speed of a single request is governed by the token-by-token execution pace, and available compute is hard to fully utilize even when hardware capacity is abundant.
This bottleneck is most visible in single-concurrency scenarios. As concurrency increases, batching amortizes the cost of weight reads and total system throughput rises. However, per-request latency is still determined by the sequential token generation pace; higher concurrency does not directly shorten the wait time of an individual request.
2. How Speculative Decoding Works
The idea behind speculative decoding is straightforward: use a low-cost draft mechanism to guess several future tokens, then let the target model verify all guesses in a single pass. One forward pass of the target model evaluates multiple positions simultaneously. Correctly guessed tokens are accepted directly; the first wrong position and all candidates after it are discarded, and a corrected token is resampled from an adjusted distribution.
Each round of generation has three steps:
- Draft phase: the draft mechanism generates k candidate tokens based on the current prefix. The draft can be a smaller standalone model or a lightweight head sharing part of the target model’s structure.
- Verification phase: the target model runs one forward pass over the prefix concatenated with the k candidates, producing output distributions for k+1 positions.
- Acceptance phase: candidates are compared left to right. A candidate is kept if accepted under the target distribution; the process stops at the first rejection, where a replacement token is sampled from the residual distribution. If all candidates pass, an additional bonus token is sampled.
Under sampling-based decoding, this rejection sampling mechanism guarantees that the output distribution matches the target model’s own distribution, so the method is generally considered lossless acceleration. This guarantee depends on strict implementation correctness and should still be verified through controlled testing in practice.
The following sketch shows the core logic of one speculative decoding round, omitting batching and KV cache management:
import randomdef sample(probs):"""Sample a token index from a probability distribution"""r, acc = random.random(), 0.0for idx, p in enumerate(probs):acc += pif r < acc:return idxreturn len(probs) - 1def residual_sample(p, q):"""Sample from the normalized max(0, p - q) distribution, used for correction after rejection"""diff = [max(0.0, pi - qi) for pi, qi in zip(p, q)]total = sum(diff)if total == 0:return sample(p)return sample([d / total for d in diff])def speculative_step(target, draft, prefix, k):# 1. Draft phase: generate k candidate tokens with their full distributionsdraft_tokens, draft_probs = draft.generate(prefix, num_tokens=k)# 2. Verification phase: one forward pass yields target distributions for k+1 positionstarget_probs = target.forward_probs(prefix + draft_tokens)# 3. Acceptance phaseoutput = []for i, tok in enumerate(draft_tokens):p, q = target_probs[i], draft_probs[i]if random.random() < min(1.0, p[tok] / q[tok]):output.append(tok)else:output.append(residual_sample(p, q))return output# If all candidates are accepted, sample a bonus token from the last position's distributionoutput.append(sample(target_probs[k]))return output
The acceptance rate is the probability that an individual candidate token is accepted. Assuming the acceptance probability is approximately the same across positions, denoted α, the expected number of tokens produced per round is:
E = (1 - α^(k+1)) / (1 - α)
3. How to Compute the Speedup
The cost of one round consists of one target model forward pass plus k draft computations. If the per-step cost of the draft is c times that of the target model, using the target’s per-step time as the unit, one round takes roughly 1 + k·c. This gives an approximate speedup estimate:
S ≈ E / (1 + k·c)
This formula says three things. First, the higher the acceptance rate, the greater the benefit. Second, the cheaper the draft, the greater the benefit. Third, the speculation length k has an optimal value. When k is too large, the draft overhead and the waste from rejected candidates cancel out the gains.
def estimate_speedup(alpha, k, cost_ratio):"""alpha: acceptance rate; k: speculation length; cost_ratio: per-step draft cost relative to the target model"""expected_tokens = (1 - alpha ** (k + 1)) / (1 - alpha)cycle_cost = 1 + k * cost_ratioreturn expected_tokens / cycle_cost# Example: acceptance rate 0.8, speculation length 4, draft cost 5% of the targetprint(round(estimate_speedup(0.8, 4, 0.05), 2)) # roughly 2.8
This example only illustrates the formula and does not represent the results of any specific test.
4. Test Setup and Interpreting the Results
The main conditions of this test were as follows:
- Hardware: 8 data-center GPUs with tensor parallelism, parallelism degree 8.
- Context: 32k tokens of low-entropy text. Low entropy means the token distribution is concentrated and highly predictable, such as code, templated reports, structured data, and repetitive paragraphs. In this kind of content the draft is more likely to guess correctly, so the acceptance rate is higher.
- Metrics: single-concurrency decoding speed and total throughput at 64 concurrent requests.
Results:
| Metric | Native Autoregressive Decoding | Speculative Decoding | Change |
|---|---|---|---|
| Single-concurrency decoding speed | ~84.5 tokens/s (derived from the speedup ratio) | 288.2 tokens/s | ~3.41x |
| Total throughput at 64 concurrency | ~420 tokens/s (derived from the improvement percentage) | 608.71 tokens/s | +44.9% |
The two sets of numbers should be interpreted differently:
- In the single-concurrency scenario, the speedup mainly manifests as lower per-request latency. Multiple tokens are produced per round, reducing the number of token-by-token waits, so the acceleration is significant.
- In the 64-concurrency scenario, batching already keeps the compute units fairly busy. Drafting and verification consume extra compute, and rejected candidates waste computation, so the benefit narrows relative to single concurrency. Total throughput still improves by 44.9%, showing that speculative decoding delivers a positive gain under this configuration.
- The two numbers are not directly comparable. 3.41x is the per-request speedup, while 44.9% is the improvement in total system throughput. Averaged across 64 concurrent requests, each request gets about 9.5 tokens/s, versus roughly 6.6 tokens/s natively.
- The raw data only provides the results above; the internal implementation of the draft strategy, acceptance rate distribution, and per-round statistics were not disclosed. Therefore, this article only analyzes the formula-level behavior and does not infer implementation details.
5. Engineering Considerations
5.1 Choosing a Draft Strategy
Common draft approaches fall into three categories: using a standalone small model; sharing the target model’s backbone and training additional prediction heads; or predicting multiple future tokens in parallel within a single forward pass. Each involves trade-offs in memory footprint, training cost, and acceptance rate. A standalone small model is simple to deploy but consumes extra memory, and its distribution alignment with the target model directly affects the acceptance rate. Backbone-sharing approaches have lower memory overhead and usually higher acceptance rates, but require additional training.
5.2 Determining the Speculation Length k
A larger k means more tokens can potentially be accepted per round, but draft cost and waste grow accordingly. A recommended practice is to run an offline sweep first, for example across values from 2 to 8, measuring throughput on a request distribution similar to production, then pick the optimum. The optimal k may differ across concurrency levels, so it can be adjusted dynamically based on load.
5.3 Memory and KV Cache
Both the draft mechanism’s weights and its extra KV cache consume GPU memory, which is especially noticeable in long-context scenarios. Tensor parallelism across 8 GPUs splits the target model’s weights, but the draft component must also be included in the memory budget. Before deployment, estimate the sum of: model weights, draft weights, per-request KV cache multiplied by maximum concurrency, and runtime buffers, and confirm there is sufficient headroom.
5.4 Integration with the Scheduler
Speculative decoding makes the number of tokens produced per step variable, so the scheduler must maintain request state accordingly, including stop-token detection, streaming output, and timeout handling. With streaming, one round may return multiple tokens at once, and the frontend must be able to concatenate them correctly.
6. Evaluation Methodology
Evaluation should cover four categories of metrics:
- Per-request latency and single-concurrency speed: reflects interactive experience.
- Total throughput: reflects service capacity.
- Acceptance rate and average tokens produced per round: reflects draft quality and helps diagnose issues.
- Output quality: under sampling decoding, compare the output distribution against the target model; under greedy decoding, check whether outputs match token by token.
Controlled experiments should satisfy these conditions: same hardware, same model version, same input set, same concurrency policy, with only speculative decoding toggled on or off. The input set should match the production distribution, and results for low-entropy and high-entropy text should be reported separately. Otherwise, aggregate numbers can easily be overestimated.
The following code computes per-position acceptance rates, which helps judge whether the speculation length is appropriate:
def per_position_acceptance(accept_counts, k):"""accept_counts: number of consecutive accepted draft tokens per round, ranging from 0 to kReturns: a list of length k; the i-th item is the acceptance ratio at draft position iamong rounds that reached that position"""rates = []for i in range(k):reached = sum(1 for a in accept_counts if a >= i)accepted = sum(1 for a in accept_counts if a >= i + 1)rates.append(accepted / reached if reached else 0.0)return ratesdef tokens_per_round(accept_counts):"""Tokens actually produced per round equal accepted drafts plus 1 (resampled or bonus token)"""return sum(a + 1 for a in accept_counts) / len(accept_counts)
If acceptance rates at earlier positions are significantly higher than at later ones, a smaller k is likely more economical. If acceptance is high across all positions, increasing k is worth trying.
7. Where It Works and Where It Doesn’t
- High-benefit scenarios: single-user interaction, code completion, structured output, templated long-document continuation, and latency-sensitive low-concurrency services.
- Limited-benefit scenarios: high-entropy creative content, open-ended dialogue, and high-concurrency services where compute is already near saturation.
- Cases requiring caution: when the draft and target model versions are mismatched, the acceptance rate drops noticeably. After upgrading the target model, acceptance rate and throughput need to be re-measured.
8. Summary
The benefit of speculative decoding depends on draft quality and load conditions. The speedup is most pronounced in single-concurrency scenarios and narrows at high concurrency. Before going live, run controlled tests on real traffic while recording acceptance rate, latency, and throughput, and use these metrics to determine the speculation length and deployment configuration.
