arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2405.17381cs.CL
收藏

长度各异,速度恒定:基于Lightning Attention的高效语言建模

Various Lengths, Constant Speed: Efficient Language Modeling with Lightning Attention

TapTap;Shanghai AI Lab(上海人工智能实验室)

Zhen Qin, Weigao Sun, Dong Li, Xuyang Shen, Weixuan Sun, Yiran Zhong

AI总结:

本研究提出Lightning Attention线性注意力方案,通过分块计算消除cumsum问题、结合GPU分块优化实现不同序列长度下的恒速训练,配套定制TransNormerLLM架构,在效率优于同类模型的同时,性能比肩顶尖传统Transformer结构大语言模型。

摘要:

我们提出了Lightning Attention,这是首个在固定内存消耗下,针对不同序列长度都能保持恒定训练速度的线性注意力实现方案。由于累积求和运算(cumsum)存在问题,以往的线性注意力实现方案在因果场景下无法发挥其理论优势。而通过采用不同的注意力计算策略来处理注意力的不同部分,可有效解决这一问题。具体而言,我们将注意力计算拆分为块内和块间两部分,对块内部分使用常规注意力计算,对块间部分使用线性注意力核技巧,从而消除了线性注意力计算中对cumsum的需求。此外,我们在前向和反向过程中都采用了分块技术,以充分利用GPU硬件。为了在保持效率的同时提升准确率,我们推出了TransNormerLLM(TNL),这是专为我们的闪电注意力定制的全新架构。我们在标准数据集和自行收集的数据集上,针对不同模型规模和序列长度开展了严格测试。TNL的效率明显优于其他语言模型。此外,基准测试结果表明,TNL的性能与采用传统Transformer结构的顶尖大语言模型(LLM)相当。源代码已发布于github.com/OpenNLPLab/TransnormerLLM。

英文摘要:

We present Lightning Attention, the first linear attention implementation that maintains a constant training speed for various sequence lengths under fixed memory consumption. Due to the issue with cumulative summation operations (cumsum), previous linear attention implementations cannot achieve their theoretical advantage in a casual setting. However, this issue can be effectively solved by utilizing different attention calculation strategies to compute the different parts of attention. Specifically, we split the attention calculation into intra-blocks and inter-blocks and use conventional attention computation for intra-blocks and linear attention kernel tricks for inter-blocks. This eliminates the need for cumsum in the linear attention calculation. Furthermore, a tiling technique is adopted through both forward and backward procedures to take full advantage of the GPU hardware. To enhance accuracy while preserving efficacy, we introduce TransNormerLLM (TNL), a new architecture that is tailored to our lightning attention. We conduct rigorous testing on standard and self-collected datasets with varying model sizes and sequence lengths. TNL is notably more efficient than other language models. In addition, benchmark results indicate that TNL performs on par with state-of-the-art LLMs utilizing conventional transformer structures. The source code is released at github.com/OpenNLPLab/TransnormerLLM.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑