Faster Neighborhood Attention: Reducing the O(n^2) Cost of Self Attention at the Threadblock Level
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
- 2017Attention Is All You Needcited by 59,932
- 2015Deep Residual Learning for Image Recognitioncited by 51,809
- 2020An Image is Worth 16x16 Words: Transformers for Image Recognition at Scalecited by 29,915
- 2019PyTorch: An Imperative Style, High-Performance Deep Learning Librarycited by 20,160
- 2022Scalable Diffusion Models with Transformerscited by 5,931
- 2022FlashAttention: Fast and Memory-Efficient Exact Attention with IO-Awarenesscited by 3,611
- 2020Longformer: The Long-Document Transformercited by 3,362
- 2023Mistral 7Bcited by 3,065
- 2023FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioningcited by 2,551
- 2020Big Bird: Transformers for Longer Sequencescited by 1,673
- 2021ViViT: A Video Vision Transformercited by 1,610
- 2019Generating Long Sequences with Sparse Transformerscited by 1,523
8 more
- 2018Image Transformercited by 770
- 2019Stand-Alone Self-Attention in Vision Modelscited by 542
- 2022Neighborhood Attention Transformercited by 235
- 2021Scaling Local Self-Attention for Parameter Efficient Visual Backbonescited by 220
- 2018Online normalizer calculation for softmaxcited by 154
- 2021Self-attention Does Not Need O(n2) Memorycited by 152
- 2022Dilated Neighborhood Attention Transformercited by 64
- 2022Efficient Image Generation with Variadic Attention Headscited by 17
Built on by
Citing papers per year: 2024: 2; 2025: 9; 2026: 3.
14 papers.
Sort:
By area:
- 2024Flex Attention: A Programming Model for Generating Optimized Attention Kernelscited by 180
- 2025Generalized Neighborhood Attention: Multi-dimensional Sparse Attention at the Speed of Lightcited by 16
- 2025InvFusion: Bridging Supervised and Zero-shot Diffusion for Inverse Problemscited by 9
- 2025Attention on the Spherecited by 9
- 2025NAF: Zero-Shot Feature Upsampling via Neighborhood Attention Filteringcited by 6
- 2025WeatherMesh-3: Fast and accurate operational global weather forecastingcited by 4
- 2025Enhancing 3D Semantic Scene Completion with a Refinement Modulecited by 3
- 2026LaplacianFormer:Rethinking Linear Attention with Laplacian Kernelcited by 3
- 2025Native Segmentation Vision Transformerscited by 2
- 2026SurGe: Improved Surface Geometry in Point Mapscited by 2
- 2024Optimizing Vision Transformers with Data-Free Knowledge Transfercited by 1
- 2025NABLA: Neighborhood Adaptive Block-Level Attentioncited by 1
2 more
- 2026SurGe: Improved Surface Geometry in Point Maps29 May 2026
- 2026LaplacianFormer:Rethinking Linear Attention with Laplacian Kernel22 Apr 2026
- 2026Le-DETR: Revisiting Real-Time Detection Transformer with Efficient Encoder Design24 Feb 2026
- 2025Enhancing 3D Semantic Scene Completion with a Refinement Module20 Dec 2025
- 2025NAF: Zero-Shot Feature Upsampling via Neighborhood Attention Filtering23 Nov 2025
- 2025Hilbert-Guided Sparse Local Attention8 Nov 2025
- 2025NABLA: Neighborhood Adaptive Block-Level Attention17 Jul 2025
- 2025Native Segmentation Vision Transformers22 May 2025
- 2025Attention on the Sphere16 May 2025
- 2025Generalized Neighborhood Attention: Multi-dimensional Sparse Attention at the Speed of Light23 Apr 2025
- 2025InvFusion: Bridging Supervised and Zero-shot Diffusion for Inverse Problems2 Apr 2025
- 2025WeatherMesh-3: Fast and accurate operational global weather forecasting28 Mar 2025
- 2024Flex Attention: A Programming Model for Generating Optimized Attention Kernelscited by 180
- 2025Generalized Neighborhood Attention: Multi-dimensional Sparse Attention at the Speed of Lightcited by 16
- 2025Attention on the Spherecited by 9
- 2025NAF: Zero-Shot Feature Upsampling via Neighborhood Attention Filteringcited by 6
- 2025WeatherMesh-3: Fast and accurate operational global weather forecastingcited by 4
- 2025Enhancing 3D Semantic Scene Completion with a Refinement Modulecited by 3
- 2026LaplacianFormer:Rethinking Linear Attention with Laplacian Kernelcited by 3
- 2025Native Segmentation Vision Transformerscited by 2
- 2026SurGe: Improved Surface Geometry in Point Mapscited by 2
- 2024Optimizing Vision Transformers with Data-Free Knowledge Transfercited by 1
- 2025NABLA: Neighborhood Adaptive Block-Level Attentioncited by 1
- 2025Hilbert-Guided Sparse Local Attentioncited by 1
12 most cited of 13 All 13 (JSON)
- 2026SurGe: Improved Surface Geometry in Point Maps29 May 2026
- 2026LaplacianFormer:Rethinking Linear Attention with Laplacian Kernel22 Apr 2026
- 2026Le-DETR: Revisiting Real-Time Detection Transformer with Efficient Encoder Design24 Feb 2026
- 2025Enhancing 3D Semantic Scene Completion with a Refinement Module20 Dec 2025
- 2025NAF: Zero-Shot Feature Upsampling via Neighborhood Attention Filtering23 Nov 2025
- 2025Hilbert-Guided Sparse Local Attention8 Nov 2025
- 2025NABLA: Neighborhood Adaptive Block-Level Attention17 Jul 2025
- 2025Native Segmentation Vision Transformers22 May 2025
- 2025Attention on the Sphere16 May 2025
- 2025Generalized Neighborhood Attention: Multi-dimensional Sparse Attention at the Speed of Light23 Apr 2025
- 2025WeatherMesh-3: Fast and accurate operational global weather forecasting28 Mar 2025
- 2024Flex Attention: A Programming Model for Generating Optimized Attention Kernels7 Dec 2024
12 newest of 13 All 13 (JSON)