LLM Architecture Evolution: How Cross-Layer KV Cache Reuse Reduces Inference Costs
As Large Language Models (LLMs) scale to handle longer contexts, the memory overhead of the Key-Value (KV) Cache has become a primary bottleneck in inference, often exceeding the footprint of the model weights themselves. This article explores how cross-layer KV Cache reuse—sharing Key and Value states across multiple transformer layers—addresses this challenge by significantly reducing memory usage, computation, and bandwidth pressure. Additionally, it examines the divergence in architecture choices, such as Mixture of Experts (MoE) versus Dense models, and provides practical guidance for enterprise deployment and model selection.
The Core Bottleneck of LLM Inference: KV Cache
In autoregressive generation scenarios, a Transformer model must compute attention between the current Query and the historical Key and Value states of all previously generated tokens for each new token. To avoid redundant calculations, engineering practices cache the calculated Key-Value states at each layer, a technique widely known as the KV Cache.
While the KV Cache dramatically reduces the computational load during the generation phase, the trade-off is that memory consumption grows linearly with sequence length and the number of layers. This footprint can be roughly expressed as:
Memory Footprint ≈ 2 × Num_Layers × Seq_Len × Hidden_Dim × Bytes_Per_Element
When a model comprises dozens of layers and the context window extends to tens of thousands of tokens or more, the memory overhead of the KV Cache often surpasses that of the model weights themselves, becoming the primary bottleneck for deploying long-context models. This issue is particularly acute in memory-constrained environments such as mobile and embedded devices. To address this pain point, the industry has developed several approaches, including Multi-Query Attention (MQA), Grouped-Query Attention (GQA), and Sliding Window Attention. Recently, a noteworthy new trend has emerged: cross-layer reuse of Key-Value states.
Cross-Layer Shared KV Cache: From Research to Mainstream Architecture
In a traditional Transformer, each layer independently computes and stores its own Key and Value representations. This design implies an underlying assumption: different layers require fundamentally distinct Key-Value representations. However, academic research has gradually revealed significant redundancy in attention states across adjacent or even more distant layers. Years ago, research papers systematically proposed cross-layer attention mechanisms, demonstrating the feasibility of allowing subsequent layers to directly reuse the Key-Value states computed by preceding layers. Experiments proved that such sharing causes minimal degradation to model quality.
Recently, an open-source model series applied this concept at scale within a mainstream architecture, marking a milestone in the engineering of this technical route. The core mechanism can be summarized as follows: specific layers in the model no longer independently generate and cache their own Keys and Values. Instead, they reference tensors already computed by designated preceding layers.
The following pseudocode illustrates this process:
# Standard approach: independent calculation per layerfor layer in layers:k, v = layer.kv_proj(hidden_states)kv_cache[layer.id] = (k, v)hidden_states = layer.attention(q, k, v)# Cross-layer reuse: some layers reference previous layers' cachefor layer in layers:if layer.reuse_kv_from is not None:k, v = kv_cache[layer.reuse_kv_from] # Direct reuseelse:k, v = layer.kv_proj(hidden_states)kv_cache[layer.id] = (k, v)hidden_states = layer.attention(q, k, v)
From an engineering perspective, this modification yields a triple benefit:
- Direct reduction in memory footprint. If half of the layers reuse the KV states from the preceding layer, the total KV Cache volume can theoretically be reduced by nearly 50%. On edge devices, this often marks the boundary between a model that can run and one that cannot.
- Decreased computational load. Layers that reuse KV states no longer need to execute Key and Value projection calculations. This also reduces the prefill latency for the first token of long sequences.
- Alleviated bandwidth pressure. During the decoding phase, the complete KV Cache must be read at every step. A smaller cache means reduced memory access volume per step, which is particularly critical for inference chips constrained by memory bandwidth.
Naturally, this design is not without its costs. The diversity of inter-layer representations is constrained to some extent. Consequently, actual architectures typically adopt a compromise: only a fraction of the layers perform reuse, and the reuse relationships are carefully designed and validated during training, rather than simply having all layers share a single cache.
Edge Models and Local Inference: Divergence in Architecture Choices
The cross-layer sharing mechanism described above was first applied to small-parameter models targeting mobile and embedded scenarios. This aligns with intuition—the tighter the memory, the greater the marginal benefit of compressing the KV Cache. Conversely, larger parameter models designed for high-quality scenarios exhibit a different architectural divergence: the coexistence of Mixture of Experts (MoE) and Dense architectures.
MoE architectures achieve an effect of “large total parameters, small active parameters per inference” by placing multiple expert networks in each layer and activating only a few during each forward pass. This allows the model to possess a larger knowledge capacity while keeping inference computation manageable, making it highly suitable for efficient local inference. However, its shortcomings are equally apparent: the discrete decisions of expert routing make the training and post-training processes more fragile. Issues such as expert load imbalance and routing collapse frequently occur during fine-tuning, raising the barrier for optimization.
Dense architectures, on the other hand, involve all parameters in every forward propagation. The unit computation cost is higher, but the training dynamics are stable, and the post-training ecosystem is mature. Supervised fine-tuning (SFT) and preference alignment processes have well-established engineering paradigms. Therefore, teams pursuing higher model quality and requiring frequent, customized post-training tend to prefer Dense architectures as their foundation.
This product strategy of “one model family, multiple architectures” essentially reflects the diversity of inference deployment needs: no single architecture can optimally satisfy edge memory constraints, inference throughput, and post-training ease of use simultaneously.
Implications for Enterprise Deployment
For teams looking to deploy LLMs in production environments, the aforementioned architectural evolution provides several actionable insights:
First, focus on the structural optimization of the KV Cache during model selection. When evaluating open-source models, beyond parameter counts and benchmark scores, teams should examine the design of the attention mechanism—whether it employs Grouped-Query Attention, introduces cross-layer sharing, and what its effective context length is. For scenarios like long-text Q&A or codebase-level comprehension, these factors often impact deployment costs more significantly than differences in parameter count.
Second, match the architecture type to the specific scenario. For edge and local deployment, prioritize small models optimized for memory. For business scenarios requiring deep customization and fine-tuning, the post-training friendliness of Dense architectures offers more value. For throughput-sensitive online services with lighter post-training requirements, MoE is a more economical choice.
Third, leverage cloud platforms to reduce validation costs. Architecture comparison experiments require substantial computational power. Teams can provision elastic GPU resources on cloud platforms such as Baidu AI Cloud, rapidly set up inference environments using container platforms, manage model weights and evaluation data with object storage, and utilize monitoring and alerting services to observe the memory footprint and latency curves of different architectures under real-world loads. This enables data-driven final selection decisions.
Conclusion
From grouped sharing at the attention head dimension to Key-Value reuse at the layer dimension, the main thread of LLM architecture optimization has consistently revolved around a single goal: compressing memory and computational overhead during inference without sacrificing model quality. The transition of cross-layer KV Cache reuse from academic research to mainstream open-source architectures signifies that this direction has passed large-scale validation. For developers, understanding the trade-off logic behind these mechanisms is more important than memorizing a specific model name—because architectural philosophies persist and will continue to shape the design of next-generation models, directly determining how far we can push model capabilities under varying hardware budgets.
