Faster Neighborhood Attention: Reducing the O(n^2) Cost of Self Attention at the Threadblock Level
Ali Hassani, Wen-Mei Hwu, Humphrey Shi
摘要
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...
问问这篇 Paper
智能体会读完全文。
Lune 把这篇 Paper 索引到了每一个公式,引用它的顶会 Paper 也一样。你提问,回答直接引用原文。
引用它的顶会 Paper7
- Attention on the SphereBoris Bonev, Max Rietmann, Andrea Paris, Alberto Carpentieri 等NeurIPS 2025 · 被引用 13 次
- InvFusion: Bridging Supervised and Zero-shot Diffusion for Inverse ProblemsNoam Elata, Hyungjin Chung, Jong Chul Ye, Tomer Michaeli 等NeurIPS 2025 · 被引用 10 次
- NAF: Zero-Shot Feature Upsampling via Neighborhood Attention FilteringLoïck Chambon, Paul Couairon, Éloi Zablocki, Alexandre Boulch 等CVPR 2026 · 被引用 6 次
- LaplacianFormer: Rethinking Linear Attention with Laplacian KernelZhe Feng, Sen Lian, Changwei Wang, Muyang Zhang 等ICLR 2026 · 被引用 3 次
- PRSformer: Disease Prediction from Million-Scale Individual GenotypesPayam Dibaeinia, Chris German, Suyash Shringarpure, Adam Auton 等NeurIPS 2025 · 被引用 3 次
它引用的顶会 Paper9
- An Image is Worth 16x16 Words: Transformers for Image Recognition at ScaleAlexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn 等ICLR 2021 · 被引用 21,477 次
- Scalable Diffusion Models with TransformersWilliam Peebles, Saining XieICCV 2023 · 被引用 5,568 次
- FlashAttention: Fast and Memory-Efficient Exact Attention with IO-AwarenessTri Dao, Daniel Y. Fu, Stefano Ermon, Atri Rudra 等NeurIPS 2022 · 被引用 5,493 次
- Big Bird: Transformers for Longer SequencesManzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie 等NeurIPS 2020 · 被引用 3,159 次
- ViViT: A Video Vision TransformerAnurag Arnab, Mostafa Dehghani, Georg Heigold, Chen Sun 等ICCV 2021 · 被引用 2,947 次
相关 Paper
- Hilbert-Guided Sparse Local AttentionYunge Li, Lanyu XuICLR 2026 · 被引用 1 次
- FlexLinearAttention: Compiling a Unified Abstraction into Scalable Kernels for Linear AttentionHaojie Duanmu, Size Zheng, Ningxin Zheng, Jianqiao Lu 等ICLR 2026
- FSA: An Alternative Efficient Implementation of Native Sparse Attention KernelRan Yan, Youhe Jiang, Zhuoming Chen, Haohui Mai 等ICLR 2026 · 被引用 10 次
- Fast Attention Over Long Sequences With Dynamic Sparse Flash AttentionMatteo Pagliardini, Daniele Paliotta, Martin Jaggi, François FleuretNeurIPS 2023 · 被引用 26 次
- FlashAttention-T: Towards Fully Tensorized Attention by Exploiting Tensor-Vector ParallelismJianxing Xu, Yuanbo Wen, Jun Bi, Ruibai Xu 等PPoPP 2026
