KVPruner: Structural Pruning for Faster and Memory-Efficient Large Language Models

Bo Lv, Quan Zhou, Xuanang Ding, Yan Wang, Zeyu Ma2024

Abstract

The deployment of Large Language Models (LLMs) is increasingly constrained by the memory overhead of the Key-Value (KV) cache, particularly in long-context applications like Retrieval-Augmented Generation (RAG). This paper introduces KVPruner, a structural pruning framework that specifically targets the KV cache dimensions. By utilizing a two-phase approach—global perplexity-based sensitivity analysis followed by local channel importance evaluation—KVPruner achieves significant memory reductions. Experimental results on LLaMA-7B demonstrate a 50% reduction in KV cache memory and a 35% boost in throughput with minimal performance loss, recoverable through a brief 2-hour LoRA fine-tuning process.

Introduction

The "KV cache" bottleneck is a primary challenge in LLM inference. As sequence lengths grow, the memory required to store previous tokens' keys and values scales linearly, often exceeding the capacity of standard hardware. Existing optimization strategies like width pruning (removing neurons) often fail to provide real-world speedups, while depth pruning (removing layers) typically results in severe accuracy degradation requiring extensive retraining. KVPruner addresses these issues by providing a hardware-friendly, structural pruning method that is both memory-efficient and fast to recover.

Methodology

KVPruner operates through a "one-shot" structural pruning pipeline consisting of two main phases:

  1. Global Pruning Ratio Awareness: Recognizing that Transformer blocks contribute unequally to model performance, KVPruner measures the Perplexity (PPL) deviation for each block. Analysis reveals a "U-shaped" sensitivity curve, where the initial and final blocks are highly sensitive, while middle layers exhibit higher redundancy. This allows for aggressive pruning in middle layers and conservative pruning in critical ones.
  2. Local Channel Importance Evaluation: Within each block, the importance of specific channels in the Query (Q), Key (K), Value (V), and Output (O) matrices is assessed. The framework evaluates metrics such as L1/L2 norms and the Taylor method (gradient-based approximation) to identify the most expendable channels.
The KVPruner methodology involves global sensitivity analysis followed by local channel importance evaluation and pruning.

Following pruning, the model undergoes a rapid recovery phase using Low-Rank Adaptation (LoRA) fine-tuning on datasets like WikiText2, typically requiring only two hours to restore performance levels.

Key Results

Evaluations using LLaMA-7B on WikiText2 and PTB datasets show that KVPruner outperforms state-of-the-art methods like LLM-Pruner and Shortened-LLM.

  • Memory and Throughput: KVPruner reduces KV cache memory usage by 50%. On NVIDIA A100 and RTX 3090 GPUs, this translates to a throughput increase of over 35% in tokens per second.
  • Model Performance: At a 20% pruning ratio, KVPruner maintains a WikiText2 PPL of 14.55, superior to LLM-Pruner (15.73) and Shortened-LLM (16.29).
KVPruner demonstrates superior perplexity (PPL) and throughput compared to existing pruning methods.

Conclusion

KVPruner offers a practical solution for scaling LLM inference by directly addressing the KV cache bottleneck. Its structural approach ensures compatibility with standard GPU kernels like FlashAttention, providing immediate hardware acceleration. Future work will explore the framework's scalability to larger models (70B+) and its integration with Feed-Forward Network (FFN) pruning for even higher compression ratios.

Summary updated

BibTeX
@misc{lv2024kvpruner,
  author = {Bo Lv and Quan Zhou and Xuanang Ding and Yan Wang and Zeyu Ma},
  title = {{KVPruner: Structural Pruning for Faster and Memory-Efficient Large Language Models}},
  year = {2024},
  eprint = {2409.11057},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2409.11057},
}
Figure