LLM Inference Acceleration in Practice: The Optimization Path from 40 to 120 tokens/s
This article explains why decoding speed is the core metric for local LLM deployment and how speculative decoding can deliver roughly 3x speedup, taking a ~27B parameter open-weight model from 40 to nearly 120 tokens/s. It breaks the technique into candidate recall, parallel verification, and accept-or-rollback, then examines the three variables that determine real gains: acceptance rate, draft cost ratio, and sampling consistency. You will also find a practical troubleshooting order covering baseline measurement, memory bandwidth checks, tuning draft length, output quality validation, batching and quantization, and stability, along with engineering notes on containerized deployment and evaluation.
1. The Starting Point: Why Speed Became the Core Metric for Local Deployment
When discussing open-weight models at roughly the 27B parameter scale, the question that comes up most often in the community is not about accuracy. It is “how many tokens/s do you get on your setup?” Behind that question is a long-underestimated fact: the time cost of autoregressive decoding is extremely unbalanced.
A complete text generation run can be split into two stages. The first stage is prefill, where the model processes the entire input prompt in parallel. This is compute-intensive and typically saturates the available compute. The second stage is decode, where generating each token requires moving all weights from VRAM to the compute units, making it memory-bandwidth-intensive. With a batch size of 1, the compute units sit largely idle, and the real bottleneck is VRAM bandwidth and weight reading.
This explains a common point of confusion: why a model with more parameters does not see a dramatically higher per-token time in single-request scenarios, yet the speed metric remains a persistent pain point for local experience. The answer is that the per-token cost in the decode stage is determined mainly by “reading the weights once” and has little to do with peak compute. So the first-principles approach to faster decoding is not to make matrix multiplications faster, but to make a single weight read produce multiple tokens.
2. Speculative Decoding: Turning “Generation” into “Recall + Verification”
The “it’s a lot like a search engine” analogy points directly to the core structure of speculative decoding. It can be broken into three actions.
The first step is candidate recall. A much smaller draft model guesses n candidate tokens in a row at very low cost. This step is cheap per unit, so it can tolerate a certain error rate; it is essentially a high-recall, low-precision initial filter.
The second step is parallel verification. The “1 confirmed token + n draft candidates” are concatenated into a sequence of length n+1 and passed to the target model for a single forward pass. Because the input of this sequence is already known, verification can be fully parallel, and one weight read yields probability distributions at all n+1 positions.
The third step is accept or roll back. Compare from front to back, truncate at the first position that is not accepted, resample one token from the target model’s distribution at that position as a correction, and end the round. If all n pass, the round directly produces n+1 tokens.
The logic can be sketched as:
# Pseudocode: one speculative decoding iterationdraft = draft_model.generate(prompt, n) # Cheaply recall n candidatesseq = prompt + draft # Sequence of length n+1 to verifylogits = target_model.forward(seq) # One parallel forward passaccepted = 0for i in range(n):if accept(logits[i], draft[i]): # Verify token by tokenaccepted += 1else:break# If all accepted, produce n+1; otherwise produce accepted + 1 corrected token
The key is the cost comparison: conventional decoding needs n+1 weight reads to produce n+1 tokens, while speculative decoding needs only 1 target model forward pass plus n cheap draft forward passes. When the draft is cheap enough and the acceptance rate is high enough, a 3x-level speedup from 40 tokens/s to nearly 120 tokens/s is a structurally expected result, not an accident of some particular implementation.
3. Three Variables That Determine the Actual Gain
The speedup ratio is not a fixed value. It is determined jointly by three variables, and understanding them matters more than memorizing any specific number.
The first is the acceptance rate α, the fraction of draft tokens approved by the target model. The higher α is, the more tokens each iteration produces on average. Ideally, with a draft length of n, the expected output is about (1-α^(n+1))/(1-α). This curve saturates quickly when α is low, which shows that blindly increasing n only burns compute for nothing.
The second is the draft cost ratio c, the ratio of the draft model’s per-step time to the target model’s per-step time. The smaller c is, the more worthwhile speculation becomes. If the draft model is too large, the time saved by verification is eaten up by the draft itself.
The third is sampling consistency. Comparison logic is simple under greedy decoding; once random sampling such as temperature and top-p is enabled, you must ensure the draft and target distributions are aligned correctly, otherwise output quality can silently degrade while the speed metric still looks good. This is the most easily overlooked pitfall in practice.
There are also several clever engineering additions worth noting: maintaining a separate key-value cache for the draft stage to avoid recomputation; using a layered draft head so candidate generation shares part of the representation with the target model; expanding candidates in a tree rather than a single chain, so one verification covers multiple possible paths; and dynamically adjusting n based on the real-time acceptance rate, staying conservative under low business load and aggressive in batch scenarios.
4. Raising the Speed: An Actionable Troubleshooting Order
Do not start by swapping implementations. First confirm where the bottleneck is. The recommended order is:
- Quantify the baseline first. Fix the prompt length and output length, and record first-token latency and steady-state tokens/s separately; they must be viewed apart, or the optimization direction will be wrong.
- Check VRAM and bandwidth usage. If VRAM bandwidth is nearly saturated while compute is idle during decode, it is indeed memory-bound, and speculative decoding is the right fix.
- Turn on speculative decoding and start with a small n, then gradually sweep n and draft model size, plot the “speedup vs. acceptance rate” curve, and find the inflection point rather than the maximum.
- Validate output quality. Compare the generation result distributions before and after enabling it on the same fixed set of prompts, and confirm no degradation was introduced by sampling inconsistency.
- Then consider batching and quantization. Continuous batching can significantly improve overall throughput but changes single-request latency characteristics; weight quantization reduces bandwidth pressure but requires evaluating accuracy loss.
- Finally, close out on stability. Wire load testing, metric collection, and alerting into the container platform and monitoring/alerting capabilities, and send logs uniformly to a logging service for long-cycle regression.
5. Engineering Recommendations for Deployment and Evaluation
In a general-purpose cloud environment, this kind of inference service is typically delivered in a containerized way: a container platform hosts elastic replicas, object storage distributes weight files, a message queue smooths request peaks, and logging and monitoring/alerting systems track four core metrics: first-token latency, steady-state throughput, acceptance rate, and VRAM usage. General-purpose capabilities from cloud platforms such as Baidu AI Cloud can serve as the foundation for this kind of load testing and online observation.
It is worth stressing that any tokens/s number is meaningful only with conditions attached: model size, quantization precision, context length, batch size, hardware VRAM bandwidth, and sampling parameters. Missing any one of them makes the numbers incomparable. The “3x speedup” circulating in the community is a reasonable expectation under a specific structure, not a promise. The truly reusable takeaway is the methodology: split generation into cheap candidate recall and expensive parallel verification, then use data to find the optimal parameter point for your own scenario.
