CyberAutomations

KV cache calculator: how many agents fit on your GPU?

Pick one of 29 open models, or paste any Hugging Face model id. Choose a weight quantization, a card and a context length. The calculator works out the KV cache each agent session needs and how many sessions fit in the memory that is left after the weights.

How the memory is spent
MeasureValue
Agents that fit-
KV cache per agent-
Fixed: weights plus buffers-
Used of total VRAM-

The KV cache formula

Every token an agent has in its context keeps a key and a value vector in every attention layer. That store is the KV cache, and it is why long-context agents run out of memory long before the GPU runs out of compute.

KV cache bytes = 2 × layers × KV heads × head dim × bytes per value × context tokens

The 2 counts keys and values. Layers, KV heads (num_key_value_heads) and head dim (head_dim, or hidden_size divided by num_attention_heads when it is missing) all come from the model's config.json. Bytes per value is 2 for f16, about 1 for an 8-bit cache, and about half for a 4-bit cache.

Worked example: Qwen3-8B at 32k context

  1. Qwen3-8B's config.json lists 36 layers, 8 KV heads and a head dim of 128.
  2. Per token, with an 8-bit cache: 2 × 36 × 8 × 128 × 1 = 73,728 bytes (72 KiB).
  3. For 32,768 tokens: 73,728 × 32,768 = 2,415,919,104 bytes, which is 2.25 GiB per agent.
  4. With an f16 cache the same agent needs 4.5 GiB. On a 24 GB card the Q4_K_M weights (4.7 GiB) plus 2 GiB of buffers leave about 16.3 GiB, so 7 agents fit with an 8-bit cache and 3 with f16.

Your numbers

Three kinds of model need a tweak to the formula, and the calculator handles each one:

All models in the list

Numbers read from each model's config.json on Hugging Face. The last column is the cache for one agent at 32,768 tokens with an 8-bit cache. Pick a model name to load it into the calculator.

ModelParamsFull-attn layersOther layersKV headsHead dimMax contextKV per 32k agent

Notice that parameter count is a poor guide to cache size. Qwen3-8B needs 2.25 GiB per 32k agent while the much larger Qwen3-30B-A3B needs 1.5 GiB, because it keeps half as many KV heads.

Things that catch people out

Method

Architecture numbers (layers, KV heads, head dim, which layers use full, sliding or linear attention, and maximum context) come from each model's public config.json on Hugging Face, and parameter counts come from the Hugging Face model API (the safetensors total). The same code reads the bundled models and any id you paste. Llama models are not in the list because their repos are gated. Gemma 3's config leaves out the layer pattern and maximum context, so the calculator uses the Gemma 3 defaults from the Hugging Face transformers library (one full-attention layer in every six, 131,072 tokens).

Weight sizes are real GGUF file sizes where we have them (Qwen3-8B, Qwen3-32B, Qwen3-30B-A3B from the official Qwen GGUF repos, and gpt-oss from ggml-org). For every other model they are estimated from the parameter count at the average bits per weight those GGUF files show: 4.82 for Q4_K_M, 5.67 for Q5_K_M, 6.56 for Q6_K, 8.5 for Q8_0 and 16 for BF16. The calculator adds 2 GiB of compute buffers per card, treats 96% of each card as usable, and counts an 8-bit cache as 1 byte per value. Linear-attention state is counted at 4 bytes per value.

Estimates, not guarantees: real usage depends on the inference server, batch settings and driver.