arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2402.02750cs.CLcs.LGcs.PF
收藏

KIVI:一种针对KV Cache的免调优非对称2比特量化方法

KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache

Rice University(莱斯大学);Texas A&M University(德克萨斯农工大学);Stevens Institute of Technology(史蒂文斯理工学院);Carnegie Mellon University(卡内基梅隆大学)

Zirui Liu, Jiayi Yuan, Hongye Jin, Shaochen Zhong, Zhaozhuo Xu, Vladimir Braverman, Beidi Chen, Xia Hu

AI总结:

针对大型语言模型中KV缓存内存瓶颈,提出免调优非对称2比特量化算法KIVI,通过分析元素分布对key和value分别采用按通道和按token量化,在保持质量的同时显著降低内存占用并提升吞吐量。

摘要:

高效服务大型语言模型(LLMs)需要对许多请求进行批处理以降低每个请求的成本。然而,随着批处理规模增大和上下文长度增加,用于存储注意力键和值以避免重新计算的键值(KV)缓存会显著增加内存需求,并成为速度和内存使用的新瓶颈。此外,KV缓存的加载导致计算核心处于空闲状态,这限制了推理速度。减少KV缓存大小的一个直接有效的方法是量化,即减少KV缓存占用的总字节数。然而,目前缺乏深入探讨KV缓存元素分布的研究,以理解KV缓存量化的难度和局限性。为了填补这一空白,我们对流行LLMs的KV缓存中的元素分布进行了全面研究。我们的发现表明,key cache应按通道进行量化,即沿通道维度对元素进行分组并一起量化。相反,value cache应按token进行量化。基于此分析,我们开发了一种名为KIVI的免调优2比特KV缓存量化算法。通过硬件友好的实现,KIVI能使Llama、Falcon和Mistral模型在保持几乎相同质量的同时,使用少2.6倍的峰值内存(包括模型权重)。这种内存使用的减少使得批处理规模可增大至4倍,在实际LLM推理工作负载上带来2.35倍至3.47倍的吞吐量。源代码可在 https://github.com/jy-yuan/KIVI 获取。

英文摘要:

Efficiently serving large language models (LLMs) requires batching of many requests to reduce the cost per request. Yet, with larger batch sizes and longer context lengths, the key-value (KV) cache, which stores attention keys and values to avoid re-computations, significantly increases memory demands and becomes the new bottleneck in speed and memory usage. Additionally, the loading of the KV cache causes the computational core to be idle, which limits the inference speed. A straightforward and effective solution to reduce KV cache size is quantization, which decreases the total bytes taken by KV cache. However, there is a lack of in-depth studies that explore the element distribution of KV cache to understand the hardness and limitation of KV cache quantization. To fill the gap, we conducted a comprehensive study on the element distribution in KV cache of popular LLMs. Our findings indicate that the key cache should be quantized per-channel, i.e., group elements along the channel dimension and quantize them together. In contrast, the value cache should be quantized per-token. From this analysis, we developed a tuning-free 2bit KV cache quantization algorithm named KIVI. With hardware-friendly implementation, KIVI can enable Llama, Falcon, and Mistral models to maintain almost the same quality while using $\mathbf{2.6\times}$ less peak memory (including model weight). This reduction in memory usage enables up to $\mathbf{4\times}$ larger batch size, bringing $\mathbf{2.35\times \sim 3.47\times}$ throughput on real LLM inference workload. The source code is available at https://github.com/jy-yuan/KIVI.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑