Language models struggle to generalize beyond pretraining context lengths, limiting long-horizon reasoning and retrieval. Continued pretraining on long-context data can help but is expensive due to the quadratic scaling of Attention. We observe that most tokens do not require (Global) Attention over the entire sequence and can rely on local context. Based on this, we propose L2A (Learning To Attend), a layer that enables conditional (token-wise) long-range memory access by deciding when to invoke global attention. We evaluate L2A on Qwen 2.5 and Qwen 3 models, extending their effective context length from 32K to 128K tokens. L2A matches the performance of standard long-context training to within 3% while skipping Global Attention for $\sim$80% of tokens, outperforming prior baselines. We also design custom Triton kernels to efficiently implement this token-wise conditional Attention on GPUs, achieving up to $\sim$2x improvements in training throughput and time-to-first-token over FlashAttention. Moreover, L2A enables post-training pruning of highly sparse Global Attention layers, reducing KV cache memory by up to 50% with negligible performance loss.


翻译:语言模型难以泛化超出预训练上下文长度的范围,这限制了其长程推理与检索能力。在长上下文数据上持续预训练虽能缓解此问题,但由于注意力机制存在二次方复杂度,其代价高昂。我们观察到,大多数词元并不需要对整个序列进行(全局)注意力计算,而可以依赖局部上下文。基于此,我们提出L2A(学习何时关注)层,该层通过决策何时调用全局注意力,实现了条件化(按词元)的长程记忆访问。我们在Qwen 2.5和Qwen 3模型上评估L2A,将其有效上下文长度从32K词元扩展至128K词元。L2A在跳过约80%词元的全局注意力计算的同时,其性能与标准长上下文训练的差距在3%以内,优于现有基线方法。我们还设计了定制化的Triton内核,以在GPU上高效实现这种按词元的条件化注意力机制,相比FlashAttention,训练吞吐量和首词生成时间最高可提升约2倍。此外,L2A支持对高度稀疏的全局注意力层进行训练后剪枝,在性能损失可忽略的情况下,将KV缓存内存降低最高达50%。

0
下载
关闭预览

相关内容

《语言模型的推理时间学习算法》162页博士论文
专知会员服务
14+阅读 · 2025年11月23日
「知识增强预训练语言模型」最新研究综述
专知
18+阅读 · 2022年11月18日
长文本表示学习概述
云栖社区
15+阅读 · 2019年5月9日
从Seq2seq到Attention模型到Self Attention(一)
量化投资与机器学习
76+阅读 · 2018年10月8日
深度学习中的注意力机制
人工智能头条
16+阅读 · 2017年11月2日
国家自然科学基金
6+阅读 · 2017年12月31日
国家自然科学基金
43+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
31+阅读 · 2015年12月31日
国家自然科学基金
12+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
VIP会员
最新内容
DeepSeek 版Claude Code,免费小白安装教程来了!
专知会员服务
0+阅读 · 今天16:16
《美空军条令出版物 2-0:情报(2026版)》
专知会员服务
6+阅读 · 今天13:54
帕兰提尔 Gotham:一个游戏规则改变器
专知会员服务
5+阅读 · 今天13:34
【综述】 机器人学习中的世界模型:全面综述
伊朗的导弹-无人机行动及其对美国威慑的影响
相关VIP内容
《语言模型的推理时间学习算法》162页博士论文
专知会员服务
14+阅读 · 2025年11月23日
相关基金
国家自然科学基金
6+阅读 · 2017年12月31日
国家自然科学基金
43+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
31+阅读 · 2015年12月31日
国家自然科学基金
12+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员