The increasing demand for long-context modeling in large language models (LLMs) is bottlenecked by the quadratic complexity of the standard self-attention mechanism. The community has proposed sparse attention to mitigate this issue. However, position-aware sparse attention methods rely on static sparse structures that lack adaptability to diverse query contexts, while content-aware sparse attention methods depend on heuristic key-value selection, hindering full differentiability. We introduce a trainable dynamic mask sparse attention mechanism, a method that merges the advantages of both position-aware and content-aware approaches. Dynamic Mask Attention (DMA) achieves this through three key innovations: First, it leverages value vector representations to generate content-aware dynamic masks, enabling the model to adaptively identify and attend to critical information. Second, it computes position-aware sparse weights in a hardware-friendly manner, efficiently skipping unnecessary computational regions. Finally, we demonstrate that the introduced dynamic mask and sparse weights do not obstruct gradients, supporting end-to-end training. We have validated the performance of DMA through comprehensive experiments. A large body of experimental evidence shows that DMA consistently holds a Pareto advantage over state-of-the-art sparse attention baselines in tasks including scaling laws, multi-query associative recall, standard benchmarks, and needle in a haystack tests, while also delivering up to a 10x overall speedup. These results highlight its ability to effectively balance model efficiency with long-context modeling capabilities. Our computational kernel code is now open-source at https://github.com/SmallDoges/flash-dmattn to encourage further research and application by the community.


翻译:大型语言模型(LLMs)对长上下文建模的需求日益增长,但标准自注意力机制的二次复杂度成为其瓶颈。学界已提出稀疏注意力以缓解此问题。然而,基于位置的稀疏注意力方法依赖于静态稀疏结构,缺乏对不同查询上下文的适应性;而基于内容的稀疏注意力方法则依赖启发式的键值选择,阻碍了完全可微性。本文提出一种可训练动态掩码稀疏注意力机制,该方法融合了基于位置和基于内容两种方法的优势。动态掩码注意力(DMA)通过三项关键创新实现这一目标:首先,它利用值向量表示生成内容感知的动态掩码,使模型能够自适应地识别并关注关键信息;其次,它以硬件友好的方式计算位置感知的稀疏权重,高效跳过不必要的计算区域;最后,我们证明所引入的动态掩码和稀疏权重不会阻碍梯度传播,支持端到端训练。我们通过全面实验验证了DMA的性能。大量实验证据表明,在包括缩放定律、多查询关联召回、标准基准测试以及“大海捞针”测试等任务中,DMA相较于最先进的稀疏注意力基线始终具有帕累托优势,同时还能实现高达10倍的整体加速。这些结果突显了其在模型效率与长上下文建模能力之间有效平衡的能力。我们的计算内核代码已在 https://github.com/SmallDoges/flash-dmattn 开源,以促进学界的进一步研究和应用。

0
下载
关闭预览

相关内容

FlowQA: Grasping Flow in History for Conversational Machine Comprehension
专知会员服务
34+阅读 · 2019年10月18日
Stabilizing Transformers for Reinforcement Learning
专知会员服务
60+阅读 · 2019年10月17日
Keras François Chollet 《Deep Learning with Python 》, 386页pdf
专知会员服务
163+阅读 · 2019年10月12日
Transferring Knowledge across Learning Processes
CreateAMind
29+阅读 · 2019年5月18日
Unsupervised Learning via Meta-Learning
CreateAMind
44+阅读 · 2019年1月3日
meta learning 17年:MAML SNAIL
CreateAMind
11+阅读 · 2019年1月2日
STRCF for Visual Object Tracking
统计学习与视觉计算组
15+阅读 · 2018年5月29日
Focal Loss for Dense Object Detection
统计学习与视觉计算组
12+阅读 · 2018年3月15日
国家自然科学基金
13+阅读 · 2017年12月31日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
Arxiv
19+阅读 · 2020年7月13日
Efficiently Embedding Dynamic Knowledge Graphs
Arxiv
14+阅读 · 2019年10月15日
Arxiv
13+阅读 · 2019年4月9日
Exploring Visual Relationship for Image Captioning
Arxiv
15+阅读 · 2018年9月19日
Arxiv
14+阅读 · 2018年5月15日
VIP会员
相关VIP内容
相关资讯
Transferring Knowledge across Learning Processes
CreateAMind
29+阅读 · 2019年5月18日
Unsupervised Learning via Meta-Learning
CreateAMind
44+阅读 · 2019年1月3日
meta learning 17年:MAML SNAIL
CreateAMind
11+阅读 · 2019年1月2日
STRCF for Visual Object Tracking
统计学习与视觉计算组
15+阅读 · 2018年5月29日
Focal Loss for Dense Object Detection
统计学习与视觉计算组
12+阅读 · 2018年3月15日
相关论文
Arxiv
19+阅读 · 2020年7月13日
Efficiently Embedding Dynamic Knowledge Graphs
Arxiv
14+阅读 · 2019年10月15日
Arxiv
13+阅读 · 2019年4月9日
Exploring Visual Relationship for Image Captioning
Arxiv
15+阅读 · 2018年9月19日
Arxiv
14+阅读 · 2018年5月15日
相关基金
国家自然科学基金
13+阅读 · 2017年12月31日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员