arXiv:2502.04420cs.LGcs.AI2025-02ICML被引 39

提出KVTuner,实现低损耗的分层混合精度键值缓存量化,提升长文本推理效率。

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

  • 基于分层敏感性分析,动态优化每层键值缓存的量化精度。
  • 在数学推理任务上实现3.25比特(Llama-3.1)和4.0比特(Qwen2.5)近无损量化。
  • 离线搜索配置,线上直接应用,支持多模型与硬件约束,灵活高效。

键值缓存量化可在长上下文和大批次场景下提升大型语言模型(LLMs)的推理吞吐量与延迟表现,同时保持模型有效性。然而现有方法存在三大未解难题:忽视各层对键值缓存量化误差的敏感性差异、在线细粒度决策开销高、难以适配不同模型与约束条件。为此,我们从理论上分析了分层Transformer注意力模式与键值缓存量化误差间的内在关联,并研究为何键缓存通常比值缓存对误差降低更为关键。在此基础上,提出简单而高效的框架KVTuner,通过多目标优化自适应搜索粗粒度键值缓存的最优分层混合精度组合,并在离线阶段完成配置,推理时直接调用。为降低离线校准计算成本,引入层内精度对剪枝与层间聚类以压缩搜索空间。实验表明,针对Llama-3.1-8B-Instruct等模型可实现接近无损的3.25比特混合精度量化;对敏感模型如Qwen2.5-7B-Instruct,可达4.0比特。相较于KIVI-KV8量化,最大推理吞吐量提升达21.25%。代码与搜索配置已开源于https://github.com/cmd2001/KVTuner。

原文摘要 · Abstract (English)

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.

量化大模型推理键值缓存混合精度

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。