ChatPaper.aiChatPaper

通过稀疏闪烁注意力实现对大序列的更快因果注意力。

Faster Causal Attention Over Large Sequences Through Sparse Flash Attention

June 1, 2023
作者: Matteo Pagliardini, Daniele Paliotta, Martin Jaggi, François Fleuret
cs.AI

摘要

基于Transformer的语言模型已被广泛应用于处理越来越长的序列,涉及到许多不同的应用场景。对于这些应用,因果自注意力——这是唯一一个与序列长度二次扩展相关的组件——成为一个核心关注点。虽然许多研究提出了稀疏化注意力模式并减少自注意力的计算开销的方案,但这些方案通常受到实现问题的限制,最终会在注意力矩阵上施加一个简单且静态的结构。相反,实现更动态稀疏注意力往往导致运行时明显慢于使用Dao等人(2022年)的Flash实现计算完整注意力。我们扩展了FlashAttention,以适应一大类注意力稀疏模式,特别包括键/查询丢弃和基于哈希的注意力。这导致我们的实现在FlashAttention的基础上不增加计算复杂度开销,并在运行时速度上实现了多倍的加速。即使在相对较低的稀疏度下,我们的方法随着序列长度的增加明显改进了FlashAttention。在不牺牲困惑度的情况下,我们将一个Transformer语言模型的训练速度分别提高了2.0倍和3.3倍,用于8k和16k标记的序列。
English
Transformer-based language models have found many diverse applications requiring them to process sequences of increasing length. For these applications, the causal self-attention -- which is the only component scaling quadratically w.r.t. the sequence length -- becomes a central concern. While many works have proposed schemes to sparsify the attention patterns and reduce the computational overhead of self-attention, those are often limited by implementations concerns and end up imposing a simple and static structure over the attention matrix. Conversely, implementing more dynamic sparse attentions often results in runtimes significantly slower than computing the full attention using the Flash implementation from Dao et al. (2022). We extend FlashAttention to accommodate a large class of attention sparsity patterns that, in particular, encompass key/query dropping and hashing-based attention. This leads to implementations with no computational complexity overhead and a multi-fold runtime speedup on top of FlashAttention. Even with relatively low degrees of sparsity, our method improves visibly upon FlashAttention as the sequence length increases. Without sacrificing perplexity, we increase the training speed of a transformer language model by 2.0times and 3.3times for sequences of respectively 8k and 16k tokens.
PDF12December 15, 2024