KVSharer: Efficient Inference via Layer-Wise Dissimilar KV Cache Sharing

Yifei Yang, Zouying Cao, Qiguang Chen, Libo Qin, Dongjie Yang +2 more
10/24/2024
cs.LGcs.AIcs.CL

No official code found. Best implementation: yangyifei729/KVSharer (32 stars, last commit 2024-10-24).

Abstract

The development of large language models (LLMs) has significantly expanded model sizes, resulting in substantial GPU memory requirements during inference. The key and value storage of the attention map in the KV (key-value) cache accounts for more than 80\% of this memory consumption. Nowadays, most existing KV cache compression methods focus on intra-layer compression within a single Transformer layer but few works consider layer-wise compression. In this paper, we propose a plug-and-play method called \textit{KVSharer}, which shares the KV cache between layers to achieve layer-wise compression. Rather than intuitively sharing based on higher similarity, we discover a counterintuitive phenomenon: sharing dissimilar KV caches better preserves the model performance. Experiments show that \textit{KVSharer} can reduce KV cache computation by 30\%, thereby lowering memory consumption without significantly impacting model performance and it can also achieve at least 1.3 times generation acceleration. Additionally, we verify that \textit{KVSharer} is compatible with existing intra-layer KV cache compression methods, and combining both can further save memory.

View on arXivView PDF

Code Implementations(1)

Source code of paper ''KVSharer: Efficient Inference via Layer-Wise Dissimilar KV Cache Sharing''

322Python, Jupyter NotebookOct 24, 20241 years ago

Similar Papers

Cite this paper

@article{yang2024kvsharer,
  title  = {KVSharer: Efficient Inference via Layer-Wise Dissimilar KV Cache Sharing},
  author = {Yifei Yang and Zouying Cao and Qiguang Chen and Libo Qin and Dongjie Yang and Hai Zhao and Zhi Chen},
  year   = {2024},
  eprint = {2410.18517},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2410.18517v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2410.18517.svg)](https://codeofpaper.com/paper/2410.18517)

Discussion