Transformers with linear attention allow for efficient parallel training but can simultaneously be formulated as an RNN with 2D (matrix-valued) hidden states, thus enjoying linear (with respect to output length) inference complexity. Recent works such as RetNet (Sun et al., 2023) and TransNormerLLM (Qin et al., 2023a) observe that adding a global decay term to the additive RNN update rule greatly improves performance, sometimes outperforming standard Transformers with softmax attention when trained at scale. In this work we show that adding a data-dependent gating mechanism further improves performance. We derive a parallel form of this gated linear attention layer that enables efficient training. However, a straightforward, numerically stable implementation of this parallel form requires generalized matrix multiplications in log-space for numerical stability, and thus cannot take advantage of tensor cores on modern GPUs which are optimized for standard matrix multiplications. We develop a hardware-efficient version of the parallel form that can still make use of tensor cores through block-parallel computations over sequence chunks. Experiments on moderate-scale language modeling (340M-parameter models trained on 15B tokens, 1.3B-parameter models trained on 100B tokens) show that gated linear attention (GLA) Transformers perform competitively against a strong LLaMA-architecture Transformer baseline (Touvron et al., 2023) as well as Mamba (Gu & Dao, 2023), a recently introduced state-space model with a data-dependent state transition mechanism. For training speed, our Triton-based implementation performs comparably to CUDA-optimized FlashAttention-2 (Dao, 2023) under the regular 2048 training length setting, while outperforming FlashAttention-2 when training on longer sequences beyond 4096.


翻译:具有线性注意力的Transformer不仅支持高效的并行训练,还能同时表示为具有二维(矩阵值)隐藏状态的RNN,从而在推理时实现与输出长度呈线性关系的复杂度。近期工作如RetNet(Sun等,2023)和TransNormerLLM(Qin等,2023a)发现,在加性RNN更新规则中加入全局衰减项可大幅提升性能,有时在规模化训练中甚至超越采用softmax注意力的标准Transformer。本研究证明,引入依赖于数据的门控机制可进一步改善性能。我们推导出这种门控线性注意力层的并行形式,从而实现高效训练。然而,该并行形式在数值稳定性上需要采用对数空间中的广义矩阵乘法,因此无法利用现代GPU上专为标准矩阵乘法优化的张量核心。我们开发了一种硬件高效的并行实现版本,通过序列分块的块并行计算仍能使用张量核心。中等规模语言建模实验(参数为3.4亿的模型在150亿词元上训练、参数为13亿的模型在1000亿词元上训练)表明:门控线性注意力(GLA)Transformer在性能上与强基线LLaMA架构Transformer(Touvron等,2023)以及近期引入的具有数据依赖状态转移机制的Mamba状态空间模型(Gu & Dao,2023)相比具有竞争力。在训练速度方面,我们基于Triton的实现与CUDA优化后的FlashAttention-2(Dao,2023)在常规2048训练长度设置下性能相当,而在超过4096的长序列训练中则优于FlashAttention-2。

0
下载
关闭预览

相关内容

FlowQA: Grasping Flow in History for Conversational Machine Comprehension
专知会员服务
34+阅读 · 2019年10月18日
Stabilizing Transformers for Reinforcement Learning
专知会员服务
60+阅读 · 2019年10月17日
《DeepGCNs: Making GCNs Go as Deep as CNNs》
专知会员服务
32+阅读 · 2019年10月17日
Keras François Chollet 《Deep Learning with Python 》, 386页pdf
专知会员服务
164+阅读 · 2019年10月12日
强化学习最新教程,17页pdf
专知会员服务
182+阅读 · 2019年10月11日
【SIGGRAPH2019】TensorFlow 2.0深度学习计算机图形学应用
专知会员服务
41+阅读 · 2019年10月9日
Hierarchically Structured Meta-learning
CreateAMind
27+阅读 · 2019年5月22日
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日
A Technical Overview of AI & ML in 2018 & Trends for 2019
待字闺中
18+阅读 · 2018年12月24日
STRCF for Visual Object Tracking
统计学习与视觉计算组
15+阅读 · 2018年5月29日
Hierarchical Imitation - Reinforcement Learning
CreateAMind
19+阅读 · 2018年5月25日
Focal Loss for Dense Object Detection
统计学习与视觉计算组
12+阅读 · 2018年3月15日
IJCAI | Cascade Dynamics Modeling with Attention-based RNN
KingsGarden
13+阅读 · 2017年7月16日
From Softmax to Sparsemax-ICML16(1)
KingsGarden
74+阅读 · 2016年11月26日
国家自然科学基金
2+阅读 · 2017年12月31日
国家自然科学基金
13+阅读 · 2017年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
Learning Implicit Fields for Generative Shape Modeling
Arxiv
11+阅读 · 2018年12月6日
VIP会员
最新内容
重新思考无人机时代的生存能力
专知会员服务
4+阅读 · 今天7:44
装甲突击旅:现代战争思考、战斗与组织
专知会员服务
4+阅读 · 今天7:28
在人工智能加速决策环境中拓展OODA循环
专知会员服务
4+阅读 · 今天7:18
军事欺骗:供作战战术指挥官使用的工具
专知会员服务
4+阅读 · 今天7:03
综述 | 世界动作模型:少做梦,多行动
专知会员服务
5+阅读 · 6月23日
美以伊冲突:无人机与人工智能的运用
专知会员服务
10+阅读 · 6月23日
《特种部队在透明战场中的生存力》最新报告
专知会员服务
5+阅读 · 6月23日
相关VIP内容
相关资讯
Hierarchically Structured Meta-learning
CreateAMind
27+阅读 · 2019年5月22日
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日
A Technical Overview of AI & ML in 2018 & Trends for 2019
待字闺中
18+阅读 · 2018年12月24日
STRCF for Visual Object Tracking
统计学习与视觉计算组
15+阅读 · 2018年5月29日
Hierarchical Imitation - Reinforcement Learning
CreateAMind
19+阅读 · 2018年5月25日
Focal Loss for Dense Object Detection
统计学习与视觉计算组
12+阅读 · 2018年3月15日
IJCAI | Cascade Dynamics Modeling with Attention-based RNN
KingsGarden
13+阅读 · 2017年7月16日
From Softmax to Sparsemax-ICML16(1)
KingsGarden
74+阅读 · 2016年11月26日
相关基金
国家自然科学基金
2+阅读 · 2017年12月31日
国家自然科学基金
13+阅读 · 2017年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员