LLM Inference Optimization: Latency, Throughput and Memory
Inference performance is mostly memory movement, context management and careful batching.
Key takeaways
- LLM inference is dominated by memory movement, not raw compute — the model weights and the KV cache have to move through memory bandwidth for every token generated.
- Quantization, batching and KV cache management are the three levers with the biggest real-world impact, in that rough order of effort-to-payoff.
- Throughput and latency trade against each other — batching improves one at the cost of the other, and the right setting depends on whether you're serving one user or many.
- Speculative decoding can meaningfully cut latency, but only when the draft model is well-matched to the target model.
Why inference is a memory problem, not just a compute problem
Generating each token requires moving the model's weights (and the growing key-value cache) through memory to the compute units, once per token. For most consumer and even many production setups, the bottleneck is how fast that data can move through memory bandwidth, not how fast the arithmetic itself can be computed. This is why inference optimization looks so different from training optimization: the problem to solve is mostly "move less data, less often."
Quantization: the highest-leverage single change
| Precision | Relative size | Effect |
|---|---|---|
| FP16 / BF16 | Baseline | Full precision, largest memory footprint |
| INT8 | ~50% of FP16 | Small, usually negligible quality loss |
| INT4 (e.g. GPTQ, AWQ) | ~25% of FP16 | Noticeable but often acceptable quality trade for the memory savings |
Lower precision means less data to move per token, which directly reduces both memory footprint and, usually, latency. The quality cost has shrunk substantially with modern quantization methods — INT4 is now a reasonable production default for many use cases, not just a hobbyist compromise. See the local LLM VRAM guide for a concrete breakdown of quantization formats and what fits in a given memory budget.
The KV cache: the part everyone underestimates
The key-value cache stores intermediate attention state so the model doesn't recompute it for every previous token on every new token generated. It's essential for reasonable latency, but it grows linearly with context length and batch size, and it is frequently the actual reason a model that "fits" runs out of memory mid-generation. For the everyday version of the same limit, see why ChatGPT forgets things in long chats.
Watch out: a model's weights fitting in memory says nothing about whether a long conversation will fit. The KV cache for a long context can exceed the size of the model weights themselves, especially at larger batch sizes.
- Cap context length to what the use case genuinely needs — every unused token of context is wasted KV cache memory.
- Use paged attention (as in vLLM) where available — it manages KV cache memory in fixed-size blocks instead of one large contiguous allocation, dramatically reducing fragmentation.
- Evict or summarize old conversation turns for long-running sessions instead of keeping the entire history in the active cache.
Batching: throughput versus latency
Processing multiple requests together lets the GPU amortize the cost of loading weights across more tokens of output, which raises overall throughput. The trade-off is per-request latency: a request in a large batch may wait longer for its turn than it would running alone.
| Scenario | Batching approach |
|---|---|
| Interactive single-user chat | Small batch size, prioritize low latency |
| Bulk offline processing (summarizing many documents) | Large batch size, prioritize throughput |
| Multi-user production API | Continuous/dynamic batching — new requests join in-flight batches instead of waiting for a batch boundary |
Continuous batching (used by serving frameworks like vLLM and TGI) gets most of the throughput benefit of large static batches without forcing every request to wait for a batch to fill — it's the right default for a multi-user serving setup.
Speculative decoding, briefly
A small, fast "draft" model proposes several tokens ahead; the larger target model verifies them in a single pass instead of generating each one sequentially. When the draft model's guesses are frequently correct, this can meaningfully reduce latency, because verification is cheaper than sequential generation. The gain shrinks or disappears if the draft model's output diverges too often from what the target model would have generated.
A practical order of operations
- Quantize to INT8 or INT4 before anything else — it's the single highest-leverage, lowest-effort change.
- Cap context length to what the application actually needs.
- Use a serving framework with continuous batching and paged attention rather than a naive request-per-call loop.
- Only reach for speculative decoding once the above are in place and latency is still the bottleneck.
Inference performance is mostly memory movement, context management and careful batching — not a search for a faster GPU.
Every lever here trades something: quality for memory, latency for throughput, complexity for speed. There's no universal best setting — only the right trade-off for whether you're serving one interactive user or a queue of offline jobs.
Frequently asked questions
Why is LLM inference considered a memory problem?
Generating each token requires moving model weights and the KV cache through memory bandwidth, which is typically the bottleneck rather than raw compute throughput.
Does quantization hurt output quality?
Some, but modern INT4 methods keep the loss small enough that it is now a reasonable production default, not just a hobbyist compromise, for many use cases.
Why does batching increase latency for individual requests?
A request inside a larger batch may wait longer for its turn to be processed, even though the batch as a whole completes more total work per unit of time.