[论文解读] MiniCache: KV Cache Compression in Depth Dimension for Large Language Models
MiniCache 提出了一种无需训练的、跨层的 KV 缓存压缩方法,通过分解键值状态为幅值和方向分量,利用深层 Transformer 层之间的层间相似性,实现在相邻层间的高效合并。在 4 位量化下,该方法实现了最高 5.02× 的压缩比,相比 FP16 基线,吞吐量提升 5 倍,内存使用降低 41%,同时在 LLaMA-2 等模型上保持近乎无损的性能。
A critical approach for efficiently deploying computationally demanding large language models (LLMs) is Key-Value (KV) caching. The KV cache stores key-value states of previously generated tokens, significantly reducing the need for repetitive computations and thereby lowering latency in autoregressive generation. However, the size of the KV cache grows linearly with sequence length, posing challenges for applications requiring long context input and extensive sequence generation. In this paper, we present a simple yet effective approach, called MiniCache, to compress the KV cache across layers from a novel depth perspective, significantly reducing the memory footprint for LLM inference. Our approach is based on the observation that KV cache states exhibit high similarity between the adjacent layers in the middle-to-deep portion of LLMs. To facilitate merging, we propose disentangling the states into the magnitude and direction components, interpolating the directions of the state vectors while preserving their lengths unchanged. Furthermore, we introduce a token retention strategy to keep highly distinct state pairs unmerged, thus preserving the information with minimal additional storage overhead. Our MiniCache is training-free and general, complementing existing KV cache compression strategies, such as quantization and sparsity. We conduct a comprehensive evaluation of MiniCache utilizing various models including LLaMA-2, LLaMA-3, Phi-3, Mistral, and Mixtral across multiple benchmarks, demonstrating its exceptional performance in achieving superior compression ratios and high throughput. On the ShareGPT dataset, LLaMA-2-7B with 4-bit MiniCache achieves a remarkable compression ratio of up to 5.02x, enhances inference throughput by approximately 5x, and reduces the memory footprint by 41% compared to the FP16 full cache baseline, all while maintaining near-lossless performance.
研究动机与目标
- 为解决自回归 LLM 推理中 KV 缓存带来的高内存占用问题,尤其是在长上下文长度下的情况。
- 探索并利用 LLM 深度维度上 KV 缓存状态的层间冗余,这一方向此前被忽视。
- 设计一种无需训练、可泛化的压缩方法,与现有的量化和稀疏化策略相辅相成。
- 在大幅降低内存使用的同时,保持近乎无损的性能,并提升推理吞吐量。
- 通过基于向量分解的简单而高效的合并策略,实现长上下文 LLM 的高效部署。
提出的方法
- 使用重参数化方法,类似于权重归一化,将 KV 缓存状态分解为幅值和方向分量,以支持稳定的层间合并。
- 在保持幅值不变的前提下,对相邻层状态的方向分量进行插值,从而实现对相似状态的精确合并。
- 引入一种标记保留策略,识别并保留高度不同的状态对,以避免合并过程中的信息丢失。
- 从网络的中深层部分开始,跨多个层应用该方法,因为此处层间相似性最高。
- 与现有压缩技术(如 4 位量化和稀疏化)无缝集成,进一步提升整体内存效率。
- 以端到端、仅推理的方式运行,无需微调或再训练。

实验结果
研究问题
- RQ1KV 缓存状态中的层间冗余能否被有效利用,以减少 LLM 推理中的内存占用?
- RQ2如何在保留模型性能的前提下,准确合并相邻层的 KV 缓存状态?
- RQ3在深度维度上合并 KV 缓存状态对推理速度和内存消耗有何影响?
- RQ4与均值平均或完整 FP16 缓存等基线方法相比,MiniCache 在精度和效率方面表现如何?
- RQ5MiniCache 能否与量化等其他压缩技术结合,实现更大的性能增益?
主要发现
- 在 ShareGPT 基准测试中,使用 4 位 MiniCache 的 LLaMA-2-7B 实现了 5.02× 的压缩比,相比 FP16 基线内存占用降低 41%。
- 在相同设置下,MiniCache 将推理吞吐量提升了约 5 倍,显著提升了服务效率。
- 该方法保持了近乎无损的性能,在 GSM8K、COQA 和 TruthfulQA 等多个基准测试中,生成质量下降极小。
- 性能提升在深层尤为显著,因为此处层间相似性最高,验证了从中深层开始合并的核心设计选择。
- MiniCache 显著优于简单的均值基线合并策略,证明了其幅值-方向分解与选择性保留机制的有效性。
- 该方法在多种模型(包括 LLaMA-2、LLaMA-3、Phi-3、Mistral 和 Mixtral)上均表现出色,跨架构类型保持一致的性能增益。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。