用自编码器和缓存复用压缩大模型解码时的键值缓存,显著降低内存占用。
KV-CAR: KV Cache Compression using Autoencoders and KV Reuse in Large Language Models
- 用轻量自编码器压缩键值张量的嵌入维度,减少存储体积。
- 通过相似性检测复用相邻层注意力头的键值,降低结构冗余。
- 在不修改架构前提下,最多节省47.85%缓存内存,适合高效推理部署。
随着大语言模型规模与上下文长度增长,键值(KV)缓存的内存需求已成为自回归解码的主要瓶颈。KV缓存随序列长度和嵌入维度增长,常超过模型自身内存占用,限制批处理大小和上下文窗口。为此,我们提出KV CAR,一种统一且与架构无关的框架,可显著减少KV缓存存储并保持模型精度。该方法结合两种互补技术:首先,轻量自编码器沿嵌入维度学习键值张量的紧凑表示,压缩后存储于缓存,并在检索时恢复;其次,基于相似性的复用机制识别特定注意力头在相邻层间的可复用性。两者共同消除键值张量中的维度与结构冗余,无需修改Transformer架构。在GPT-2和TinyLLaMA模型上,针对Wikitext、C4、PIQA和Winogrande数据集的评估表明,KV CAR实现最高达47.85%的缓存内存缩减,对困惑度和零样本准确率影响极小。NVIDIA A40 GPU上的系统级测量显示,缓存减小直接带来更长序列长度和更大批处理规模。结果证明了KV CAR在提升大模型推理效率方面的有效性。
原文摘要 · Abstract (English)
As Large Language Models (LLMs) scale in size and context length, the memory requirements of the key value (KV) cache have emerged as a major bottleneck during autoregressive decoding. The KV cache grows with sequence length and embedding dimension, often exceeding the memory footprint of the model itself and limiting achievable batch sizes and context windows. To address this challenge, we present KV CAR, a unified and architecture agnostic framework that significantly reduces KV cache storage while maintaining model fidelity. KV CAR combines two complementary techniques. First, a lightweight autoencoder learns compact representations of key and value tensors along the embedding dimension, compressing them before they are stored in the KV cache and restoring them upon retrieval. Second, a similarity driven reuse mechanism identifies opportunities to reuse KV tensors of specific attention heads across adjacent layers. Together, these methods reduce the dimensional and structural redundancy in KV tensors without requiring changes to the transformer architecture. Evaluations on GPT 2 and TinyLLaMA models across Wikitext, C4, PIQA, and Winogrande datasets demonstrate that KV CAR achieves up to 47.85 percent KV cache memory reduction with minimal impact on perplexity and zero shot accuracy. System level measurements on an NVIDIA A40 GPU show that the reduced KV footprint directly translates into longer sequence lengths and larger batch sizes during inference. These results highlight the effectiveness of KV CAR in enabling memory efficient LLM inference.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。