Back to articles
Hardware & costs2 min read

Why Longer AI Conversations Use More VRAM: Understanding the KV Cache

Model weights stay the same, yet longer conversations are more likely to run out of memory. One reason is the KV cache saved during generation. Its size depends on context length, model architecture, and concurrency, so your hardware budget needs to account for both model size and usage.

An unbranded computing chip surrounded by layered circuit traces and memory modules.
AI-generated editorial illustrationConcept illustration; not a product screenshot, research result or source photograph.
Three-month free access · All articles are open through January 10, 2027 (Japan time).

The KV cache stores the keys and values needed for attention calculations, reducing repeated computation when generating subsequent tokens. Hugging Face's cache strategy documentation discusses memory and speed tradeoffs between caching approaches. NVIDIA's inference article also identifies the cache as an important part of resource budgeting. Hugging Face documentation ↗, NVIDIA technical article ↗

For a typical full-attention cache, a simplified estimate is:

Cache size in bytes ≈ 2 × number of layers × number of KV heads × dimensions per head × token count × concurrent sequences × bytes per element.

The 2 accounts for keys and values. Suppose an example model has 32 layers, 8 KV heads, and 128 dimensions per head. It stores 4,096 tokens for a single sequence using 2-byte values. The calculated cache size is approximately 512MiB.

Holding those assumptions constant:

  • Increasing the context to 8,192 tokens gives approximately 1GiB.
  • Storing four 4,096-token sequences concurrently gives approximately 2GiB.

This is an illustrative order-of-magnitude calculation created for this article. It excludes overhead such as cache allocation and buffers. Sliding windows, different attention architectures, and cache quantization can also change the result, so the estimate cannot be applied to every model.

VISUAL NOTE
Selected document slices and their neighboring context enter a transparent reading window.
AI-generated concept illustrationThe weights stay. The conversation grows.

Try it

Keep the model and quantization method fixed, gradually increase input length, and record peak memory and time to first token. Then vary concurrency. Change only one condition at a time to make it easier to identify which requirement drives memory usage upward.

Measure speed when testing ways to save VRAM, too. Moving the cache to another memory location or quantizing it further may introduce additional computation and data-transfer costs.

EXPLAINED IN SLICES

The weights stay. The conversation grows.

  1. Model weights

    The same checkpoint

  2. Longer context

    More tokens to attend to

  3. KV cache

    Saved attention state

Editorial diagramCache requirements depend on architecture, precision, context length and concurrency. This shows the relationship, not a measured growth rate.

Understand it. Then try it.

Read something else
Was this useful?

No sign-in needed. One like per browser, across all languages.

Loading likes…

Original references

Use these links to verify details and learn more. A reference does not imply endorsement.

huggingface.coReference 1developer.nvidia.comReference 2