arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2405.05219cs.LGcs.AI
收藏

Conv-Basis:Transformer中高效注意力推理与梯度计算的新范式

Conv-Basis: A New Paradigm for Efficient Attention Inference and Gradient Computation in Transformers

The University of Hong Kong(香港大学);University of Wisconsin-Madison(威斯康星大学麦迪逊分校);The Hong Kong University of Science and Technology(香港科技大学);The Simons Institute for the Theory of Computing at the University of California, Berkeley(加州大学伯克利分校西蒙斯理论计算研究所);Rice University(莱斯大学)

Yingyu Liang, Heshan Liu, Zhenmei Shi, Zhao Song, Zhuoyan Xu, Junze Yin

AI总结:

本文提出Conv-Basis新范式,利用注意力矩阵的类卷积结构,通过快速傅里叶变换将近似注意力推理与梯度计算的时间复杂度降至近乎线性,有效解决了长上下文Transformer的二次计算成本问题。

摘要:

自注意力机制是近期大型语言模型(LLMs)中Transformer成功的关键。然而,输入序列长度$n$带来的二次计算成本$O(n^2)$是进一步改进和扩展更长上下文的 notorious 障碍。在本研究中,我们利用注意力矩阵的类卷积结构,开发了一种使用卷积矩阵进行注意力计算的高效近似方法。我们提出了一个类似于秩基的$\mathsf{conv}$基系统,并证明任何下三角矩阵始终可以分解为该基中结构化卷积矩阵之和。随后,我们设计了一种快速算法,通过$k$个此类卷积矩阵之和来近似注意力矩阵。这使我们能够通过快速傅里叶变换(FFT)在$O(knd \log n)$时间内计算注意力推理,其中$d$为隐藏维度,从而在$kd = n^{o(1)}$的实际场景中实现近乎线性的时间$n^{1+o(1)}$。此外,注意力训练的前向传播和反向梯度也可以在$n^{1+o(1)}$时间内计算。我们提供了关于运行时间和近似误差的理论保证,并进行了初步实验以评估其有效性。我们希望这一加速Transformer模型中注意力计算的新范式能促进其在更长上下文中的应用。

英文摘要:

The self-attention mechanism is the key to the success of transformers in recent Large Language Models (LLMs). However, the quadratic computational cost $O(n^2)$ in the input sequence length $n$ is a notorious obstacle for further improvement and scalability in longer contexts. In this work, we leverage the convolution-like structure of attention matrices to develop an efficient approximation method for attention computation using convolution matrices. We propose a $\mathsf{conv}$ basis system, analogous to the rank basis, and show that any lower triangular matrix can always be decomposed as a sum of structured convolution matrices in this basis. We then design a fast algorithm to approximate the attention matrix via a sum of such $k$ convolution matrices. This allows us to compute the attention {\it inference} via Fast Fourier Transforms (FFT) in $O(knd \log n)$ time, where $d$ is the hidden dimension, and thus achieve almost linear time $n^{1+o(1)}$ in the practical scenario where $kd = n^{o(1)}$. Furthermore, the attention {\it training forward} and {\it backward gradient} can be computed in $n^{1+o(1)}$ as well. We provide theoretical guarantees on the run time and approximation error and conduct preliminary experiments to evaluate its effectiveness. We hope our new paradigm for accelerating attention computation in transformer models can help their application to longer contexts.

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

↑