更长的注意力跨度:利用稀疏图处理技术增加Transformer上下文长度
Longer Attention Span: Increasing Transformer Context Length with Sparse Graph Processing Techniques
AI总结:
本文提出将注意力机制视为图计算问题,通过图处理算法实现真正稀疏的注意力计算,在单块A100 GPU上支持高达1.6亿的序列长度,并显著超越FlashAttention的执行速度。
摘要:
Transformer在自然语言处理和生物信息学等众多领域取得了巨大成功。这一成功源于这些模型使用注意力机制来表示和传播序列数据中各个token之间的成对交互。然而,该操作的主要局限在于其相对于输入上下文长度(即需要捕获交互的序列长度)的二次方内存和时间复杂度。这极大地限制了这些模型能够进行推理的序列长度。已有大量研究通过开发稀疏注意力掩码,在注意力机制中引入稀疏性,从而将成对交互的数量降低到相对于上下文长度的次二次方复杂度。然而,能够实现“真正稀疏性”的高效实现仍然缺乏。\n\n在这项工作中,我们通过提出一种图计算视角来解决这一问题,在该视角下,token被视为图的节点,注意力掩码决定图的边。利用这一视角,我们开发了图处理算法来实现注意力机制。我们从理论和实验两方面证明,我们的算法只执行所需的计算,即它们是工作最优的。我们还使用流行的注意力掩码进行了大量实验,以探索稀疏性对执行时间和可实现的上下文长度的影响。我们的实验表明,与FlashAttention等最先进的注意力实现相比,对于大序列长度,我们的算法在执行时间上实现了显著加速。我们还证明,我们的算法能够在单个NVIDIA A100 GPU(SXM4 80GB)上实现高达1.6亿的极长序列长度。
英文摘要:
Transformers have demonstrated great success in numerous domains including natural language processing and bioinformatics. This success stems from the use of the attention mechanism by these models in order to represent and propagate pairwise interactions between individual tokens of sequential data. However, the primary limitation of this operation is its quadratic memory and time complexity in relation to the input's context length - the length of a sequence over which the interactions need to be captured. This significantly limits the length of sequences that can be inferred upon by these models. Extensive research has been conducted to reduce the number of pairwise interactions to sub-quadratic in relation to the context length by introducing sparsity into the attention mechanism through the development of sparse attention masks. However, efficient implementations that achieve "true sparsity" are lacking. In this work, we address this issue by proposing a graph computing view of attention where tokens are perceived as nodes of the graph and the attention mask determines the edges of the graph. Using this view, we develop graph processing algorithms to implement the attention mechanism. Both theoretically and empirically, we demonstrate that our algorithms only perform the needed computations, i.e., they are work optimal. We also perform extensive experimentation using popular attention masks to explore the impact of sparsity on execution time and achievable context length. Our experiments demonstrate significant speedups in execution times compared to state-of-the-art attention implementations such as FlashAttention for large sequence lengths. We also demonstrate that our algorithms are able to achieve extremely long sequence lengths of as high as 160 million on a single NVIDIA A100 GPU (SXM4 80GB).
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。