Layer-Condensed KV Cache for Efficient Inference of Large Language Models

Haoyi Wu, Kewei Tu
5/17/2024
cs.CL

Official code: whyNLP/LCKV (156 stars, last commit 2025-04-07).

Abstract

Huge memory consumption has been a major bottleneck for deploying high-throughput large language models in real-world applications. In addition to the large number of parameters, the key-value (KV) cache for the attention mechanism in the transformer architecture consumes a significant amount of memory, especially when the number of layers is large for deep language models. In this paper, we propose a novel method that only computes and caches the KVs of a small number of layers, thus significantly saving memory consumption and improving inference throughput. Our experiments on large language models show that our method achieves up to 26$\times$ higher throughput than standard transformers and competitive performance in language modeling and downstream tasks. In addition, our method is orthogonal to existing transformer memory-saving techniques, so it is straightforward to integrate them with our model, achieving further improvement in inference efficiency. Our code is available at https://github.com/whyNLP/LCKV.

View on arXivView PDF

Code Implementations(1)

whyNLP/LCKVOfficial100%

Layer-Condensed KV cache w/ 10 times larger batch size, fewer params and less computation. Dramatic speed up with better task performance. Accepted to ACL 2024.

15614Shell, PythonMar 9, 20241 years ago

Similar Papers

Cite this paper

@article{wu2024layercondensed,
  title  = {Layer-Condensed KV Cache for Efficient Inference of Large Language Models},
  author = {Haoyi Wu and Kewei Tu},
  year   = {2024},
  eprint = {2405.10637},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2405.10637v2}
}

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/2405.10637.svg)](https://codeofpaper.com/paper/2405.10637)

Discussion