GEAR: An Efficient KV Cache Compression Recipe for Near-Lossless Generative Inference of LLM
作者: Hao Kang, Qingru Zhang, Souvik Kundu, Geonhwa Jeong, Zaoxing Liu, Tushar Krishna, Tuo Zhao
分类: cs.LG, cs.AI, cs.CL
发布日期: 2024-03-08 (更新: 2024-09-30)
🔗 代码/项目: GITHUB
💡 一句话要点
提出GEAR以解决LLM推理中的KV缓存压缩问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: KV缓存压缩 大型语言模型 推理优化 量化技术 低秩矩阵 稀疏矩阵 生成模型
📋 核心要点
- 现有的KV缓存压缩方法在处理长序列时,容易导致高近似误差,影响生成性能。
- GEAR通过超低精度量化、低秩矩阵近似和稀疏矩阵修正,提出了一种高效的KV缓存压缩方案。
- 实验结果显示,GEAR在4位KV缓存压缩下,吞吐量提升达2.38倍,峰值内存减少至2.29倍。
📝 摘要(中文)
随着序列长度的增加,关键值(KV)缓存已成为加速大型语言模型(LLM)推理生成速度的标准。然而,缓存需求的增长使得LLM推理变成了一个受内存限制的问题,显著制约了系统的吞吐量。现有方法依赖于丢弃不重要的标记或均匀量化所有条目,但这些方法往往会导致高近似误差,从而影响模型生成的准确性。为此,本文提出了GEAR,一个高效的KV缓存压缩框架,能够实现近乎无损的高比率压缩。GEAR首先对大多数相似幅度的条目进行超低精度量化,然后利用低秩矩阵来近似量化误差,并通过稀疏矩阵来修正个别异常条目的误差。实验表明,与其他方法相比,GEAR实现了近乎无损的4位KV缓存压缩,吞吐量提升高达2.38倍,同时峰值内存大小减少至2.29倍。
🔬 方法详解
问题定义:本文旨在解决大型语言模型(LLM)推理中KV缓存的压缩问题。现有方法在处理长序列时,往往通过丢弃不重要的标记或均匀量化所有条目,导致高近似误差,从而影响生成的准确性和性能。
核心思路:GEAR的核心思路是通过结合超低精度量化、低秩矩阵近似和稀疏矩阵修正,来实现高效的KV缓存压缩。这样的设计旨在最大限度地减少压缩过程中的信息损失,从而保持生成的质量。
技术框架:GEAR的整体架构包括三个主要模块:首先对大多数相似幅度的条目进行超低精度量化;其次,利用低秩矩阵来近似量化误差;最后,通过稀疏矩阵修正个别异常条目的误差。
关键创新:GEAR的最重要创新在于其通过三种技术的协同作用,实现了近乎无损的高比率压缩。这与现有方法的本质区别在于,GEAR不仅关注压缩比,还重视生成质量的保持。
关键设计:在设计中,GEAR采用了超低精度量化策略,具体参数设置为4位;低秩矩阵的选择基于主成分分析,稀疏矩阵则通过L1正则化来优化,以确保修正效果最佳。整体损失函数设计考虑了压缩误差与生成质量的平衡。
🖼️ 关键图片
📊 实验亮点
GEAR在实验中实现了近乎无损的4位KV缓存压缩,吞吐量提升高达2.38倍,峰值内存大小减少至2.29倍。这些结果表明,GEAR在保持生成质量的同时,显著提高了系统的效率,优于现有的压缩方法。
🎯 应用场景
GEAR的研究成果在多个领域具有潜在应用价值,尤其是在需要高效推理的自然语言处理任务中,如对话系统、文本生成和机器翻译等。通过提高推理速度和降低内存需求,GEAR能够使得大型语言模型在资源受限的环境中更为实用,推动相关技术的广泛应用与发展。
📄 摘要(原文)
Key-value (KV) caching has become the de-facto to accelerate generation speed for large language models (LLMs) inference. However, the growing cache demand with increasing sequence length has transformed LLM inference to be a memory bound problem, significantly constraining the system throughput. Existing methods rely on dropping unimportant tokens or quantizing all entries uniformly. Such methods, however, often incur high approximation errors to represent the compressed matrices. The autoregressive decoding process further compounds the error of each step, resulting in critical deviation in model generation and deterioration of performance. To tackle this challenge, we propose GEAR, an efficient KV cache compression framework that achieves near-lossless high-ratio compression. GEAR first applies quantization to majority of entries of similar magnitudes to ultra-low precision. It then employs a low rank matrix to approximate the quantization error, and a sparse matrix to remedy individual errors from outlier entries. By adeptly integrating three techniques, GEAR is able to fully exploit their synergistic potentials. Our experiments demonstrate that compared to alternatives, GEAR achieves near-lossless 4-bit KV cache compression with up to 2.38x throughput improvement, while reducing peak-memory size up to 2.29x. Our code is publicly available at https://github.com/HaoKang-Timmy/GEAR.