How many GPUs does it take to serve an LLM?
Serving a large language model (LLM) means answering many users at once within latency targets: how long until the first token of an answer appears (time to first token), and how long each later token takes (time per output token). The number of GPUs needed follows from three things: how much memory each request needs, how long each forward pass takes, and how many requests arrive per second.
This case study plans a deployment for a 7-billion-parameter chat model from first principles. Every number is computed from the model's shape and an illustrative 80 GB GPU with 2 TB/s of memory bandwidth and 300 TFLOP/s of compute, the same accelerator used in the KV cache and continuous batching explainers. Each forward pass takes whichever is slower: the arithmetic, or reading its bytes from memory. This is the roofline model.
Key ideas
- Weights are loaded once per GPU, but every request keeps its own KV cache, so cache memory decides how many users one GPU can serve.
- Prefill is compute-bound and sets time to first token; decode is memory-bound and sets time per output token.
- Batching shares each read of the weights across many requests, raising throughput while each user's time per token rises slowly.
- The best batch is the largest one that fits in memory and keeps time per token under the target.
- Little's law turns a request rate and a latency into the number of requests in flight, which the fleet has to hold at once.
- When cache reads dominate a decode step, shrinking the cache (GQA, an int8 cache, shorter contexts) saves more GPUs than shrinking the weights.
Common questions
Why does a 7B model need more than one GPU if it fits in 13.5 GB?
The weights fit easily, but serving many users at once is limited by their KV caches and by time. At 1,000-token prompts and 300-token answers each request needs about 0.68 GB of cache, so about 85 fit beside the weights on an 80 GB GPU. Each GPU then answers about 6 requests a second within a 50 ms per-token target, so 50 requests a second needs about 11 GPUs with burst headroom.
What is the difference between time to first token and time per output token?
Time to first token is how long a user waits before the answer starts. It is dominated by prefill, the single pass over the whole prompt. Time per output token is the gap between later tokens, set by one decode pass over the current batch. Users notice the first as a delay and the second as reading speed.
How accurate are these numbers for a real deployment?
They show how a deployment scales, not exact figures for any vendor. The model assumes the ideal roofline (adjustable under Assumptions), an empty request queue, and that prefill does not stall decoding. Real servers reach a fraction of peak, so measure your own hardware and use the planner to see which change matters most.
Why does int4 quantization help less than grouped-query attention here?
At the default brief a decode step at the chosen batch reads about 13.5 GB of weights but about 51 GB of KV cache, so the cache dominates. int4 shrinks only the weights, from 13.5 GB to 3.4 GB. GQA with 8 KV heads cuts the cache four times, so each step reads far less and the GPU can hold four times as many requests.
Related explainers
- KV Cache — Why LLM generation caches keys and values, and what it costs
- Quantization — Shrinking model weights to 8 and 4 bits
- Continuous Batching — Serving many requests at once without idle slots
- Decoder-Only Transformers — The architecture behind GPT and modern LLMs
- FlashAttention — Exact attention with far less GPU memory traffic
- Speculative Decoding — Drafting tokens cheaply and verifying them in one pass
References
- Williams, Waterman, and Patterson (2009), "Roofline: An Insightful Visual Performance Model for Multicore Architectures", Communications of the ACM
- Little (1961), "A Proof for the Queuing Formula: L = λW", Operations Research
- Pope et al. (2022), "Efficiently Scaling Transformer Inference"
- Ainslie et al. (2023), "GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints"
- Touvron et al. (2023), "Llama 2: Open Foundation and Fine-Tuned Chat Models"
- Kwon et al. (2023), "Efficient Memory Management for Large Language Model Serving with PagedAttention"
Last updated