How Many GPUs Do You Need to Serve an LLM?
You have a model and some serving constraints to meet. How many GPUs does it take to serve? You can answer that on a napkin, using numbers you already know. It comes down to two questions.
Does it fit? The weights and the KV cache have to live in GPU memory. This is the easy one, and where most people stop.
Can it keep up? The GPUs have to push tokens fast enough to hit your rate without missing the latency target. This is where the GPU count usually comes from.
The Answer in One Line
Call the three bills memory, prefill, and decode. The model has to fit, and it has to keep up:
| Bill | Question | Bottleneck |
|---|---|---|
| Do weights and KV cache fit? | GPU memory capacity | |
| Can we process prompts fast enough? | FLOPs | |
| Can we generate tokens fast enough? | HBM bandwidth |
For the running example below, Qwen3-8B on H200s at 2 req/s with 4K input and 1K output, the bills come out to about 0.7 cards to fit, 0.3 for prefill, and 0.5 for decode. That rounds to one H200. Push the same workload to 20 req/s and it becomes about eight.
What You Need
You need three groups of inputs:
- Model: total parameters , active parameters , precision, and attention architecture.
- Hardware: memory per GPU , bandwidth , and peak compute .
- Demand: request rate , input length , output length , and TPOT target.
is equal to for a dense model. For an MoE, is the total resident parameter count, while is the active parameter count per token. Precision sets bytes per parameter: 2 for bf16, which we use throughout, or 1 for fp8.
For hardware, an H200 has 141 GB of HBM, 4.8 TB/s of bandwidth, and about 990 dense bf16 TFLOPS [1]. The datasheet's larger bf16 number assumes sparsity; for dense weights, use half.
TPOT means time per output token. In the examples below, the decode SLO is 50 ms/token. If the model writes 1,000 output tokens, that is a 50 second decode window.
The running anchor is the case I'll carry through the memory, prefill, and decode bills, before varying the parameters at the end:
Two Questions, Three Resources
The two questions turn into three resource bills. Does it fit? is about capacity: the weights and the live KV cache have to sit in GPU memory at the same time. Can it keep up? is about throughput, but generation does not have a single bottleneck from start to finish.
Prefill reads the prompt all at once, runs large matrix multiplies, and is compute-bound [8]. Decode writes one token at a time. Serving engines batch many streams together, but each decode step still streams weights and KV cache from HBM, so decode is bandwidth-bound [10]. That split is why the final count has one memory bill and two throughput bills.
Step 1: Does It Fit?
Capacity has two parts: the weights, which are fixed, and the KV cache, which grows with the number of live tokens. Start with the fixed part.
The Weights
The weights are the easy part. Multiply parameters by bytes per parameter:
Here, is bytes per parameter. Qwen3-8B is 16 GB at bf16, and the 30B-A3B MoE is 60 GB. That MoE number uses the total parameter count, not the 3B active count, because every expert has to be resident even though a given token routes through only a few.
The KV Cache
The KV cache is the term you cannot read off the model's parameter count. During generation, each token's keys and values are stored so later tokens can attend to them. The bytes per token depend on the attention design: number of layers, KV heads, head dimension, and precision.
For standard grouped-query attention [2], the expression includes both keys and values. The per-token cache is:
The leading 2 is for keys and values. So yes, the KV-per-token number can be calculated, but you need architectural details: layer count, number of KV heads, head dimension, and dtype. If the model uses a hybrid or compressed attention scheme, use its actual cache layout instead of this standard-GQA formula.
Qwen3's dense line is a clean example: 8 KV heads and head dim 128 across sizes. That is 4 KB per layer at bf16 [6]. The cache is then 4 KB times the layer count. The 8B has 36 layers, so 144 KB per token; the 0.6B has 28 layers, so 112 KB. Despite a more than 10x parameter gap, their KV caches are in the same ballpark.
However, nobody keeps layer counts in their head, so a rule of thumb helps. For standard dense GQA at bf16, the table below gives a ceiling; use it for any model whose attention you have not checked.
| Model size | KV cache per token |
|---|---|
| 0.6B | ~112 KB |
| 8B | ~144 KB |
| 32B | ~256 KB |
| 72B | ~320 KB |
The table is per token; multiply it by average sequence length and requests in flight to get total KV bytes in memory [4]:
Concurrency comes from Little's Law: requests in flight equal rate times latency. For generation, napkin latency is output tokens times TPOT; add prefill and queueing if those are meaningful fractions of your SLO:
For the anchor, TPOT is 50 ms and , so each request occupies the system for about 50 seconds. At 2 req/s, Little's Law gives 100 requests in flight. The average sequence length during decode is:
Qwen3-8B has 16 GB of bf16 weights and a standard-GQA cache of 144 KB/token, so:
The memory you need to fit is weights plus KV cache, with about 15% extra for CUDA context, fragmentation, and activation buffers:
Dividing by 141 GB of H200 memory gives the fit bill:
Step 2a: Prefill Is a Compute Bill
Prefill reads the prompt. Every input token is processed together in one large matrix-multiply batch, so compute units stay saturated and the phase is compute-bound [8]. That makes the GPU bill a FLOP budget: demand is rate times tokens-per-request times FLOPs-per-token, and supply is MFU times peak compute , with MFU [8].
The per-token cost has two terms. The weight term () is one multiply-add per active parameter. The attention term () comes from scoring each query against every prior key and summing weighted values across all layers:
For Qwen3-8B (, ), the weight term is 16B FLOPs/token and the attention term adds 2.4B at a 4K prompt:
Below the weight term dominates and ; above it, attention takes over and total prefill compute scales as . That crossover is roughly 6K tokens for a 0.6B model, up to 50K for 72B.
Step 2b: Decode Is a Bandwidth Bill
Decode writes the answer one token at a time. Each output token depends on the one before it, so a single request cannot be parallelised across time. Serving systems recover parallelism by batching requests instead, so one decode step advances active streams by one token.
Each decode step streams bytes from HBM. It reads the weights once across the batch, and it reads the KV cache once per stream. The arithmetic is small compared to this traffic, so decode is usually bandwidth-bound [10].
A single GPU has usable bandwidth , where MBU is model-bandwidth utilization. We use MBU [9]. But the latency target has first claim on that bandwidth: to produce one token every seconds, the card has to read bytes of weights, consuming bandwidth. Subtract that fixed weight read from usable bandwidth to get what remains for KV traffic:
With request rate , output length , average context , and per-token cache , the decode bill is:
For Qwen3-8B, and . On an H200, usable bandwidth is , and the weight read consumes :
If approaches , the GPU cuont explodes. We cannot hit the TPOT target without splitting the model across GPUs to shrink the per-GPU weight read (and each split adding all-reduce network overhead per step).
MoE models trip people up here. A 30B-A3B serves like a 3B model in prefill because only 3B parameters activate per token. Decode does not get the same discount. It is bandwidth-bound: what matters is bytes streamed from HBM per step, not FLOPs. All experts have to live in memory, and under load different requests pull different expert subsets simultaneously. By the time the batch is served, nearly the full pool has been read.
Step 3: Combine the Bills
Now take the larger of the memory bill and the throughput bill.
For our example, Qwen3-8B at 2 req/s, 4K input, 1K output, and 50 ms TPOT is a one-card H200 job before operational margin. The three bills collapse to:
The workload shape determines which compute term leads. Long prompts and short answers, like RAG, coding, multi-turn chat, and agents, push prefill up. Long outputs push up and shift the cost into decode and the KV cache, as in reasoning models and long-form generation.
Run the Napkin
If you want to adapt this to your own workload, start here. The script below uses the same formulas as the walkthrough. Change the constants at the top for your model, hardware, and traffic shape; it prints the memory, prefill, decode, and final bills separately, not just the rounded GPU count.
Turning the Knobs
We demonstrated the mechanics through the working example. Now we change one input at a time and watch which bill moves. Each case below is one constant changed at the top of the script.
Raise the rate. Keep the dense 8B and the 4K-in, 1K-out shape, but push demand from 2 to 20 requests/sec. The load-dependent terms scale almost linearly: prefill grows to about 3 H200s, decode to about 5, and the KV-heavy fit floor to about 6.
Change the shape. Back to 2 requests/sec on the dense 8B, but vary the request shape. With 16K-token prompts and 1K-token answers, prefill rises because the prompt is longer, and decode rises because the average context is now 16.5K tokens. The bills are about 2 H200s for fit, 1.6 for prefill, and 1.9 for decode, so the answer is roughly four cards.
With 8K-token prompts and 8K-token answers, prefill is still under one H200, but decode jumps to about 11. Every one of the 8,000 output tokens rereads a cache averaging 12K tokens. The resident KV cache also grows to roughly the same size, so the answer is about 12 cards, with decode and KV cache as the binding terms.
Swap the model. Return to the original 2 requests/sec, 4K-in, 1K-out workload, but trade the dense 8B for Qwen3-30B-A3B. The MoE moves two numbers in opposite directions.
For prefill, 4K tokens sit well below the attention crossover for this model, so :
Decode does not get that discount. Under load the batch touches nearly the full expert pool, so the weight-read term uses all 60 GB:
The MoE buys cheap prefill, not a cheap decode budget. That pays off most for multi-turn chat, where each turn re-sends the full transcript: climbs with the conversation while per turn stays short.
The cases line up like this; the bottleneck changes with traffic shape:
| Model | RPS | In / Out | Answer | Bottleneck | |||
|---|---|---|---|---|---|---|---|
| 8B | 2 | 4K / 1K | ~0.7 | ~0.3 | ~0.5 | 1 | rounds up to 1 |
| 8B | 20 | 4K / 1K | ~6 | ~3 | ~5 | ~8 | decode throughput |
| 8B | 2 | 16K / 1K | ~2 | ~1.6 | ~1.9 | ~4 | prefill (long input) |
| 8B | 2 | 8K / 8K | ~11 | ~0.7 | ~11 | ~12 | KV + decode (long output) |
| 30B-A3B | 2 | 4K / 1K | ~1 | ~0.1 | ~0.8 | ~1 | weights (MoE) |
A Floor, Not a Target
You now have an answer to both questions: the weights and KV cache fit on cards; throughput demands at least plus cards. Treat that result as a floor, not a target.
Real deployments usually land 20 to 30 percent higher. MFU sags under load, prefill and decode compete for bandwidth on shared cards, and tensor parallelism eats into both. The napkin gets the order of magnitude and names the bottleneck; a benchmark against your actual traffic tightens the number before you commit hardware.
References
- NVIDIA. H200 Tensor Core GPU. Datasheet, 2024. 141 GB HBM3e, 4.8 TB/s. The datasheet quotes 1,979 bf16 TFLOPS, but that number assumes 2:4 sparsity; dense weights run at half, so we use ~990 TFLOPS throughout.
- Ainslie et al. GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints. arXiv:2305.13245, 2023. EMNLP 2023.
- Gated DeltaNet (Yang et al., ICLR 2025), the hybrid attention in Qwen3.5, and multi-head latent attention (DeepSeek-V2), the compressed-cache design. Both shrink the KV cache below standard attention, never above it.
- Kwon et al. Efficient Memory Management for Large Language Model Serving with PagedAttention. arXiv:2309.06180, 2023. SOSP 2023.
- Williams, Waterman, and Patterson. Roofline: An Insightful Visual Performance Model for Floating-Point Programs and Multicore Architectures. Communications of the ACM, 2009.
- Qwen Team. Qwen3 and Qwen3.5 model cards. HuggingFace, 2025–2026. Layer counts, KV-head, and head-dimension values for the 0.6B/8B/32B dense models and the Qwen3.5 hybrids.
- Kaplan et al. Scaling Laws for Neural Language Models. arXiv:2001.08361, 2020. The forward FLOPs per token (Eq. 2.2, Table 1), and the condition for the attention term to stay negligible.
- Pope et al. Efficiently Scaling Transformer Inference. arXiv:2211.05102, MLSys 2023. Prefill compute-bound vs. decode memory-bound; the per-step cost ; weights amortize across the batch, KV caches do not.
- Databricks. LLM Inference Performance Engineering: Best Practices. Blog, 2023. Defines Model Bandwidth Utilization (MBU) and the memory-bandwidth limit on decode.
- Kipply Chen. Transformer Inference Arithmetic. 2022. Decode is memory-bandwidth-bound: the GPU re-reads all weights ( per token) for each step, while prefill is compute-bound; the two meet at the flops-to-bandwidth ratio (batch 208 on an A100).