arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2502.14837cs.CLcs.AI
收藏

迈向经济推理:在任意基于Transformer的大语言模型中实现DeepSeek的多头潜在注意力(MLA)

Towards Economical Inference: Enabling DeepSeek's Multi-Head Latent Attention in Any Transformer-based LLMs

School of Computer Science, Fudan University(复旦大学计算机科学学院);School of Computer Science and Technology, East China Normal University(华东师范大学计算机科学与技术学院);Institute of Modern Languages and Linguistics, Fudan University(复旦大学现代语言与语言学研究所);Institute of Trustworthy Embodied Artificial Intelligence, Fudan University(复旦大学可信具身人工智能研究所);Shanghai Collaborative Innovation Center of Intelligent Visual Computing(上海智能视觉计算协同创新中心);Pengcheng Laboratory(鹏城实验室);Hikvision Inc(海康威视公司)

Tao Ji, Bin Guo, Yuanbin Wu, Qipeng Guo, Lixing Shen, Zhan Chen, Xipeng Qiu, Qi Zhang, Tao Gui

AI总结:

本研究提出首个MHA转MLA的数据高效微调方法MHA2MLA,通过部分RoPE调整与联合SVD近似策略,仅用少量数据即可让现有LLM适配MLA架构,大幅压缩KV缓存、降低推理成本且性能损失极小。

摘要:

多头潜在注意力(Multi-head Latent Attention,MLA)是DeepSeek提出的一种创新架构,旨在通过将键值(Key-Value,KV)缓存显著压缩为潜在向量,实现高效经济的推理。与MLA相比,采用多头注意力(Multi-Head Attention,MHA)及其变体(如分组查询注意力Grouped-Query Attention,GQA)的标准大语言模型(LLM)存在明显的成本劣势。让训练成熟的LLM(例如Llama)无需从头预训练就能快速适配MLA,既具意义又充满挑战。本文提出了首个用于从MHA向MLA迁移的数据高效微调方法MHA2MLA,该方法包含两个核心组件:针对部分RoPE(旋转位置编码),我们从对注意力得分贡献较小的查询和键维度中移除RoPE;针对低秩近似,我们基于预训练的键和值参数引入联合SVD(奇异值分解)近似。这些精心设计的策略使MHA2MLA仅需使用极小比例(0.3%至0.6%)的数据就能恢复性能,在显著降低推理成本的同时,还能与KV缓存量化等压缩技术无缝集成。例如,Llama2-7B的KV缓存大小减少了92.19%,而LongBench性能仅下降0.5%。

英文摘要:

Multi-head Latent Attention (MLA) is an innovative architecture proposed by DeepSeek, designed to ensure efficient and economical inference by significantly compressing the Key-Value (KV) cache into a latent vector. Compared to MLA, standard LLMs employing Multi-Head Attention (MHA) and its variants such as Grouped-Query Attention (GQA) exhibit significant cost disadvantages. Enabling well-trained LLMs (e.g., Llama) to rapidly adapt to MLA without pre-training from scratch is both meaningful and challenging. This paper proposes the first data-efficient fine-tuning method for transitioning from MHA to MLA (MHA2MLA), which includes two key components: for partial-RoPE, we remove RoPE from dimensions of queries and keys that contribute less to the attention scores, for low-rank approximation, we introduce joint SVD approximations based on the pre-trained parameters of keys and values. These carefully designed strategies enable MHA2MLA to recover performance using only a small fraction (0.3% to 0.6%) of the data, significantly reducing inference costs while seamlessly integrating with compression techniques such as KV cache quantization. For example, the KV cache size of Llama2-7B is reduced by 92.19%, with only a 0.5% drop in LongBench performance.

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

↑