Beyond KV Caching: Shared Attention for Efficient LLMs

Bingli Liao, Danilo Vasconcellos Vargas · DOI

Introduction

The rapid scaling of Large Language Models (LLMs) has brought significant challenges in deployment efficiency. A primary bottleneck is the "KV cache"—the memory required to store key and value vectors for all previous tokens during autoregressive inference. As sequence lengths grow, the KV cache can exceed the available GPU memory, limiting throughput and increasing latency.

While existing techniques like Multi-Query Attention (MQA) and Grouped-Query Attention (GQA) reduce memory by sharing heads within a single layer, and Cross-Layer Attention (CLA) shares caches between adjacent layers, these methods still require every layer to compute its own unique attention weights. This redundancy in computation and memory storage for attention scores ($QK^T$) and the subsequent $softmax$ operation remains a significant overhead.

Shared Attention (SA)

To address these inefficiencies, researchers have introduced Shared Attention (SA). This novel mechanism reuses the final attention weights across multiple layers, bypassing expensive redundant operations and significantly shrinking the KV cache with minimal impact on accuracy.

Comparison of attention mechanisms: Multi-Query Attention, Cross-Layer Attention, and the proposed Shared Attention.

How It Works

The core of SA lies in the concept of an "Attention Span"—a designated range of layers (e.g., layers 23 to 30 in a 32-layer model). Within this span:

  1. Calculate Once: The model computes the attention weights (the result of $QK^T$ followed by $softmax$) only for the first layer in the span.
  2. Reuse Many Times: All subsequent "follower" layers in the span skip the $QK^T$ and $softmax$ steps entirely. They directly apply the pre-computed weights from the first layer to their own Value ($V$) matrices.

By sharing the output of the $softmax$ operation, SA eliminates the need to store $K$ matrices for follower layers and removes the FLOPs required for their attention weight calculations.

Empirical Foundation: Attention Isotropy

The feasibility of SA is rooted in the observation that attention patterns in mature, pre-trained LLMs become "isotropic" in the middle-to-late layers. This means that the distribution of attention weights becomes remarkably similar across these layers.

3D visualization of attention weight similarity across layers for Llama2, Llama3, and Qwen2 models, highlighting the regions of high isotropy.

The researchers identified a "Group 3" sweet spot—the bulk of middle-to-late layers—where this isotropy is most pronounced. Analysis of model training checkpoints (e.g., Baichuan2-7B) revealed that while attention patterns are initially chaotic, they stabilize and become uniform after the model has processed approximately 1.0 trillion tokens.

Evaluation and Results

The authors evaluated SA across several prominent models, including Llama2-7B, Llama3-8B, and Qwen2-7B/72B, using benchmarks such as MMLU, GLUE, GSM8k, and HellaSwag.

Performance and Efficiency

The results demonstrate that SA maintains high performance with significantly reduced overhead:

  • Accuracy: On Llama3-8B, implementing SA across layers 23–30 resulted in a GLUE score of 0.5595, notably outperforming the base model's 0.4804 in that specific configuration.
  • Reasoning: For Llama2-7B, applying SA to the final layers (27–30) maintained a GSM8k score of 0.1243, compared to the base score of 0.1395, indicating that reasoning capabilities are largely preserved.
  • Fine-tuning: While "plugging in" SA to a pre-trained model can cause a minor initial performance dip, a small amount of instruction fine-tuning (SFT) allows the model to adapt, often recovering or exceeding original performance levels.

Limitations and Future Directions

Despite its promise, SA currently requires manual selection of the "Attention Span" based on empirical observation. Future research could focus on automated or dynamic span selection to optimize efficiency across different model architectures. Additionally, while this study focused on post-hoc integration, pre-training a model from scratch with SA could potentially yield even greater efficiency gains and architectural stability. Combining SA with Cross-Layer Attention (CLA) represents a holistic path toward maximizing LLM inference efficiency.

Summary updated

BibTeX
@article{liao2025beyond,
  author = {Bingli Liao and Danilo Vasconcellos Vargas},
  title = {{Beyond KV Caching: Shared Attention for Efficient LLMs}},
  journal = {Neurocomputing},
  year = {2025},
  doi = {10.1016/j.neucom.2025.130587},
}
Figure