atlas

Research map / Architectures and efficiency / Attention and transformers

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

NeurIPS 2024 · Architectures and efficiency › Attention and transformers · approach: Sparse and structured attention · 3 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Proposes GEMM-based and fused CUDA kernels (built on CUTLASS and xFormers FMHA) for 1-D/2-D/3-D neighborhood attention, yielding large speedups over the naive NATTEN kernels on A100.

Problem

Neighborhood and sliding-window attention reduce self-attention cost but lack efficient implementations in higher-rank (2-D/3-D) token spaces; existing naive CUDA kernels are memory-bound and slow.

Approach

Reformulates neighborhood attention's GEMV-like operators (PN, NN, IN) as batched GEMMs with space-aware tiling and gather/scatter fusion, and extends fused FMHA kernels to multi-dimensional token spaces with per-axis window, dilation, and causal masking.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use fused neighborhood attention instead of naive kernelsNeighborhood attention kernels · 1-D neighborhood attention, FP16 forwardaverage speed improvement over naive: 1759%Helped
Use fused neighborhood attention instead of naive kernelsNeighborhood attention kernels · 2-D neighborhood attention, FP16 forwardaverage speed improvement over naive: 958%Helped
Use fused neighborhood attention instead of naive kernelsNeighborhood attention kernels · 3-D neighborhood attention, FP16 forwardaverage speed improvement over naive: 1135%Helped
Use GEMM-based neighborhood attention instead of naive kernelsNeighborhood attention kernels · 1-D neighborhood attention, FP16 forwardaverage speed improvement over naive: 548%Helped
Use GEMM-based neighborhood attention instead of naive kernelsNeighborhood attention kernels · 2-D neighborhood attention, FP16 forwardaverage speed improvement over naive: 193%Helped
Use GEMM-based neighborhood attention instead of naive kernelsNeighborhood attention kernels · 1-D neighborhood attention, FP16 forward + backwardaverage speed improvement over naive: 502%Helped
Use GEMM-based neighborhood attention instead of naive kernelsNeighborhood attention kernels · 2-D neighborhood attention, FP16 forward + backwardaverage speed improvement over naive: 92%Helped
Use fused neighborhood attention instead of naive kernelsNeighborhood attention kernels · 1-D neighborhood attention, FP16 forward + backwardaverage speed improvement over naive: 844%Helped
Use fused neighborhood attention instead of naive kernelsNeighborhood attention kernels · 2-D neighborhood attention, FP16 forward + backwardaverage speed improvement over naive: 385%Helped
Use fused neighborhood attention instead of naive kernelsNeighborhood attention kernels · 3-D neighborhood attention, FP16 forward + backwardaverage speed improvement over naive: 447%Helped
Replace naive NAT-M kernels with GEMM-based kernelsNAT-M · ImageNet-1K, FP16throughput (imgs/sec): 2975 -> 2660Hurt
Replace naive NAT-M kernels with fused kernelsNAT-M · ImageNet-1K, FP16throughput (imgs/sec): 2975 -> 3742Helped

Surprising findings

Limitations

Experimental setup

Datasets: ImageNet-1K FFHQ

Benchmarks: ImageNet-1K throughput benchmarks FFHQ StyleNAT throughput benchmarks operator-level FP16/FP32 kernel benchmarks on A100

Metrics: runtime throughput (imgs/sec) training time estimate (hours) FID

Baselines: NATTEN naive CUDA kernels xFormers FMHA FlashAttention V2

Builds on: Neighborhood Attention FlashAttention xFormers FMHA CUTLASS NATTEN

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy