LLM Inference Optimization: From Bottleneck Analysis to a Systematic Approach
Learn why LLM inference is bound by memory bandwidth rather than compute, and explore a systematic map of optimization techniques—quantization, KV Cache compression, operator fusion, speculative decoding, continuous batching, and parallelism—along with a practical decision sequence for optimizing inference performance.
Why Inference Optimization Deserves Its Own Discussion
LLM inference optimization is a field easily buried under jargon. KV Cache, FlashAttention, speculative decoding, PagedAttention—each term alone could fill an article, and strung together they become overwhelming. This article assumes you know what a large language model is, understand the basic Transformer architecture, and have run some inference code, but lack a systematic picture of “how to make inference faster.” Our goal is not to dive into the implementation details of any single technique, but to map the entire landscape—so you know what problem each optimization solves and where it fits.
The Prerequisite: Figure Out Where the Slowness Comes From
Any performance optimization without first locating the bottleneck is guesswork. Training and inference have completely different bottleneck profiles, so training optimization experience cannot be applied directly.
The Fundamental Difference Between Training and Inference
The training bottleneck is primarily compute: forward passes compute the loss, backward passes compute gradients, and most time is spent on matrix multiplications that keep GPU compute units well fed. Inference is far more complex, especially in autoregressive generation.
The Two Phases of Inference
LLM inference typically runs in two phases with very different workload characteristics:
Prefill phase: The complete user prompt is fed into the model at once, and hidden states for all tokens are computed in parallel. Because input tokens can be fully parallelized, the matrix multiplications have large dimensions—this phase is compute-intensive, and GPU compute utilization is relatively high.
Decode phase: Tokens are generated one at a time. Producing each token requires reading the Key/Value cache of all previous tokens for attention computation. The per-step compute is tiny, but parameters and cache must be read and written repeatedly—this is a classic memory-bandwidth-bound workload.
A Counterintuitive Fact: The Bottleneck Is in Moving, Not Computing
For LLM inference, most of the time is spent not on computation but on data movement. A rough order-of-magnitude estimate makes this clear:
A typical high-end data center GPU delivers hundreds of TFLOPS of FP16 compute, but its memory bandwidth is only around 2 TB/s—a gap of several hundred times between the two.
A 7B-parameter model occupies about 14 GB of memory in FP16. During autoregressive generation, each new token theoretically requires reading all 14 GB of parameters from memory once. At 2 TB/s bandwidth, moving the parameters alone takes roughly 7 ms. In other words, even with infinite compute, simply “reading the parameters” caps generation speed at roughly 140 tokens per second. Factoring in KV Cache reads/writes plus scheduling and kernel launch overhead, actual throughput is even lower.
This is the core tension of inference optimization: the GPU spends most of its time waiting for data, not computing on it.
Two Main Optimization Paths
With the bottleneck understood, all optimization techniques fall into two categories: reducing the amount of data that must be moved, and moving data more efficiently while overlapping compute with movement.
Path One: Reduce the Data to Move
Model Quantization
Quantization is one of the most cost-effective techniques. The idea is to represent weights and activations with lower-precision numbers:
- FP16/BF16: Directly halves memory footprint and data movement versus FP32;
- INT8: Halves parameter size again, typically paired with calibration (e.g., techniques that smooth activation distributions) to preserve accuracy;
- INT4 and below: Combined with group quantization and outlier handling, a 7B model can be compressed to around 4 GB, delivering multi-fold speedups with acceptable accuracy loss in many scenarios.
The essential benefit of quantization is not just saving memory—it proportionally cuts the “parameter traffic” required per token, directly hitting the Decode phase’s bandwidth bottleneck.
KV Cache Compression
The KV Cache grows linearly with sequence length and, in long-context scenarios, can even exceed the parameters themselves. Common compression approaches include:
- Multi-Query Attention (MQA) / Grouped-Query Attention (GQA): Multiple query heads share the same set of KV heads, shrinking the KV cache to a fraction of its original size;
- Cache quantization and sparsification: Store the cache in lower precision, or retain cache entries only for key tokens;
- Attention architecture modifications like sliding windows: Limit the context range that must be retained.
Pruning and Distillation
Structured pruning removes unimportant attention heads or layers; unstructured pruning, combined with sparse computation, reduces actual computation and storage. Knowledge distillation uses a small model to approximate a large model’s output, reducing the data to move at the root.
Path Two: Move Data More Efficiently and Overlap Compute with Movement
Operator Fusion
A single forward pass involves many small operators (LayerNorm, activations, bias additions, etc.), each reading and writing intermediate results once—fast to compute but fragmented in data movement. Operator fusion merges multiple operations into a single kernel, keeping intermediate results in registers or shared memory and dramatically reducing round trips to memory. FlashAttention-style techniques exemplify this idea: by computing attention in tiles, they avoid writing the huge attention matrix to memory and reduce IO volume.
Efficient KV Cache Management
Traditional implementations pre-allocate the cache to the maximum length, causing severe waste and fragmentation. Paged management splits the cache into small blocks allocated on demand, and with Copy-on-Write mechanisms, the same memory can serve far more concurrent requests, greatly boosting system throughput. This is now a standard capability of inference serving frameworks.
Speculative Decoding
The approach uses “small model drafts, large model verifies”: the small model generates multiple candidate tokens in one go, and the large model verifies them in parallel with a single forward pass. Since the data-movement cost of verifying multiple tokens is nearly identical to verifying one (parameters are read only once), effective Decode throughput can increase several-fold while preserving the output distribution. The speedup depends on how well the small model’s distribution matches the large model’s.
Continuous Batching and Scheduling Optimization
Traditional static batching requires all requests in a batch to start and finish together, so short requests get dragged down by long ones. Continuous batching lets new requests join at any time and finished requests exit at any time, keeping GPU utilization high. Additionally, hybrid Prefill/Decode scheduling (e.g., chunked prefill) prevents long-prompt computation from blocking other requests’ generation.
Parallelism Strategies
For models too large for a single GPU, tensor parallelism, pipeline parallelism, and similar strategies are needed. Tensor parallelism splits weight matrices across multiple GPUs but adds communication overhead, requiring a trade-off between partition granularity and communication cost. During the Decode phase—where compute is small and communication dominates—the choice of parallelism strategy is especially sensitive for latency.
A Simplified Decision Guide
In practice, work through the following sequence:
- Measure the bottleneck first: Use profiling tools to confirm whether you are compute-bound or bandwidth-bound;
- Apply quantization early: INT8/INT4 can usually be deployed quickly with immediate gains;
- Check KV Cache management and batching: Confirm that paged caching and continuous batching are in use;
- Enable operator fusion and efficient attention implementations: Reduce IO round trips;
- Evaluate speculative decoding for long-output scenarios: Clear latency benefits for latency-sensitive online services;
- Finally, tune system-level parallelism and scheduling: Carefully optimize communication and placement in multi-GPU deployments.
Conclusion
Every LLM inference optimization technique ultimately answers one of two questions: Can we move less data? Can we move data faster and overlap movement with computation? Quantization, KV Cache compression, and pruning belong to the former; operator fusion, speculative decoding, continuous batching, and parallel scheduling belong to the latter. With this map in hand, you can quickly locate any specific optimization in the overall system and judge whether it is valuable for your scenario. Optimization has no silver bullet, but it has a methodology—measure the bottleneck first, then apply the right remedy. That is the proper path of performance engineering.
