Neighborhood Attention Transformer

Ali Hassani, Steven Walton, Jiachen Li, Shen Li, Humphrey Shi
4/14/2022
cs.CVcs.AIcs.LG

Official code: SHI-Labs/Neighborhood-Attention-Transformer (1,186 stars, MIT, PyTorch, last commit 2024-05-15). 1 more implementation below.

Abstract

We present Neighborhood Attention (NA), the first efficient and scalable sliding-window attention mechanism for vision. NA is a pixel-wise operation, localizing self attention (SA) to the nearest neighboring pixels, and therefore enjoys a linear time and space complexity compared to the quadratic complexity of SA. The sliding-window pattern allows NA's receptive field to grow without needing extra pixel shifts, and preserves translational equivariance, unlike Swin Transformer's Window Self Attention (WSA). We develop NATTEN (Neighborhood Attention Extension), a Python package with efficient C++ and CUDA kernels, which allows NA to run up to 40% faster than Swin's WSA while using up to 25% less memory. We further present Neighborhood Attention Transformer (NAT), a new hierarchical transformer design based on NA that boosts image classification and downstream vision performance. Experimental results on NAT are competitive; NAT-Tiny reaches 83.2% top-1 accuracy on ImageNet, 51.4% mAP on MS-COCO and 48.4% mIoU on ADE20K, which is 1.9% ImageNet accuracy, 1.0% COCO mAP, and 2.6% ADE20K mIoU improvement over a Swin model with similar size. To support more research based on sliding-window attention, we open source our project and release our checkpoints at: https://github.com/SHI-Labs/Neighborhood-Attention-Transformer .

View on arXivView PDF

Code Implementations(2)

PyTorchMIT

Neighborhood Attention Transformer, arxiv 2022 / CVPR 2023. Dilated Neighborhood Attention Transformer, arxiv 2022

1,18690Shell, PythonApr 14, 20222 years agoMIT
neighborhood-attentionpytorch
SHI-Labs/NATTENOfficial100%
PyTorchMIT

Fast Multi-dimensional Sparse Attention

78970C++, CudaOct 8, 20226 months agoMIT
cudaneighborhood-attentionpytorchsparse-attention

Similar Papers

Cite this paper

@article{hassani2022neighborhood,
  title  = {Neighborhood Attention Transformer},
  author = {Ali Hassani and Steven Walton and Jiachen Li and Shen Li and Humphrey Shi},
  year   = {2022},
  eprint = {2204.07143},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2204.07143}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2204.07143.svg)](https://codeofpaper.com/paper/2204.07143)

Discussion