Cross-Layer KV Cache Reuse: Architecture Practices to Reduce LLM Memory Usage
KV Cache has become a major memory bottleneck in long-context LLM inference. This article reviews existing compression approaches such as MQA and GQA, then explains cross-layer KV tensor reuse—grouping layers so they share KV states—including its core implementation, benefits, tradeoffs, and practical deployment recommendations. Readers will learn how this layer-dimension compression technique complements GQA and quantization for edge, long-context, and agent deployments.
Introduction: Why KV Cache Becomes a Memory Bottleneck in LLM Inference
During LLM inference, every newly generated token requires the model to access the Key and Value tensors computed for all previous tokens in the attention layers. To avoid recomputation, engineering practice widely adopts the KV Cache mechanism, storing these intermediate states in GPU memory. This delivers significant speedups, but it also introduces a new bottleneck: KV Cache size grows linearly with sequence length, batch size, and number of layers.
KV Cache memory usage can be estimated with a simplified formula:
Memory usage ≈ 2 × layers × sequence length × KV heads × head dimension × bytes per element × batch size
Consider a 30-layer model with hidden dimension 4096. When context length extends to tens or even hundreds of thousands of tokens, KV Cache alone may consume tens of GB of memory, sometimes exceeding the model weights themselves. As reasoning models and agent applications become more common, long reasoning chains and multi-turn tool calls produce extremely long contexts. KV Cache memory pressure has become a core constraint on deployment cost and context-window expansion.
As a result, “how to shrink KV Cache” has become a central theme in model architecture design. This article focuses on an approach that is moving into the mainstream: cross-layer KV tensor reuse.
Existing Compression Approaches: From MHA to GQA
Before discussing cross-layer reuse, it is useful to review existing KV Cache compression methods to understand where the new approach fits.
1. Multi-Query Attention and Grouped-Query Attention
In traditional multi-head attention (MHA), each attention head has independent K and V projections. Multi-query attention (MQA) lets all query heads share the same set of KV heads, directly compressing KV Cache to a fraction of the head count. Grouped-query attention (GQA) is a compromise: query heads are divided into groups, and each group shares one set of KV heads.
GQA can reduce KV Cache several times over with almost no loss in model quality, and it has become a standard feature in mainstream open-source models. However, it only addresses redundancy among heads within the same layer; redundancy across layers remains.
2. Other Common Directions
- KV Cache quantization: Compress cached K and V from FP16 to INT8 or even lower precision. This is an inference-engine-level optimization independent of architecture and can be combined with other methods.
- Sparse attention and sliding-window attention: Restrict each token to a local window or to important tokens, trading some global information for lower memory usage and computation.
- KV Cache eviction and compression strategies: Dynamically discard or merge unimportant historical KV entries during inference.
Most of these approaches operate on the sequence dimension or the numerical-precision dimension. Cross-layer reuse opens a new dimension: layers.
Cross-Layer KV Tensor Reuse: Core Principle
The basic observation behind cross-layer reuse is that attention patterns in adjacent Transformer layers are often highly correlated, and local features extracted by lower layers are repeatedly used by higher layers. Since K and V representations across different layers contain substantial redundancy, subsequent layers can directly reuse KV states already computed by an earlier layer instead of computing and storing them independently.
A typical implementation is “group sharing”: divide the model’s L layers into several groups. Within each group, only the first layer (or a designated layer) computes K and V, and the remaining layers reference the shared KV during attention computation:
# Illustrative pseudocode: share one KV Cache per group_size layerskv_cache_groups = {}for layer_id in range(num_layers):group_id = layer_id // group_sizeif layer_id % group_size == 0:# First layer in the group: compute normally and write to cachek = x @ W_k[layer_id]v = x @ W_v[layer_id]kv_cache_groups[group_id] = (k, v)else:# Subsequent layers in the group: reuse the shared KVk, v = kv_cache_groups[group_id]q = x @ W_q[layer_id]attn_out = attention(q, k, v)
If every two layers share one KV cache, the layer dimension of the KV Cache is halved; larger sharing groups save more memory. This idea has appeared in academic research, such as papers on cross-layer attention, but only recently has it begun to be applied at scale to mainstream open-weight models—especially small-parameter models for mobile and embedded devices. These devices have extremely limited memory, and their need for KV Cache compression is most urgent.
Benefits and Costs
1. Benefits
- Significant memory reduction: The layer dimension of the KV Cache is directly divided by the sharing group size, delivering large gains in long-context scenarios.
- Lower computation: Shared layers no longer perform K and V projections, reducing prefill cost as well.
- Orthogonal to GQA and quantization: Cross-layer reuse operates on the layer dimension and can be combined with GQA (head dimension) and INT8 quantization (precision dimension), forming multi-dimensional composite compression.
- Better for edge deployment: In memory-constrained environments such as phones and IoT devices, this technique can determine whether a model runs with a usable context length.
2. Costs and Risks
- Loss of expressiveness: Sharing KV means some layers lose independent key/value representations, which may cause quality regression on tasks that require fine-grained hierarchical features, such as complex reasoning and code generation.
- Training coupling: Sharing structures are best introduced during pretraining so the model learns to work under sharing constraints. Retrofitting an already trained dense model usually requires additional continued training to recover quality.
- Scheduling complexity: Inference frameworks need to manage cache lifetime by group, placing additional requirements on custom kernels and memory management.
A common engineering compromise is “partial sharing”: share only a few middle layers with the highest correlation, keep independent KV in the first and last layers, and preserve model quality at a modest memory cost.
Engineering Deployment Recommendations
- Evaluate before sharing: Use layer-wise attention similarity analysis to identify layers with the highest KV redundancy, and prioritize those layers instead of grouping them uniformly.
- Combine compression methods: Cross-layer reuse + GQA + KV quantization can often stack to several times or even an order of magnitude of memory savings, and their quality losses do not simply add up and worsen.
- Use end-to-end metrics: Do not focus only on memory numbers. Evaluate perplexity and accuracy changes on target business tasks such as long-document QA, multi-turn dialogue, and tool-calling chains.
- Pay attention to inference framework support: Choose an inference engine that supports custom KV Cache layouts, or implement grouped cache management in your own inference stack. For cloud deployment, combine container platforms with monitoring and alerting to observe memory levels for long-context requests in real time and schedule elastically, avoiding OOM caused by KV Cache growth.
Conclusion
Cross-layer KV tensor reuse represents a new dimension in KV Cache compression: moving from “intra-layer compression” to “cross-layer compression.” It is not a silver bullet, but in high-memory-pressure scenarios such as edge inference, long context, and agents, combining it with mature methods such as GQA and quantization can significantly lower deployment barriers. As more open-source architectures incorporate it into standard designs, this technical direction is worth understanding and practicing for every developer focused on LLM inference efficiency.
