arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2306.01160cs.LGcs.AIcs.CL
收藏

通过稀疏 Flash Attention 实现长序列上更快的因果注意力

Faster Causal Attention Over Large Sequences Through Sparse Flash Attention

EPFL(洛桑联邦理工学院);University of Geneva(日内瓦大学)

Matteo Pagliardini, Daniele Paliotta, Martin Jaggi, François Fleuret

AI总结:

本文扩展 FlashAttention 以支持 key/query dropping、基于哈希等动态稀疏注意力模式,在无复杂度开销且不损失困惑度的情况下,显著提升长序列语言模型训练速度。

摘要:

基于 Transformer 的语言模型已在众多不同应用中得到使用,这些应用要求它们处理越来越长的序列。对于这些应用,因果自注意力——唯一相对于序列长度呈二次方扩展的组件——成为核心关注点。尽管许多工作提出了稀疏化注意力模式并降低自注意力计算开销的方案,但这些方案往往受到实现方面的限制,最终对注意力矩阵施加简单且静态的结构。相反,实现更动态的稀疏注意力通常会导致运行时间明显慢于使用 Dao 等人(2022)的 Flash 实现计算完整注意力。我们扩展了 FlashAttention,以容纳一大类注意力稀疏模式,其中尤其包括 key/query dropping(键/查询丢弃)和基于哈希的注意力。这带来了没有计算复杂度开销的实现,并在 FlashAttention 之上实现数倍的运行时加速。即使在相对较低的稀疏程度下,随着序列长度增加,我们的方法也明显优于 FlashAttention。在不牺牲困惑度的情况下,对于分别为 8k 和 16k 个 token 的序列,我们将 Transformer 语言模型的训练速度提高了 2.0 倍和 3.3 倍。

英文摘要:

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.0\times$ and $3.3\times$ for sequences of respectively $8k$ and $16k$ tokens.

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

↑