A transformer generating text repeatedly needs information from the tokens it has already processed. The key-value cache, usually called the KV cache, keeps part of that intermediate computation so the model can generate the next token without rebuilding the entire past at every step. It consumes memory because it retains numerical state for earlier token positions across attention layers.

In one attention layer, the current token produces a query vector. The model compares that query with key vectors for positions it may attend to, then uses the resulting weights to combine their value vectors. Keys help determine where to attend. Values contain the information combined by that attention operation. These vectors come from learned transformations of the layer's inputs. They are neither the original prompt text nor a conversational summary.

During prefill, the model processes the input prompt and creates the corresponding cached keys and values. During decode, it processes the next generated token using previously cached states and appends the new states needed for subsequent tokens. At layer two, the cache contains layer-two representations, not a copy of layer one's vectors. Hugging Face's cache explanation describes these tensors and how their sequence dimension grows. This is the ordinary autoregressive decoder case, with attention restricted to permitted earlier positions.

For the hypothetical full-attention model in the question, the approximate cache bytes per token are 2 × layers × KV heads × head dimension × bytes per element. The leading two accounts for both keys and values. Substituting the numbers gives 2 × 32 × 8 × 128 × 2 = 131,072 bytes, or 128 KiB per token. For 8,192 live token positions, that is 131,072 × 8,192 = 1,073,741,824 bytes, exactly 1 GiB of KV data.

Sixteen independent sequences of that length require about 16 GiB of such cache data. Model weights, attention workspace, temporary activations, allocator overhead and reserved blocks are additional. The calculation describes the aggregate uncompressed cache for this assumed model. It does not establish per-GPU residency under a particular parallel layout. Grouped-query attention uses fewer KV heads than query heads. Sliding-window, hybrid and compressed attention architectures can have different growth rules, so inspect the actual model rather than substituting its advertised width into this formula.

A matrix of token positions and attention layers shows that each new live token adds a key and value at every layer.

Both prompt and output length matter. A long prompt creates a large cache before the answer begins. A short prompt can produce a long answer that consumes increasing memory after a fast first token. Concurrent live requests add their retained histories together. This explains why flat requests per second does not imply flat memory demand. Allocating cache in blocks also means reserved capacity can exceed the exact count of useful live tokens.

Prefix caching reuses compatible cached computation when requests begin with the same effective input tokens. A second request can reuse the common prefix and compute its own suffix. The PagedAttention paper discusses block management and sharing for serving. The sharing must retain correct ownership: releasing one request cannot free a block another request still needs, and modifying a divergent continuation cannot overwrite shared prefix state.

Suppose, hypothetically, two conversations each contain 4,096 common prefix tokens followed by 4,096 different tokens. Without sharing, they hold 16,384 token positions in total. Perfect sharing of that common prefix reduces physical KV storage to 12,288 positions, or about 1.5 GiB under our assumptions. The saving is 25 percent of their combined cache, not half. Engine block boundaries, residency and additional cache metadata can change the realized saving.

Compatibility requires more than similar meaning. Token identities, model and adapter revisions, positions and cache representation must agree. vLLM's prefix-cache design describes block hashing and optional isolation salts. Treat that as one engine's design. The platform must choose trust scopes that avoid cross-tenant timing disclosures and prevent stale instruction or data reuse. KV reuse does not replace current authorization for evidence or make a cached answer safe to disclose.

Prefix retention policy still matters. In vLLM V1, cached blocks with no active users can remain on the free queue and be evicted when new allocations need them. Cached occupancy is therefore different from active memory pressure. A policy that pins retained prefixes or reserves capacity for them can reduce space available to other work. Measure reused versus recomputed tokens, active versus reclaimable blocks, preemption, first-token latency and completion latency. Prefix caching can make repeated prompt processing cheaper while leaving substantial memory and decode work for every conversation's unique continuation.