新架构NHA融合线性与全注意力,高效处理长序列且保持高召回。
Native Hybrid Attention for Efficient Sequence Modeling
- 在层内层间统一设计混合注意力,用滑动窗口+线性RNN存长期记忆
- 在长文本任务上超越Transformer和现有混合模型,召回率提升显著
- 仅调窗口大小即可平滑切换效率与精度,适合部署在资源受限场景
Transformers在序列建模中表现优异,但存在二次复杂度问题;线性注意力虽提升效率,却常牺牲长上下文的召回准确率。本文提出原生混合注意力(Native Hybrid Attention, NHA),一种将线性与全注意力集成于统一层结构的新型混合架构,支持层内与层间混合。NHA通过线性RNN更新键值槽以保留长期上下文,并用滑动窗口引入短期令牌进行增强。单一softmax注意力操作作用于所有键值对,实现逐标记、逐头的上下文相关加权,无需额外融合参数。层间行为由单个超参数——滑动窗口大小控制,可平滑调节从纯线性到全注意力的过渡,同时保持所有层结构一致。实验表明,NHA在需要高召回的任务及常识推理任务中优于Transformer和其他混合基线。此外,预训练大模型可结构化地替换为NHA,实现竞争力准确率的同时获得显著效率提升。代码已开源:https://github.com/JusenD/NHA。
原文摘要 · Abstract (English)
Transformers excel at sequence modeling but face quadratic complexity, while linear attention offers improved efficiency but often compromises recall accuracy over long contexts. In this work, we introduce Native Hybrid Attention (NHA), a novel hybrid architecture of linear and full attention that integrates both intra & inter-layer hybridization into a unified layer design. NHA maintains long-term context in key-value slots updated by a linear RNN, and augments them with short-term tokens from a sliding window. A single softmax attention operation is then applied over all keys and values, enabling per-token and per-head context-dependent weighting without requiring additional fusion parameters. The inter-layer behavior is controlled through a single hyperparameter, the sliding window size, which allows smooth adjustment between purely linear and full attention while keeping all layers structurally uniform. Experimental results show that NHA surpasses Transformers and other hybrid baselines on recall-intensive and commonsense reasoning tasks. Furthermore, pretrained LLMs can be structurally hybridized with NHA, achieving competitive accuracy while delivering significant efficiency gains. Code is available at https://github.com/JusenD/NHA.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。