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

RecurFormer:并非所有 Transformer 头都需要自注意力

RecurFormer: Not All Transformer Heads Need Self-Attention

Nanyang Technological University(南洋理工大学);The University of New South Wales(新南威尔士大学);Shanghai Jiao Tong University(上海交通大学);The College of William and Mary(威廉玛丽学院)

Ruiqing Yan, Linghan Zheng, Xingbo Du, Han Zou, Yufeng Guo, Jianfei Yang

AI总结:

RecurFormer 通过将近期感知的注意力头替换为线性 RNN(Mamba),在保持长程依赖建模和重用预训练权重的同时,显著提升了基于 Transformer 的 LLMs 的推理效率。

摘要:

基于 Transformer 的大型语言模型(LLMs)擅长建模复杂的语言模式,但在推理过程中面临显著的计算成本,尤其是由于注意力机制的内存开销,在处理长输入时更为突出。我们观察到,某些注意力头表现出一种分布,其注意力权重集中在查询 token 附近的 token 上,这被称为近期感知,专注于局部和短程依赖。基于这一洞察,我们提出了 RecurFormer,一种新颖的架构,用线性循环神经网络(RNNs),特别是 Mamba 架构,来替换这些注意力头。这种替换在不驱逐 token 的情况下减少了缓存大小,从而保持生成质量。RecurFormer 通过剩余的注意力头保留了建模长程依赖的能力,并允许通过持续训练重用预训练的基于 Transformer 的 LLMs 权重。实验表明,RecurFormer 在匹配原始模型性能的同时,显著提升了推理效率。我们的方法为基于 Transformer 的 LLMs 推理的计算挑战提供了实用解决方案,使其在涉及长输入的任务中极具吸引力。

英文摘要:

Transformer-based large language models (LLMs) excel in modeling complex language patterns but face significant computational costs during inference, especially with long inputs due to the attention mechanism's memory overhead. We observe that certain attention heads exhibit a distribution where the attention weights concentrate on tokens near the query token, termed as recency aware, which focuses on local and short-range dependencies. Leveraging this insight, we propose RecurFormer, a novel architecture that replaces these attention heads with linear recurrent neural networks (RNNs), specifically the Mamba architecture. This replacement reduces the cache size without evicting tokens, thus maintaining generation quality. RecurFormer retains the ability to model long-range dependencies through the remaining attention heads and allows for reusing pre-trained Transformer-based LLMs weights with continual training. Experiments demonstrate that RecurFormer matches the original model's performance while significantly enhancing inference efficiency. Our approach provides a practical solution to the computational challenges of Transformer-based LLMs inference, making it highly attractive for tasks involving long inputs.

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

↑