Compressing KV Cache for Long-Context LLM Inference with Inter-Layer Attention Similarity

Fuente: arXiv
Guardado en:
Detalles Bibliográficos
Autores principales: Ma, Da, Chen, Lu, Zhang, Situo, Miao, Yuxun, Zhu, Su, Chen, Zhi, Xu, Hongshen, Li, Hanqi, Fan, Shuai, Pan, Lei, Yu, Kai
Formato: Preprint
Publicado: 2024
Materias:
Acceso en línea:
Etiquetas: Agregar Etiqueta
Sin Etiquetas, Sea el primero en etiquetar este registro!
_version_ 1866916878584119296
author Ma, Da
Chen, Lu
Zhang, Situo
Miao, Yuxun
Zhu, Su
Chen, Zhi
Xu, Hongshen
Li, Hanqi
Fan, Shuai
Pan, Lei
Yu, Kai
author_facet Ma, Da
Chen, Lu
Zhang, Situo
Miao, Yuxun
Zhu, Su
Chen, Zhi
Xu, Hongshen
Li, Hanqi
Fan, Shuai
Pan, Lei
Yu, Kai
contents The rapid expansion of context window sizes in Large Language Models~(LLMs) has enabled them to tackle increasingly complex tasks involving lengthy documents. However, this progress comes at the cost of a substantial increase in memory usage during inference, primarily due to the linear growth of the key-value~(KV) cache. Existing KV cache compression methods often discard less relevant tokens, which can lead to significant performance degradation when critical information is lost. In this paper, we propose \textsc{PoD}~(Proximal tokens over Distant tokens), a novel KV cache compression framework that allocates memory according to token importance, retaining less important tokens in a more compact, shared form rather than discarding them entirely. Our approach is motivated by two key observations: (1) proximal tokens -- those at the beginning and end of the context -- are significantly more important for next-token prediction, and (2) attention scores for distant tokens are highly redundant across consecutive layers. Leveraging these insights, \textsc{PoD} preserves the full KV cache for proximal tokens, while for distant tokens, it shares key states across layers. Since attention scores are determined by both queries and keys, sharing key states enables multiple layers to reuse a single set of keys for distant tokens, substantially reducing KV cache memory without discarding essential context. We further introduce a lightweight post-training adaptation to enable the model to adjust to this new attention-sharing structure. Extensive experiments on both synthetic~(Needle in a Haystack) and real-world long-context benchmarks demonstrate that \textsc{PoD} reduces KV cache memory usage by up to 35\% without compromising performance. Our method is orthogonal to existing token-selection-based techniques and can be combined with them for further KV cache compression.
format Preprint
id arxiv_https___arxiv_org_abs_2412_02252
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Compressing KV Cache for Long-Context LLM Inference with Inter-Layer Attention Similarity
Ma, Da
Chen, Lu
Zhang, Situo
Miao, Yuxun
Zhu, Su
Chen, Zhi
Xu, Hongshen
Li, Hanqi
Fan, Shuai
Pan, Lei
Yu, Kai
Computation and Language
The rapid expansion of context window sizes in Large Language Models~(LLMs) has enabled them to tackle increasingly complex tasks involving lengthy documents. However, this progress comes at the cost of a substantial increase in memory usage during inference, primarily due to the linear growth of the key-value~(KV) cache. Existing KV cache compression methods often discard less relevant tokens, which can lead to significant performance degradation when critical information is lost. In this paper, we propose \textsc{PoD}~(Proximal tokens over Distant tokens), a novel KV cache compression framework that allocates memory according to token importance, retaining less important tokens in a more compact, shared form rather than discarding them entirely. Our approach is motivated by two key observations: (1) proximal tokens -- those at the beginning and end of the context -- are significantly more important for next-token prediction, and (2) attention scores for distant tokens are highly redundant across consecutive layers. Leveraging these insights, \textsc{PoD} preserves the full KV cache for proximal tokens, while for distant tokens, it shares key states across layers. Since attention scores are determined by both queries and keys, sharing key states enables multiple layers to reuse a single set of keys for distant tokens, substantially reducing KV cache memory without discarding essential context. We further introduce a lightweight post-training adaptation to enable the model to adjust to this new attention-sharing structure. Extensive experiments on both synthetic~(Needle in a Haystack) and real-world long-context benchmarks demonstrate that \textsc{PoD} reduces KV cache memory usage by up to 35\% without compromising performance. Our method is orthogonal to existing token-selection-based techniques and can be combined with them for further KV cache compression.
title Compressing KV Cache for Long-Context LLM Inference with Inter-Layer Attention Similarity
topic Computation and Language
url https://arxiv.org/abs/2412.02252