arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.05462cs.LGcs.DS
收藏

LevAttention:面向高权重注意力的时间、空间与流式高效算法

LevAttention: Time, Space, and Streaming Efficient Algorithm for Heavy Attentions

Simons Institute, UC Berkeley(西蒙斯研究所,加州大学伯克利分校);Google Research(谷歌研究院);Carnegie Mellon University(卡内基梅隆大学)

Ravindran Kannan, Chiranjib Bhattacharyya, Praneeth Kacham, David P. Woodruff

AI总结:

该研究提出基于杠杆得分的LevAttention机制,在线性时间内找出所有大注意力分数对应的通用键集合,无需数据假设、空间不随序列长度增长,支持流式与并行计算,在视觉Transformer训练中可稳定筛选重要键。

摘要:

Transformer相关的一个核心问题可表述为:给定两个n×d矩阵Q和K,以及一个非负函数f,按如下方式定义矩阵A:(1) 对n×n矩阵QK^T的每个元素应用函数f,然后(2) 将A的每一行的行和归一化为1。假设f对单个数值的应用为常数时间,矩阵A的计算时间复杂度为O(n²d),但当n对应长上下文长度时,这种与n的二次依赖关系在实际应用中难以承受。\n针对一大类函数f,我们展示了如何在与n呈线性依赖的时间(即n·poly(d/ε),其中ε>0为正参数)内找出所有“大注意力分数”,也就是A中值不小于正值ε的元素。我们的函数类别包含所有形如f(x)=|x|^p的函数,这类函数近期已在Transformer模型中得到探索。利用随机数值线性代数领域最新开发的工具,我们证明对于任意K,存在一个大小与n无关的“通用集合”U⊂[n],使得对于任意Q和任意行i,A的第i行中的大注意力分数A_{i,j}对应的索引j均属于U。我们还能在n·poly(d/ε)时间内求出该集合U。\n值得注意的是:(1) 我们对数据不做任何假设;(2) 我们的工作空间不随n增长;(3) 我们的算法可在流式与并行场景下计算。我们将仅使用通用集合中键子集的注意力机制命名为LevAttention,因为我们识别通用集合U的算法基于杠杆得分(leverage scores)。我们通过实验验证了该方案在视觉Transformer上的优势,展示了如何在训练过程中也使用我们的通用集合来训练新模型,结果表明我们的模型能够在训练期间持续筛选出“重要键”。

英文摘要:

A central problem related to transformers can be stated as follows: given two $n \times d$ matrices $Q$ and $K$, and a non-negative function $f$, define the matrix $A$ as follows: (1) apply the function $f$ to each entry of the $n \times n$ matrix $Q K^T$, and then (2) normalize each of the row sums of $A$ to be equal to $1$. The matrix $A$ can be computed in $O(n^2 d)$ time assuming $f$ can be applied to a number in constant time, but the quadratic dependence on $n$ is prohibitive in applications where it corresponds to long context lengths. For a large class of functions $f$, we show how to find all the ``large attention scores", i.e., entries of $A$ which are at least a positive value $\varepsilon$, in time with linear dependence on $n$ (i.e., $n \cdot \textrm{poly}(d/\varepsilon)$) for a positive parameter $\varepsilon > 0$. Our class of functions include all functions $f$ of the form $f(x) = |x|^p$, as explored recently in transformer models. Using recently developed tools from randomized numerical linear algebra, we prove that for any $K$, there is a ``universal set" $U \subset [n]$ of size independent of $n$, such that for any $Q$ and any row $i$, the large attention scores $A_{i,j}$ in row $i$ of $A$ all have $j \in U$. We also find $U$ in $n \cdot \textrm{poly}(d/\varepsilon)$ time. Notably, we (1) make no assumptions on the data, (2) our workspace does not grow with $n$, and (3) our algorithms can be computed in streaming and parallel settings. We call the attention mechanism that uses only the subset of keys in the universal set as LevAttention since our algorithm to identify the universal set $U$ is based on leverage scores. We empirically show the benefits of our scheme for vision transformers, showing how to train new models that use our universal set while training as well, showing that our model is able to consistently select ``important keys'' during training.

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

↑