mlsanityData to 14 Oct 2026

S2-Attention: Hardware-Aware Context Sharding Among Attention Heads

arXiv 2407.17678 ↗First posted 25 Jul 2024cs.CLcited by 0

Not on the map. Why?

Abstract (arXiv)

Sparse attention, which selectively attends to a subset of tokens in the context was supposed to be efficient. However, its theoretical reduction in FLOPs has rarely translated into wall-clock speed-up over its dense attention counterparts due to the lack of hardware-aware optimizations like FlashAttention. Meanwhile, it remains unclear whether sparse attention can maintain the model's quality at a scale of today's large language models (LLMs) and how. This paper presents Sparsely-Sharded(S2) Attention, a Triton library that provides kernel optimization for sparse attention customizable at both per-head and per-context-range levels. S2-Attention enables the exploration of novel and high-performance sparse attention techniques, which we demonstrate through extensive ablations across a wide range of sparse attention designs at various model scales. From these insights, we present several basic guidelines to design sparse attention that can achieve not only practical efficiency improvements, but also strong downstream performance. To achieve high parallelization and optimized memory IO, sparse attention should shard the context heterogeneously across attention heads, where each head attends to a different subset of tokens while collectively covering the full context. Meanwhile, we find hybrid architectures combining sparse and dense attention particularly beneficial in practice. S2-Attention achieves wall-clock speedup of 8.79X, 15.87X, 25.3X compared to the strong FlashAttention-2 baseline with strong downstream performance on-par with full attention and perfect retrieval performance at a 128k context length. At inference, for 7B models, our model, with the help of our S2-Attention kernel, achieves 4.5x speed-up compared to dense counterparts. S2-Attention is released with easy-to-customize APIs for direct usage in Megatron and vLLM.

Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 17 of its 20 references that are in the map. First posted on arXiv 25 Jul 2024.

Builds on

17 of 20 references.

References · 17

  1. 2023Efficient Memory Management for Large Language Model Serving with PagedAttentioncited by 5,944
  2. 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,673
  3. 2020Longformer: The Long-Document Transformercited by 3,413
  4. 2023FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioningcited by 2,598
  5. 2020Transformers are RNNs: Fast Autoregressive Transformers with Linear Attentioncited by 2,022
  6. 2020Big Bird: Transformers for Longer Sequencescited by 1,684
  7. 2020Reformer: The Efficient Transformercited by 1,668
  8. 2019Generating Long Sequences with Sparse Transformerscited by 1,546
  9. 2024The FineWeb Datasets: Decanting the Web for the Finest Text Data at Scalecited by 1,160
  10. 2020Efficient Transformers: A Surveycited by 790
  11. 2019Axial Attention in Multidimensional Transformerscited by 358
  12. 2022Tensor Programs V: Tuning Large Neural Networks via Zero-Shot Hyperparameter Transfercited by 288
5 more
  1. 2024Retrieval Head Mechanistically Explains Long-Context Factualitycited by 232
  2. 2024Data Engineering for Scaling Language Models to 128K Contextcited by 186
  3. 2019Blockwise Self-Attention for Long Document Understandingcited by 159
  4. 2022Pyramid-BERT: Reducing Complexity via Successive Core-set based Token Selectioncited by 13
  5. 2024Efficient Language Adaptive Pre-training: Extending State-of-the-Art Large Language Models for Polishcited by 4

Built on by

Not cited yet.