ChatPaper.aiChatPaper

Snellere Causale Aandacht Over Grote Sequenties Via Sparse Flash Attention

Faster Causal Attention Over Large Sequences Through Sparse Flash Attention

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

Samenvatting

Transformer-gebaseerde taalmodelen hebben veel uiteenlopende toepassingen gevonden waarbij ze steeds langere sequenties moeten verwerken. Voor deze toepassingen wordt de causale self-attention -- het enige onderdeel dat kwadratisch schaalt ten opzichte van de sequentielengte -- een centrale zorg. Hoewel veel onderzoeken voorstellen om de aandachtspatronen te verspreiden en de rekenkosten van self-attention te verminderen, worden deze vaak beperkt door implementatieproblemen en resulteren ze in een eenvoudige en statische structuur van de aandachtmatrix. Aan de andere kant leiden meer dynamische, verspreide aandachtspatronen vaak tot aanzienlijk langere uitvoeringstijden vergeleken met het berekenen van de volledige aandacht met behulp van de Flash-implementatie van Dao et al. (2022). Wij breiden FlashAttention uit om een grote klasse van aandachtssparsiteitpatronen te ondersteunen, waaronder het weglaten van sleutel/query en op hashing gebaseerde aandacht. Dit resulteert in implementaties zonder extra rekencomplexiteit en een meervoudige versnelling van de uitvoeringstijd bovenop FlashAttention. Zelfs bij relatief lage sparsiteitsgraden verbetert onze methode zichtbaar ten opzichte van FlashAttention naarmate de sequentielengte toeneemt. Zonder in te leveren op perplexiteit verhogen we de trainingssnelheid van een transformer-taalmodel met 2,0 keer en 3,3 keer voor sequenties van respectievelijk 8k en 16k tokens.
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.
PDF12February 8, 2026