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

MatryoshkaKV:基于可训练正交投影的自适应KV压缩

MatryoshkaKV: Adaptive KV Compression via Trainable Orthogonal Projection

Shanghai Jiao Tong University(上海交通大学);Huawei(华为);University of California, San Diego(加州大学圣地亚哥分校)

Bokai Lin, Zihao Zeng, Zipeng Xiao, Siqi Kou, Tianqi Hou, Xiaofeng Gao, Hao Zhang, Zhijie Deng

AI总结:

针对大语言模型推理中KV缓存的存储与传输瓶颈,提出MatryoshkaKV方法,通过可训练正交投影在特征维度实现自适应KV压缩,在高压缩率下仍能保持优异性能。

摘要:

KV缓存已成为大语言模型(LLM)推理的事实标准技术,它引入形状为(层数、头数、序列长度、特征维度)的张量来缓存自注意力的历史信息。随着模型规模和数据量的增长,KV缓存会迅速成为系统在存储和内存传输方面的瓶颈。为解决这一问题,已有研究通常聚焦于缓存张量的前三个维度进行压缩。本文对这些研究进行补充,聚焦于特征维度轴,利用低秩投影矩阵将缓存特征转换到维度更低的空间中。我们首先研究了通过主成分分析(PCA)实现数据压缩的经典正交投影方法,观察到PCA投影存在低压缩率下性能显著下降的问题。为弥补这一缺陷,我们提出采用精心设计的Matryoshka训练策略,以蒸馏为目标直接调整正交投影矩阵。训练完成后,我们在不同的压缩预算下,自适应地为各层和各注意力头搜索最优压缩率。与已有工作相比,我们的方法能够轻松适配预训练大语言模型,并在性能和压缩率之间实现平滑的权衡。我们通过实验验证了训练过程的高数据效率,并发现在LLaMA2-7B-base和Mistral-7B-v0.3-base等主流大语言模型上,该方法在平均60%的KV缓存压缩率(极端场景下最高可达75%)下,仍能保持90%以上的性能。

英文摘要:

KV cache has become a de facto technique for the inference of large language models (LLMs), where tensors of shape (layer number, head number, sequence length, feature dimension) are introduced to cache historical information for self-attention. As the size of the model and data grows, the KV cache can quickly become a bottleneck within the system in both storage and memory transfer. To address this, prior studies usually focus on the first three axes of the cache tensors for compression. This paper supplements them, focusing on the feature dimension axis, by utilizing low-rank projection matrices to transform the cache features into spaces with reduced dimensions. We begin by investigating the canonical orthogonal projection method for data compression through principal component analysis (PCA). We observe the issue with PCA projection where significant performance degradation is observed at low compression rates. To bridge the gap, we propose to directly tune the orthogonal projection matrices with a distillation objective using an elaborate Matryoshka training strategy. After training, we adaptively search for the optimal compression rates for various layers and heads given varying compression budgets. Compared to previous works, our method can easily embrace pre-trained LLMs and hold a smooth tradeoff between performance and compression rate. We empirically witness the high data efficiency of our training procedure and find that our method can sustain over 90% performance with an average KV cache compression rate of 60% (and up to 75% in certain extreme scenarios) for popular LLMs like LLaMA2-7B-base and Mistral-7B-v0.3-base.

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

↑