KV Cache Size: How Many Users Fit on One GPU?
From the publisher’s feed, collected in the ZeroLabs newsroom.
DeepSeek V3 has 671B parameters and a smaller KV cache than Llama 3 8B. Here is the formula, a comparison table, and a script you can run on any model.Image by authorDeepSeek V3 has 671 billion parameters. Its KV cache per token is roughly half the size of Llama 3 8B’s. That cache decides how many users fit on your GPU, and you can compute it from a config file in two minutes.Sebastian Raschka’s Big LLM Architecture Comparison explains the design choices behind this: grouped-query attention, latent attention, sliding windows. I wanted to know what they cost in bytes, because that is the number on your GPU bill.TL;DRThe KV cache is the memory a model uses to remember the conversation so far. It grows with every token and every concurrent user.Its size follows from one formula and a model’s config.json.Grouped-query attention cut the cache 4x between Llama 2 7B (512 KiB per token) and Llama 3 8B (128 KiB). Latent attention takes DeepSeek V3 to 68.6 KiB.This number often decides how many users fit on one GPU, so check it before you pick a model.1. What the KV cache is, in plain wordsWhen an LLM writes a reply, each new token has to look back at every token before it. Recomputing all of that at every step would be far too slow, so the model keeps the intermediate results (the keys and values) in GPU memory and reuses them.That saves compute. It costs memory. The cache grows with every token, and every user in the batch has their own copy.So two things you control, context length and number of concurrent users, matter as much as the model’s parameter count.2. The formulaFor standard attention (multi-head or grouped-query):bytes per token = 2 × layers × kv_heads × head_dim × bytes per valueThe 2 is for keys and values. Everything else comes from the model’s config.json.Image by authorFor Llama 3 8B with a 16-bit cache, that is 131,072 bytes, or 128 KiB per token. A 4,000-token conversation holds about 0.5 GiB of cache. A hundred of them in parallel is about 49 GiB, before you have loaded a single weight.3. The tableI ran the formula on five public models, using values from each model’s config or paper. The cache is 16-bit. The last column assumes you reserve 40 GiB of GPU memory for cache and every user has a 4k-token conversation, which every model here supports natively.† Beyond the model’s native context, so a what-if number. * gpt-oss sliding-window layers stop growing after 128 tokens, so past that point each extra token costs about 24 KiB. That only holds if your inference engine actually frees out-of-window cache. Check before you rely on it.Computed from each model’s configIllustrative budget.In the same 40 GiB, the full-attention design fits 20 conversations and Llama 3 8B fits 80. DeepSeek V3, roughly 80 to 100 times larger by parameter count, fits 149.4. The three tricks behind the dropIllustrative, not to scale.Grouped-query attention (GQA): share keys and values. Llama 2 7B has 32 attention heads, and each keeps its own keys and values. Llama 3 8B keeps 32 query heads but only 8 sets of keys and values, so the cache falls from 512 to 128 KiB per token, exactly 4x.Multi-head latent attention (MLA): compress them. DeepSeek V3 does not store full keys and values. It stores one compressed vector per layer (512 latent values plus 64 positional ones) and rebuilds what it needs. That is 61 × 576 × 2 bytes, about 68.6 KiB per token, which is about half of Llama 3 8B’s cache.Sliding-window attention: stop remembering everything. Some layers only look at the most recent tokens. gpt-oss-20b alternates sliding-window layers (128 tokens) with full-attention layers, so half its layers can keep a fixed-size cache however long the conversation gets, if the engine frees the rest. Raschka covers the same idea in Gemma 3, which mixes local and global layers at a 5:1 ratio.The gap widens as conversations get longer:Solid = within native context, dashed = what-if.5. Where this table can mislead youSay these out loud if you reuse the numbers:Cache size is not quality. Llama 2 7B is a 2023 model, used here as the full-attention baseline, not as a recommendation. The table shows memory cost per design, not which model to choose.Weights are separate. DeepSeek V3 activates about 37B of its 671B parameters per token, but you still have to load all of them. The cache sits on top.MoE does not shrink the cache. Qwen3–30B-A3B has a small cache because it uses GQA with 4 KV heads. The expert layers affect compute and weight memory, not the cache.Precision changes everything. The table assumes a 16-bit cache. Many serving stacks can store it in 8-bit, which roughly halves the numbers, with a quality risk you should test on your own data.Native context matters. Llama 2 7B supports 4k tokens and Llama 3 8B 8k (later 3.1 releases extend it to 128k with the same cache shape). Qwen3–30B-A3B is 32,768 native, or 131,072 with YaRN scaling. The † columns are what-if.Sliding-window savings depend on your engine. See the table note.The 40 GiB budget is illustrative. Your real number is GPU memory minus weights minus runtime overhead.6. Run it on your own modelThe core of the script is this:def per_token_bytes(layers, kv_heads, head_dim, bytes_per_value=2): return 2 * layers * kv_heads * head_dim * bytes_per_valueprint(per_token_bytes(32, 32, 128) / 1024) # Llama 2 7B: 512.0 KiB per tokenprint(per_token_bytes(32, 8, 128) / 1024) # Llama 3 8B: 128.0 KiB per tokenThe full version, with MLA and sliding-window handling, is here: [GitHub link]. Copy a model’s config.json values into the config list and it prints the table for you.7. What to do on MondayCompute KV bytes per token for every model you are considering, before you benchmark anything.Multiply by your real P95 prompt length and your expected concurrent users. For RAG, count the retrieved chunks, because they are part of the prompt.Subtract model weights and overhead from GPU memory. Compare.If it does not fit, you have three options: shorter context, a quantized cache, or a model with fewer KV heads, MLA or sliding-window layers.Re-check whenever you change how many chunks you retrieve.What does the number come out to for the model you run? Post it in the comments, and say which model and context length.Next: How Many RAG Users Fit on One GPU?, using this math as the first filter.LLM Architecture for People Who Ship: Part 1: Why One AI Model Can Serve 4x More Users on the Same GPU · Part 2: KV Cache Size: How Many Users Fit on One GPU? · Part 3: How Many RAG Users Fit on One GPU?KV Cache Size: How Many Users Fit on One GPU? was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.