mlsanityData to 7 Oct 2026

Faster Neighborhood Attention: Reducing the O(n^2) Cost of Self Attention at the Threadblock Level

arXiv 2403.04690 ↗First posted 7 Mar 2024cs.CV cs.AI cs.LGcited by 14

Not on the map. Why?

Abstract (arXiv)

Neighborhood attention reduces the cost of self attention by restricting each token's attention span to its nearest neighbors. This restriction, parameterized by a window size and dilation factor, draws a spectrum of possible attention patterns between linear projection and self attention. Neighborhood attention, and more generally sliding window attention patterns, have long been bounded by infrastructure, particularly in higher-rank spaces (2-D and 3-D), calling for the development of custom kernels, which have been limited in either functionality, or performance, if not both. In this work, we aim to massively improve upon existing infrastructure by providing two new methods for implementing neighborhood attention. We first show that neighborhood attention can be represented as a batched GEMM problem, similar to standard attention, and implement it for 1-D and 2-D neighborhood attention. These kernels on average provide 895% and 272% improvement in full precision runtime compared to existing naive CUDA kernels for 1-D and 2-D neighborhood attention respectively. We find that aside from being heavily bound by memory bandwidth, certain inherent inefficiencies exist in all unfused implementations of neighborhood attention, which in most cases undo their theoretical efficiency gain. Motivated by the progress made into fused dot-product attention kernels, we developed fused neighborhood attention; an adaptation of fused dot-product attention kernels that allow fine-grained control over attention across different spatial axes. Known for reducing the quadratic time complexity of self attention to a linear complexity, neighborhood attention can now enjoy a reduced and constant memory footprint, and record-breaking half precision runtime. We observe that our fused implementation successfully circumvents some of the unavoidable inefficiencies in unfused implementations...

Key facts. Cited by 14 papers in the map (data through 7 Oct 2026). Builds on 20 of its 26 references that are in the map. First posted on arXiv 7 Mar 2024.

Builds on

20 of 26 references.

References · 20

  1. 2017Attention Is All You Needcited by 59,932
  2. 2015Deep Residual Learning for Image Recognitioncited by 51,809
  3. 2020An Image is Worth 16x16 Words: Transformers for Image Recognition at Scalecited by 29,915
  4. 2019PyTorch: An Imperative Style, High-Performance Deep Learning Librarycited by 20,160
  5. 2022Scalable Diffusion Models with Transformerscited by 5,931
  6. 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,611
  7. 2020Longformer: The Long-Document Transformercited by 3,362
  8. 2023Mistral 7Bcited by 3,065
  9. 2023FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioningcited by 2,551
  10. 2020Big Bird: Transformers for Longer Sequencescited by 1,673
  11. 2021ViViT: A Video Vision Transformercited by 1,610
  12. 2019Generating Long Sequences with Sparse Transformerscited by 1,523
8 more
  1. 2018Image Transformercited by 770
  2. 2019Stand-Alone Self-Attention in Vision Modelscited by 542
  3. 2022Neighborhood Attention Transformercited by 235
  4. 2021Scaling Local Self-Attention for Parameter Efficient Visual Backbonescited by 220
  5. 2018Online normalizer calculation for softmaxcited by 154
  6. 2021Self-attention Does Not Need O(n2) Memorycited by 152
  7. 2022Dilated Neighborhood Attention Transformercited by 64
  8. 2022Efficient Image Generation with Variadic Attention Headscited by 17

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2024: 2; 2025: 9; 2026: 3.

14 papers.

Sort:

By area: