大型语言模型的门控注意力:非线性、稀疏性与无注意力汇聚

Gated Attention for Large Language Models: Non-linearity, Sparsity, and Attention-Sink-Free

林俊旸 Junyang Lin · Qwen Team, Alibaba · 2025-05-10 · arXiv:2505.06708 ↗ · 被引 224

打开互动全文版(逐段中英对照 + 图/公式 + 论文问答)→

摘要 · Abstract

门控机制已被广泛使用,从早期的 LSTM 和高速公路网络到最近的状态空间模型、线性注意力以及 softmax 注意力。然而,现有文献很少探讨门控的具体效果。在这项工作中,我们进行了全面的实验,系统地研究了门控增强的 softmax 注意力变体。具体来说,我们对 30 种 15B 混合专家(MoE)模型和 1.7B 密集模型进行了全面比较,这些模型在 3.5 万亿 token 数据集上训练。我们的核心发现是,一个简单的修改——在缩放点积注意力(SDPA)后应用头部特定的 sigmoid 门控——能够持续提升性能。这种修改还增强了训练稳定性,容忍更大的学习率,并改善了缩放特性。通过比较各种门控位置和计算变体,我们将这种有效性归因于两个关键因素:(1)在 softmax 注意力的低秩映射中引入非线性,以及(2)应用查询相关的稀疏门控分数来调节 SDPA 输出。值得注意的是,我们发现这种稀疏门控机制缓解了“注意力汇聚”问题,并增强了长上下文外推性能。我们还发布了相关代码和模型,以促进未来的研究。

Gating mechanisms have been widely utilized, from early models like LSTMs and Highway Networks to recent state space models, linear attention, and also softmax attention. Yet, existing literature rarely examines the specific effects of gating. In this work, we conduct comprehensive experiments to systematically investigate gating-augmented softmax attention variants. Specifically, we perform a comprehensive comparison over 30 variants of 15B Mixture-of-Experts (MoE) models and 1.7B dense models trained on a 3.5 trillion token dataset. Our central finding is that a simple modification-applying a head-specific sigmoid gate after the Scaled Dot-Product Attention (SDPA)-consistently improves performance. This modification also enhances training stability, tolerates larger learning rates, and improves scaling properties. By comparing various gating positions and computational variants, we attribute this effectiveness to two key factors: (1) introducing non-linearity upon the low-rank mapping in the softmax attention, and (2) applying query-dependent sparse gating scores to modulate the SDPA output. Notably, we find this sparse gating mechanism mitigates 'attention sink' and enhances long-context extrapolation performance, and we also release related $\href{https://github.com/qiuzh20/gated_attention}{codes}$ and $\href{https://huggingface.co/QwQZh/gated_attention}{models}$ to facilitate future research.

核心贡献 · Key contributions

局限 · Limitations

论文章节 · Sections(共 15)

阅读逐段中英对照全文 →