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

通过跨层注意力减小 Transformer 键值缓存大小

Reducing Transformer Key-Value Cache Size with Cross-Layer Attention

MIT CSAIL(麻省理工学院计算机科学与人工智能实验室);MIT-IBM Watson AI Lab(麻省理工学院-IBM沃森人工智能实验室)

William Brandon, Mayank Mishra, Aniruddha Nrusimha, Rameswar Panda, Jonathan Ragan Kelly

AI总结:

本文提出 Cross-Layer Attention(CLA),在 MQA 基础上让相邻层共享键值头,将 KV 缓存再减半,并在 1B、3B 模型训练中验证其内存-准确率帕累托优势。

摘要:

键值(KV)缓存在加速基于 Transformer 的自回归大语言模型(LLM)解码方面发挥着关键作用。然而,在序列长度较长且批量较大时,存储 KV 缓存所需的内存可能会高得令人难以承受。自 Transformer 发明以来,人们发现用于减小 KV 缓存大小的两种最有效干预措施是 Multi-Query Attention(MQA,多查询注意力)及其推广形式 Grouped-Query Attention(GQA,分组查询注意力)。MQA 和 GQA 都修改了注意力块的设计,使多个查询头可以共享同一个键/值头,从而大幅减少不同键/值头的数量,同时仅造成极小的准确率下降。在本文中,我们表明可以将 Multi-Query Attention 再推进一步:让相邻层之间也共享键头和值头,由此得到一种新的注意力设计,我们称之为 Cross-Layer Attention(CLA,跨层注意力)。借助 CLA,我们发现可以将 KV 缓存的大小再减小 2 倍,同时保持与未经修改的 MQA 几乎相同的准确率。在从零开始训练 10 亿和 30 亿参数模型的实验中,我们证明 CLA 相对于传统 MQA 所能实现的内存/准确率权衡提供了帕累托改进,使推理能够支持原本无法实现的更长序列长度和更大批量。

英文摘要:

Key-value (KV) caching plays an essential role in accelerating decoding for transformer-based autoregressive large language models (LLMs). However, the amount of memory required to store the KV cache can become prohibitive at long sequence lengths and large batch sizes. Since the invention of the transformer, two of the most effective interventions discovered for reducing the size of the KV cache have been Multi-Query Attention (MQA) and its generalization, Grouped-Query Attention (GQA). MQA and GQA both modify the design of the attention block so that multiple query heads can share a single key/value head, reducing the number of distinct key/value heads by a large factor while only minimally degrading accuracy. In this paper, we show that it is possible to take Multi-Query Attention a step further by also sharing key and value heads between adjacent layers, yielding a new attention design we call Cross-Layer Attention (CLA). With CLA, we find that it is possible to reduce the size of the KV cache by another 2x while maintaining nearly the same accuracy as unmodified MQA. In experiments training 1B- and 3B-parameter models from scratch, we demonstrate that CLA provides a Pareto improvement over the memory/accuracy tradeoffs which are possible with traditional MQA, enabling inference with longer sequence lengths and larger batch sizes than would otherwise be possible

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

↑