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

基于Transformer的线性注意力与优化GPU内核实现

Transformer Based Linear Attention with Optimized GPU Kernel Implementation

Department of Computer Science, Umiacs University of Maryland College Park, MD(计算机科学系,乌米亚茨大学马里兰大学学院公园分校)

Armin Gerami, Ramani Duraiswami

AI总结:

针对线性注意力实际效率低于理论的问题,提出优化的前向/反向传播及CUDA内核,实现3.3倍加速和3.6倍内存缩减,并在14亿参数模型上验证了与常规注意力相当的性能。

摘要:

在极为成功的Transformer架构中,原始的基于softmax的注意力机制(常规注意力)计算N个token之间的注意力,每个token嵌入在D维头中,时间复杂度为O(N^2D)。鉴于Transformer的成功,在训练和推理过程中提升其运行速度是一个热门研究领域。其中一种方法是引入线性注意力(LA)机制,该机制提供O(ND^2)的线性时间复杂度,并已展现出与常规注意力相当的准确性。然而,线性注意力在实际应用中落后于其理论效率。我们提出了一种新颖的线性注意力前向和反向传播方法,以及高度优化的CUDA实现。我们的方法在速度上比现有最先进技术快3.3倍,并将内存消耗降低3.6倍。我们通过训练一个14亿参数的语言模型,在单层和端到端设置中验证了这些改进,该模型在主要推理基准上展现出与常规注意力相似的表达能力。

英文摘要:

The original softmax-based attention mechanism (regular attention) in the extremely successful Transformer architecture computes attention between $N$ tokens, each embedded in a $D$-dimensional head, with a time complexity of $O(N^2D)$. Given the success of Transformers, improving their runtime during both training and inference is a popular research area. One such approach is the introduction of the linear attention (LA) mechanisms, which offers a linear time complexity of $O(ND^2)$ and have demonstrated comparable accuracy to regular attention. However, LA in practice lags behind its theoretical efficiency. We propose a novel method for LA's forward and backward passes, along with a highly-optimized CUDA implementation. Our approach outperforms the state-of-the-art by 3.3 times in speed and reduces memory consumption by 3.6 times. We validate these improvements in both single-layer and end-to-end settings by training a 1.4 billion parameter language model, which demonstrates similar expressivity to regular attention on major reasoning benchmarks.

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

↑