Cross-Layer KV Cache Reuse in LLM Architecture Evolution: Engineering Practices and Trade-offs
This article examines the memory bottleneck caused by KV Cache in long-context LLM inference and reviews three recent open-weight architecture directions: lightweight edge models, MoE models for efficient inference, and dense models with high performance ceilings and easier tuning. It then explains cross-layer KV cache reuse, including its theoretical basis, implementation logic, and engineering benefits for memory, latency, and bandwidth. It also discusses post-training trade-offs between MoE and dense architectures and deployment considerations for cloud and edge environments.
Introduction: The Memory Bottleneck in LLM Inference
As large language models (LLMs) continue to improve across tasks, application scenarios are rapidly extending toward ultra-long context processing, such as long-document summarization and large-scale codebase analysis. However, in the Transformer architecture, the memory footprint and computational cost of self-attention grow non-linearly with sequence length. Specifically, during autoregressive decoding, the model must cache the Key and Value tensors of historical tokens in GPU memory—this is the so-called KV Cache.
When context length reaches tens of thousands or even hundreds of thousands of tokens, the memory footprint of the KV Cache often far exceeds that of the model weights themselves. This not only limits the number of concurrent requests a single GPU can serve, but also significantly raises the barrier to deployment on edge devices. Therefore, effectively reducing the time and space complexity of the KV Cache while maintaining model performance has become one of the core topics in recent LLM architecture evolution.
Three Major Directions in Recent Open-Weight Model Architectures
Looking at recently released open-weight model series, their architecture designs show clear differentiation and can be broadly grouped into three directions:
- Lightweight models for edge and IoT devices: These models have very small parameter counts, typically in the few-billion range, and are deeply optimized for mobile devices, edge computing nodes, and embedded devices. Their core requirement is smooth inference under extremely limited compute and memory.
- Mixture-of-Experts (MoE) models for efficient inference: MoE uses sparse activation to expand total parameter count while keeping inference computation relatively low. For example, some MoE models with tens of billions of total parameters activate only a few billion parameters per inference pass, greatly improving inference throughput.
- Dense architecture models pursuing high ceilings and ease of tuning: In contrast to MoE, Dense models activate all parameters during inference. Although the per-pass compute cost is higher, their simple gradient propagation path and lack of complex routing mechanisms give them higher stability and convenience during post-training and domain fine-tuning.
Core Mechanism: How Cross-Layer KV Cache Reuse Works
Among the architecture changes in these lightweight models, one of the most notable is the “shared KV Cache” mechanism, also known as Cross-Layer Attention. In a traditional Transformer architecture, each layer has an independent attention module and must separately compute and store the KV state for that layer. This means that for an N-layer model, KV Cache memory usage is proportional to the number of layers.
Theoretical Basis
Recent academic research suggests that in deep neural networks, the Key-Value projection matrices of different Transformer layers often show a high degree of similarity in feature space. In other words, when later layers extract contextual information, they do not always need to fully reconstruct Key and Value states; they can directly reuse tensors already computed by earlier layers.
Cross-Layer Reuse Mechanism
Based on this observation, some advanced open-weight models have begun to introduce cross-layer KV reuse. The approach is as follows: during forward propagation, certain layers compute and generate standard KV Cache, while several immediately following layers skip KV projection computation and directly reference the KV state from the adjacent preceding layer for attention computation.
For example, assume a model has 32 layers. If every 4 layers form a sharing group, only the first layer in each group computes new KV Cache, and the other 3 layers reuse that state. Theoretically, this design can reduce KV Cache memory usage to one quarter of the original, with minimal impact on long-context inference accuracy.
Engineering Practice and Performance Benefits
Applying cross-layer KV cache reuse in practical inference frameworks can deliver significant engineering benefits, especially in resource-constrained environments. The mechanism improves several key dimensions:
- Substantially lower memory usage: By reducing KV Cache storage requirements, a GPU or edge chip with the same memory capacity can support a longer context window, or increase concurrent batch size at the same context length.
- Reduced computational latency: Eliminating a large number of repeated KV projection matrix multiplications effectively lowers per-step decoding latency and improves token generation speed.
- Relieved bandwidth pressure: In distributed inference or edge computing, KV Cache transmission across nodes or devices is often a bottleneck. Reducing its size directly alleviates communication bandwidth pressure.
Below is a simplified pseudocode example showing the basic logic of cross-layer KV reuse in an inference forward pass:
def forward_layer(hidden_states, layer_idx, shared_kv_cache):# Determine whether the current layer needs to compute new KVif layer_idx % SHARING_INTERVAL == 0:# Current layer is a compute layer; perform standard QKV projectionquery = self.q_proj(hidden_states)key = self.k_proj(hidden_states)value = self.v_proj(hidden_states)# Update the shared cacheshared_kv_cache[layer_idx // SHARING_INTERVAL] = (key, value)else:# Current layer is a reuse layer; directly obtain KV from the preceding layer# Query projection is still computed independently for each layerquery = self.q_proj(hidden_states)key, value = shared_kv_cache[layer_idx // SHARING_INTERVAL]# Subsequent standard attention computationattn_output = scaled_dot_product_attention(query, key, value)# ... MLP and subsequent computation
Architecture Trade-offs: Post-Training Challenges for MoE and Dense Models
Beyond KV Cache optimization, recent architecture choices also reflect deep consideration of post-training workflows. Although MoE architectures are highly efficient during inference, they face multiple challenges during post-training and fine-tuning:
First, MoE routing networks are usually discrete and non-differentiable choices, requiring approximation algorithms such as Gumbel-Softmax or load-balancing losses to ensure training stability. During instruction tuning or reinforcement learning from human feedback (RLHF), this instability can be amplified, causing some expert nodes to be over-trained while others remain idle. In addition, MoE models have large parameter counts and extremely high memory requirements, making full-parameter fine-tuning expensive.
By contrast, although Dense architecture models incur higher inference compute costs, their simple structure and clear gradient update paths make post-training tuning more mature. For enterprises that need deep domain adaptation, Dense models are often easier to tune effectively through parameter-efficient methods such as LoRA. As a result, the industry often releases an MoE model for efficient inference alongside a Dense model with a similar parameter count, to meet the needs of different application scenarios and developers.
Engineering Considerations for Cloud and Edge Deployment
In practical deployment, whether choosing MoE or Dense, cross-layer KV reuse or other memory optimization techniques, decisions need to be coordinated with the specific deployment environment. In cloud environments, container platforms can provide elastic scheduling of compute resources, dynamically scaling inference instances up or down based on request volume at different times. Combined with efficient load balancing and monitoring and alerting systems, this can maximize cluster GPU utilization.
For edge deployment, in addition to relying on model structure optimization, deep quantization such as INT4/INT8 and operator fusion should be combined with the underlying hardware instruction set. Cross-layer KV reuse combined with quantization can make it possible for models at the ten-billion-parameter level to run smoothly on consumer-grade devices.
Conclusion
From the engineering implementation of cross-layer KV cache reuse to the parallel development of MoE and Dense architectures, LLM architecture evolution is shifting from pure “scale expansion” toward a refined balance between efficiency and quality. Understanding the evolution logic of these underlying architectures not only helps developers better select and deploy models, but also provides valuable engineering experience for exploring more efficient general AI foundations in the future. As general cloud infrastructure continues to mature, enterprise developers will be able to apply these architectural advances more easily and build high-performance, low-cost intelligent applications.
