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

Zihan Qiu, Zekun Wang, Bo Zheng, Zeyu Huang, Kaiyue Wen +8 more
5/10/2025
cs.CL

Official code: qiuzh20/gated_attention (975 stars, MIT, last commit 2025-12-20). 1 more implementation below.

Abstract

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.

View on arXivView PDF

Code Implementations(2)

MIT

The official implementation for [NeurIPS2025 Oral] Gated Attention for Large Language Models: Non-linearity, Sparsity, and Attention-Sink-Free

97561Python, Jupyter NotebookMay 9, 202510 months agoMIT

My implementation of Qwen 3 Next Gated Attention from "GatedAttentionforLarge LanguageModels: Non-linearity,Sparsity, and Attention-Sink-Free, https://arxiv.org/abs/2505.06708

00PythonJan 9, 20269 months ago

Similar Papers

Cite this paper

@article{qiu2025gated,
  title  = {Gated Attention for Large Language Models: Non-linearity, Sparsity, and Attention-Sink-Free},
  author = {Zihan Qiu and Zekun Wang and Bo Zheng and Zeyu Huang and Kaiyue Wen and Songlin Yang and Rui Men and Le Yu and Fei Huang and Suozhi Huang and Dayiheng Liu and Jingren Zhou and Junyang Lin},
  year   = {2025},
  eprint = {2505.06708},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2505.06708v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2505.06708.svg)](https://codeofpaper.com/paper/2505.06708)

Discussion