SimLayerKV: A Simple Framework for Layer-Level KV Cache Reduction

Xuan Zhang, Cunxiao Du, Chao Du, Tianyu Pang, Wei Gao, Min Lin · DOI

As Large Language Models (LLMs) scale to handle massive contexts exceeding 100K tokens, they encounter a significant "memory wall." The primary bottleneck is the Key-Value (KV) cache, which stores past token information to accelerate generation. Because this cache grows linearly with sequence length, it quickly exhausts GPU memory and slows down inference throughput.

While hybrid architectures—mixing standard attention with more efficient mechanisms like RNNs or Mamba—offer a solution, they typically require training from scratch, which is prohibitively expensive. SimLayerKV introduces the LIGHTTRANSFER framework to bridge this gap, transforming existing, high-performing Transformers (like LLaMA or Mistral) into efficient hybrid models with minimal effort.

Identifying "Lazy Layers"

The core insight of SimLayerKV is that not all layers in a Transformer contribute equally to long-range context processing. The authors observe that many layers are "lazy," exhibiting "attention sink" behavior. These layers primarily focus on the very first few tokens (sinks) and the most recent tokens (the local window), largely ignoring the middle of the context.

Attention weights in a 'lazy' layer (Layer 20), showing focus on initial sink tokens and recent local tokens.

By identifying these lazy layers, the framework can replace their full attention mechanisms with memory-efficient streaming attention. This targeted reduction allows the model to maintain its performance while significantly lowering the memory footprint of the KV cache.

The LIGHTTRANSFER Framework

LIGHTTRANSFER operates by converting standard attention layers into efficient variants that use a fixed-size streaming cache instead of a full linear-growth cache. This transformation creates a hybrid model that balances global context awareness with local efficiency.

Comparison between a standard Transformer and the hybrid model produced by LIGHTTRANSFER.

The framework provides two implementation strategies:

  1. LIGHTTRANSFER-TEST (Training-Free): This mode identifies lazy layers dynamically during the "prefilling" stage. It calculates a Lazy Ratio for each layer on-the-fly using a priority queue. To maintain efficiency, it leverages log-sum-exp values from FlashAttention to compute these ratios without the overhead of recomputing the entire attention matrix. Once identified, the full KV caches for these layers are discarded in favor of a streaming cache.
  2. LIGHTTRANSFER-TRAIN (Minimal Fine-tuning): For complex reasoning tasks where inputs are short but logic is deep, lazy behavior is harder to detect at test time. In these cases, the authors pre-select lazy layers and perform a small amount of Supervised Fine-Tuning (SFT) using only 5,000 samples to help the model adapt to the hybrid structure.

Key Results and Insights

The authors evaluated SimLayerKV across a diverse set of models, including LLaMA-2, LLaMA-3, Mistral, and QwQ-32B, using benchmarks like LongBench and Needle-In-A-Haystack.

  • Throughput and Efficiency: The framework achieved up to a 2.17× throughput boost at 16K context lengths. The overhead for identifying lazy layers is negligible, impacting relative throughput by less than 0.006.
  • Performance Retention: On LongBench, the hybrid models maintained high accuracy with only a 1.45% average decline, even when 50% of the layers were converted to streaming attention.
  • Reasoning Gains: Surprisingly, the fine-tuned variant outperformed the baseline on the difficult AIME24 math benchmark (53.3% vs 46.7%), suggesting that the hybrid structure might act as a beneficial regularizer for deep reasoning tasks.
  • Theoretical Grounding: The authors provide mathematical proof that the error introduced by shortening the KV cache is bounded by the sum of the attention scores of the discarded tokens. By targeting layers with high lazy ratios, the algorithm performs a principled optimization of the model's output error.

Conclusion

SimLayerKV demonstrates that the transition to efficient hybrid architectures does not require massive retraining. By leveraging the natural specialization of Transformer layers, LIGHTTRANSFER provides a simple, effective path to overcoming the KV cache memory wall, enabling existing LLMs to handle longer contexts with significantly higher throughput.

Summary updated

BibTeX
@misc{zhang2024simlayerkv,
  author = {Xuan Zhang and Cunxiao Du and Chao Du and Tianyu Pang and Wei Gao and Min Lin},
  title = {{SimLayerKV: A Simple Framework for Layer-Level KV Cache Reduction}},
  year = {2024},
  eprint = {2410.13846},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.13846},
}
Figure