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.


翻译:随着大语言模型(LLMs)的规模与上下文长度不断增长,自回归解码过程中键值(KV)缓存的内存需求已成为主要瓶颈。KV缓存随序列长度和嵌入维度线性增长,其内存占用量常超过模型本身,限制了可实现的批处理大小与上下文窗口。为应对这一挑战,我们提出了KV-CAR——一个统一且架构无关的框架,能在保持模型保真度的同时显著降低KV缓存存储需求。KV-CAR融合了两种互补技术:首先,一个轻量级自编码器沿嵌入维度学习键值张量的紧凑表示,在存入KV缓存前进行压缩,并在读取时恢复;其次,基于相似性的重用机制识别相邻层间特定注意力头的KV张量重用机会。这两种方法共同减少了KV张量在维度和结构上的冗余,且无需改变Transformer架构。在GPT-2与TinyLLaMA模型上,基于Wikitext、C4、PIQA和Winogrande数据集的评估表明,KV-CAR最高可实现47.85%的KV缓存内存压缩,同时对困惑度与零样本准确率影响极小。在NVIDIA A40 GPU上的系统级测试显示,降低的KV内存占用量直接转化为推理过程中更长的序列长度与更大的批处理规模。这些结果凸显了KV-CAR在实现内存高效LLM推理方面的有效性。

0
下载
关闭预览

相关内容

【NeurIPS2024】TableRAG:基于语言模型的百万标记表格理解
专知会员服务
37+阅读 · 2024年10月8日
《用于代码弱点识别的 LLVM 中间表示》CMU
专知会员服务
14+阅读 · 2022年12月12日
AAAI 2022 | ProtGNN:自解释图神经网络
专知
10+阅读 · 2022年2月28日
【NeurIPS2019】图变换网络:Graph Transformer Network
国家自然科学基金
2+阅读 · 2016年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
2+阅读 · 2016年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员