arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.14366cs.CLcs.AIcs.LG

MiniCache:面向大语言模型的深度维度 KV Cache 压缩

MiniCache: KV Cache Compression in Depth Dimension for Large Language Models

Monash University(莫纳什大学);Zhejiang University(浙江大学)

Akide Liu, Jing Liu, Zizheng Pan, Yefei He, Gholamreza Haffari, Bohan Zhuang

AI总结:

本文提出无需训练的 MiniCache,通过跨层合并中深层相似 KV 状态并保留特殊 token,在多模型和基准上实现高压缩、高吞吐且近乎无损。

摘要:

高效部署计算需求高昂的大语言模型(LLM)的一种关键方法是键值(KV)缓存。KV cache 存储先前已生成 token 的键值状态,可显著减少重复计算需求,从而降低自回归生成中的延迟。然而,KV cache 的大小会随序列长度线性增长,这给需要长上下文输入和大量序列生成的应用带来了挑战。本文提出一种简单而有效的方法,名为 MiniCache,从全新的深度视角跨层压缩 KV cache,显著降低 LLM 推理的内存占用。该方法基于如下观察:在 LLM 中到深层部分,相邻层之间的 KV cache 状态表现出高度相似性。为便于合并,作者提出将状态解耦为幅度和方向分量,在保持状态向量长度不变的同时对其方向进行插值。此外,论文引入一种 token 保留策略,使高度不同的状态对不被合并,从而以极小的额外存储开销保留信息。MiniCache 无需训练且具有通用性,可补充量化和稀疏性等现有 KV cache 压缩策略。作者使用 LLaMA-2、LLaMA-3、Phi-3、Mistral 和 Mixtral 等多种模型,在多个基准上对 MiniCache 进行了全面评估,证明其在实现优异压缩率和高吞吐量方面表现出色。在 ShareGPT 数据集上,采用 4-bit MiniCache 的 LLaMA-2-7B 实现了高达 5.02 倍的显著压缩率,推理吞吐量提升约 5 倍,并且与 FP16 完整缓存基线相比内存占用降低 41%,同时保持近乎无损的性能。

英文摘要:

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.

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

↑