KV cache grows with context length because the runtime stores attention keys and values for every retained token across multiple model layers.
A short home AI prompt may leave enough memory for several users, while a long document, extended chat history, or agent trace can consume far more working memory without changing the model file itself. The cache begins during prompt processing and continues growing as the model generates new tokens. Its size also depends on layer count, attention architecture, numerical precision, and simultaneous requests. The sections below trace that growth from one token to the server-wide memory limit.
Every Retained Token Adds Attention State
During transformer inference, each layer produces key and value tensors from the tokens already processed. The runtime keeps those tensors so the next token can attend to prior context without recomputing the full sequence.
The vLLM work identifies per-token KV state as a major serving-memory requirement. New tokens add new cache entries while previously retained entries remain available to later attention steps.
The cache is therefore mutable request state rather than part of the static model weights. Loading the same model with a longer active conversation creates a larger memory footprint.
Cache Growth Is Approximately Linear With Retained Sequence Length
For a fixed model architecture and cache precision, doubling the number of retained tokens approximately doubles the KV entries held for that request. The prompt and generated answer both count toward the active sequence.
H2O describes how KV cache scales with sequence length and batch size. The relationship remains roughly linear because each additional token contributes keys and values at every cache-producing layer.
This is why increasing a runtime setting from a small context to a much larger maximum can change the practical memory ceiling even when the model uses identical weights.
The maximum setting and actual use are different. Some runtimes allocate cache blocks on demand, while others reserve a larger region early to guarantee future growth.
Model Architecture Changes the Number of Bytes per Token
Two models with the same parameter count can require different KV memory because they may use different layer counts, head dimensions, attention heads, grouped-query attention, or multi-query attention.
KIVI studies KV cache precision and shows that storing keys and values at fewer bits can substantially reduce peak memory. The benefit applies to request state rather than shrinking the underlying model weights.
Grouped-query and multi-query designs share key-value heads across more query heads, which can lower cache bytes per token compared with full multi-head attention. Layer count and head width still multiply the retained state.
A useful estimate must therefore use the exact model architecture and runtime cache format, not only a generic bytes-per-token rule copied from another model.
Generated Tokens Keep Extending the Cache After Prefill
Prompt processing creates the initial cache for the input context. Autoregressive decoding then appends state for each accepted output token so later tokens can attend to the complete conversation.
vAttention treats dynamic cache growth as an allocation problem because the final output length is unknown when a request begins. Reserving too much wastes memory, while reserving too little can force preemption or expansion work.
A prompt that fits comfortably can still cross the memory boundary during a long answer. Output limits therefore protect memory as well as response length and generation time.
Concurrent Users Multiply Separate Context State
Model weights can be shared across requests, but each active conversation normally carries its own token history and KV cache. Five users with long contexts do not share one universal cache merely because they use the same model.
Recent KV-management research frames per-request reservations as a central trade-off between memory efficiency and preemption risk. Unknown output lengths make the combined peak harder to predict than a simple user count.
Shared prompt prefixes can sometimes reuse cache state when the runtime supports exact prefix matching, but private chat history and divergent outputs still create separate branches.
ZimaSpaceโs hardware guide treats context and concurrency as memory requirements beyond the model file. A one-user test can therefore understate the RAM or VRAM needed by a household assistant.
Paging, Quantization, and Eviction Change the Limit, Not the Cause
Paged allocation reduces fragmentation by dividing cache state into smaller blocks, so a runtime does not need one oversized contiguous reservation for every possible sequence.
PagedAttention provides block-based allocation, while cache quantization reduces bytes per stored value and eviction policies discard selected old entries. Each method changes how much context fits, but the retained attention state still grows as tokens accumulate.
Eviction or sliding windows can cap memory by removing earlier tokens, but the model can no longer attend to discarded state through the normal full-context path. Compression and selective retention may also introduce quality or workload-specific trade-offs.
Measure cache use with the real model, context, cache precision, batch size, and user count. The practical limit is reached when another token or request cannot be admitted without eviction, offload, recomputation, or failure.
FAQ
Does the model file become larger when context length increases?
No. The model weights remain the same. The additional memory is runtime state created for the active prompt and generated tokens.
Does setting a large maximum context always allocate all KV memory immediately?
No. Allocation behavior depends on the runtime. Some reserve capacity early, while paged systems allocate blocks as tokens are admitted.
Can system RAM hold KV cache when VRAM is full?
Some runtimes can offload or move cache state, but transfers add latency and depend on software support, bandwidth, and the active attention path.
Tech & AI HUB
More to Read

Runtime State vs Persistent State in Home Assistant: What Must Survive Restart?
Home Assistant does not persist every live value; config, registries, selected restored states, history, and deployment data play different restart roles.

How Does Home Assistant Authenticate Local and Remote Sessions?
Local and remote Home Assistant sessions use the same server-side identity model; remote access changes the route and TLS boundary, not the core token...

Why Can Home Assistant History Queries Slow as Recorder Data Grows?
Recorder growth can raise History query cost when the requested range touches more rows, cache misses increase, or storage and index work become slower.

