Accelerating Inference for 10B-Scale LLMs: A Practical Path to 120 tokens/s
This article explains how speculative sampling and system-level engineering optimizations can boost inference throughput for large language models with tens of billions of parameters (such as 27B models) from around 40 tokens/s to nearly 120 tokens/s. It covers the memory-bandwidth bottleneck of autoregressive generation, the draft-and-verify mechanism of speculative sampling, acceptance strategies, and supporting techniques such as KV cache management, operator fusion, continuous batching, and cloud-native deployment practices.
Accelerating Inference for 10B-Scale LLMs: A Practical Path to 120 tokens/s
As large language models with tens of billions of parameters (such as 27B-scale models) are deployed across increasingly complex business scenarios, inference latency has become a critical bottleneck for both user experience and system throughput. Under the traditional autoregressive generation paradigm, every token requires a full forward pass through the model. This serial computation pattern leaves the GPU’s parallel compute capacity underutilized, and generation speed often plateaus at around 40 tokens/s. This article explores how speculative sampling, combined with a series of system-level engineering optimizations, can push inference speed close to 120 tokens/s.
1. The Bottleneck of Traditional Inference and the Way Out
In standard autoregressive generation, an LLM predicts the next token conditioned on all previously generated tokens. For a model at the 27B scale, each forward pass requires loading massive weight matrices and performing dense matrix multiplications. However, the memory bandwidth of modern GPUs is typically far lower than their peak compute capacity. As a result, when generating a single token, most of the time is spent reading weights and the KV cache from memory, while the compute units sit “starved.” This memory-bound characteristic is the fundamental reason behind the baseline performance of roughly 40 tokens/s.
To break through this bottleneck, the industry has adopted speculative sampling, a technique analogous to the “retrieve-and-rank” mechanism used by search engines. A search engine typically uses a lightweight algorithm to quickly recall a large pool of candidate pages, then applies a complex model for precise ranking. LLM inference can borrow the same idea: let a small model rapidly “recall” candidate tokens that are likely correct, then let the large model “verify” them all at once—dramatically improving inference efficiency.
2. A Deep Dive into Speculative Sampling
The core of speculative sampling lies in introducing a small, fast Draft model alongside the original Target model (the large model). The workflow proceeds as follows:
- Rapid candidate generation by the small model: Given the current context, the Draft model quickly generates n candidate tokens at very low latency. Because the Draft model is small, its generation speed far exceeds that of the Target model. Although the small model is less accurate and may produce errors, it provides a candidate window that has a high probability of containing the correct tokens.
- Parallel verification by the large model: Instead of verifying the n tokens one by one, the Target model leverages the GPU’s parallel compute capability to run a single forward pass over all n candidate tokens. In this process, the Target model outputs the true probability distribution at each of the n positions and simultaneously computes its prediction for token n+1.
- Accept and reject strategy: The system compares the probability distributions of the Draft model and the Target model at each position. If the Draft model’s prediction at a given position is accepted by the Target model, that prediction is considered correct. If a rejection occurs at position k, the first k-1 correct tokens are retained, the Target model’s actual prediction at position k is used as the final result, and the remaining candidates are discarded.
- Recomputation and iteration: Once a rejection occurs, the Draft model restarts candidate generation from the acceptance point, beginning a new round of the speculative sampling loop.
Through this “guess-and-verify” mechanism, if the Draft model’s guesses are accurate enough, a single forward pass of the Target model can yield n+1 tokens. Even when some rejections occur, as long as the overall acceptance rate stays within a reasonable range, the average cost of each large-model forward pass is significantly amortized.
3. The Leap from 40 to 120 tokens/s
Raising inference speed from 40 tokens/s to nearly 120 tokens/s represents a threefold increase in system throughput. This leap is driven primarily by optimizations along the following dimensions:
First, higher compute density. With speculative sampling, a single forward pass of the large model verifies n tokens instead of predicting just one. This effectively transforms a memory-bound workload into a compute-bound one, substantially improving the utilization of GPU Tensor Cores. Although the compute per forward pass increases slightly, the added time is far less than the cost of running multiple serial forward passes to generate n tokens.
Second, lower average latency. Suppose the Draft model generates a candidate sequence of length 4 (i.e., n=4). As long as the Target model accepts more than 2 of them, the overall generation speed exceeds that of the traditional mode. In practice, a well-trained Draft model typically maintains a high acceptance rate, enabling an end-to-end speedup approaching 3x.
4. Sophisticated Engineering Optimizations
Beyond speculative sampling itself, sustaining peak performance at 120 tokens/s requires a series of deep optimizations at the engineering level:
- Dynamic KV cache management: As sequences grow longer, the KV cache’s memory footprint increases linearly. The system needs to implement memory-paging techniques such as PagedAttention to reduce memory fragmentation, support longer context windows, and avoid the overhead of frequent memory allocation and deallocation.
- Operator fusion and low-level optimization: By fusing multiple operators within the Attention computation and the feed-forward network (FFN), intermediate results are kept out of memory as much as possible. Introducing optimized algorithms such as FlashAttention leverages SRAM to cache local computation results, further reducing memory bandwidth pressure.
- Continuous batching: In high-concurrency server scenarios, Continuous Batching dynamically adjusts the number of requests in each batch. When certain requests in a speculative sampling round finish early due to rejections, the system can immediately schedule other waiting requests to fill the gaps, keeping the GPU fully loaded at all times.
5. Deployment and Operations in Cloud-Native Environments
In real-world enterprise deployments, the stability and elasticity of LLM inference services are equally important. Under general-purpose cloud-native architectures such as those offered by Baidu AI Cloud, developers can build highly available inference services on top of container platforms and elastic compute resources.
By containerizing the optimized inference engine described above and combining it with the cloud platform’s load balancing services, teams can effectively handle traffic peaks and valleys. At the same time, integrating logging services and monitoring/alerting systems enables real-time collection and analysis of key metrics such as GPU utilization, memory usage, and tokens/s. If performance degradation occurs due to hardware failures or traffic surges, the system can automatically trigger elastic scaling to keep the overall service running smoothly at the high-performance level of 120 tokens/s.
6. Conclusion
Optimizing LLM inference speed is a systems engineering effort. By introducing speculative sampling and cleverly orchestrating the collaboration between small and large models, the inference speed of 10B-scale models such as 27B can be raised dramatically from 40 tokens/s to 120 tokens/s. Combined with low-level techniques like operator fusion, KV cache management, and continuous batching—along with elastic deployment on mature infrastructure such as Baidu AI Cloud—developers can deliver smooth, efficient LLM-powered experiences to end users. As algorithms and hardware continue to evolve, there remains significant room for further gains in LLM inference efficiency.
