LLM KV Cache Memory Estimator
Pure frontend: enter the model shape and your expected load to get the per-token byte price, the memory for one request, the combined total and a concurrency ceiling. Nothing leaves your browser — no network call, nothing recorded.
How to use
Take the three structural values from the model's config.json: layer count, num_key_value_heads and head dimension. Add the cache dtype and your real workload. The result table shows every multiplier separately so you can audit the arithmetic.
Assumptions and where the formula comes from
The expression follows from the structure of the attention cache; it is not an internal detail of any one engine.
bytes per token = 2 × layers × KV heads × head dimension × bytes per element
bytes per sequence = bytes per token × context length
total KV bytes = bytes per sequence × concurrent sequences
concurrency ceiling = cache budget in bytes ÷ bytes per sequence
- The leading
2is one Key tensor plus one Value tensor. KV headsmeansnum_key_value_headsfrom the config, notnum_attention_heads. They match in MHA; GQA and MQA use fewer KV heads.- Bytes per element follows the cache dtype: 2 for FP16/BF16, 1 for FP8/INT8, 4 for FP32.
- Capacity is computed in binary GiB (1 GiB = 1024³ bytes). Vendors quote memory in decimal GB, roughly 7% apart; align units before comparing.
This is not a precise figure. It excludes model weights, activations, block alignment and fragmentation, scheduler reserve, CUDA graphs and communication buffers. It also does not apply to sliding-window, MLA or mixed-attention layouts. Use it as a first pass, then trust the KV capacity and maximum concurrency logged by the engine itself.
Reading the output
The KV head count is not the query head count — copy the query number into a GQA config and the whole estimate is fiction. Get those three config fields right before discussing any tuning. This page gives you a per-token byte price, then leaves the context-versus-concurrency split to you: double the context and one request costs twice as much, so the same budget holds half as many users. Doubling concurrency works the same way.
Weight quantization is a separate matter. Turning 16-bit weights into 4-bit weights does not quietly shrink the KV cache. If you want longer contexts on the same card, shorten the context, cut concurrency, choose an architecture with fewer KV heads, or move the cache to FP8 and verify quality on your own long-document tasks before shipping.
Related tutorials
- vLLM production tuning — memory utilization, KV blocks and concurrency knobs together
- KV cache misses and repeated prefill — how prefix hits change time to first token
- LLM serving throughput and latency — turning memory capacity into concurrency
Official references
- vLLM optimization and tuning — memory allocation,
gpu_memory_utilizationand cache sizing - vLLM automatic prefix caching — how shared prefixes reuse cached KV blocks