arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.04420cs.LGcs.AIcs.CL

KVTuner: 一种面向层间敏感性的混合精度KV缓存量化方法,用于高效且接近无损的LLM推理

KVTuner: Sensitivity-Aware Layer-Wise Mixed-Precision KV Cache Quantization for Efficient and Nearly Lossless LLM Inference

Huawei Noah's Ark Lab(华为诺亚实验室);The Chinese University of Hong Kong(香港中文大学);Huawei Computing Product Line(华为计算产品线)

Xing Li, Zeyu Xing, Yiming Li, Linping Qu, Hui-Ling Zhen, Wulong Liu, Yiwu Yao, Sinno Jialin Pan, Mingxuan Yuan

AI总结:

KVTuner通过多目标优化实现高效且接近无损的LLM推理,适用于不同模型和约束条件。

摘要:

KV缓存量化可以提高大型语言模型(LLMs)在长上下文和大批次大小场景下的推理吞吐量和延迟,同时保持LLMs的有效性。然而,当前方法存在三个未解决的问题:忽视层间对KV缓存量化敏感性、在线细粒度决策的高开销以及对不同LLMs和约束的低灵活性。因此,我们从理论上分析层间Transformer注意力模式与KV缓存量化误差之间的内在相关性,并研究为什么键缓存通常比值缓存更重要以减少量化误差。我们进一步提出一个简单而有效的框架KVTuner,以自适应搜索最优的硬件友好层间KV量化精度对,用于粗粒度的KV缓存,并通过多目标优化进行直接利用。为了减少离线校准的计算成本,我们利用层内KV精度对剪枝和层间聚类来减少搜索空间。实验结果表明,我们可以在数学推理任务上实现接近无损的3.25位混合精度KV缓存量化,如Llama-3.1-8B-Instruct,以及4.0位用于敏感模型如Qwen2.5-7B-Instruct。最大推理吞吐量可以比KIVI-KV8量化提高21.25%,在各种上下文长度上。我们的代码和搜索配置可在https://github.com/cmd2001/KVTuner上获得。

英文摘要:

KV cache quantization can improve Large Language Models (LLMs) inference throughput and latency in long contexts and large batch-size scenarios while preserving LLMs effectiveness. However, current methods have three unsolved issues: overlooking layer-wise sensitivity to KV cache quantization, high overhead of online fine-grained decision-making, and low flexibility to different LLMs and constraints. Therefore, we theoretically analyze the inherent correlation of layer-wise transformer attention patterns to KV cache quantization errors and study why key cache is generally more important than value cache for quantization error reduction. We further propose a simple yet effective framework KVTuner to adaptively search for the optimal hardware-friendly layer-wise KV quantization precision pairs for coarse-grained KV cache with multi-objective optimization and directly utilize the offline searched configurations during online inference. To reduce the computational cost of offline calibration, we utilize the intra-layer KV precision pair pruning and inter-layer clustering to reduce the search space. Experimental results show that we can achieve nearly lossless 3.25-bit mixed precision KV cache quantization for LLMs like Llama-3.1-8B-Instruct and 4.0-bit for sensitive models like Qwen2.5-7B-Instruct on mathematical reasoning tasks. The maximum inference throughput can be improved by 21.25\% compared with KIVI-KV8 quantization over various context lengths. Our code and searched configurations are available at https://github.com/cmd2001/KVTuner.

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

↑