TL;DR
While sparse attention promises massive theoretical speedups, real-world GPU implementations rarely deliver because dense hardware primitives outpace complex sliding-window logic. Generalized Neighborhood Attention (GNA) bridges this gap by introducing a "stride" parameter that unifies sliding-window and blocked attention, paired with an analytical simulator (NATTENSim) and an optimized Blackwell kernel that achieves up to 100% of theoretical FLOP-wise speedup—accelerating large diffusion models like FLUX and HunyuanVideo by 28% to 46% end-to-end without fine-tuning.
What Problem Does This Paper Address?
Attention mechanisms in modern Transformers exhibit quadratic $\mathcal{O}(n^2)$ complexity. While natural language tokens sit on a 1-D line, visual and physical tokens (images and video) inhabit multi-dimensional 2-D or 3-D grids.
Applying local or sliding-window sparse attention to multi-dimensional data encounters the "curse of multi-dimensionality":
- Wasted Compute: Standard hardware tiles (e.g., in Tensor Cores) are square or 1-D. Mapping them across non-aligned multi-dimensional sliding windows results in partially masked tiles where hardware computes matrix multiplies only to discard elements before softmax.
- Infrastructure Complexity: Dense attention kernels (like FlashAttention) heavily exploit hardware features like NVIDIA's Tensor Memory Accelerator (TMA). Prior sparse kernels either relied on dynamic tiling and heavy software predication—which stalls modern GPU pipelines—or expensive memory copies.
Consequently, while models claim 90% theoretical sparsity, actual wall-clock speedups routinely fall flat.
Methods
The authors tackle these issues across algorithm design, analytical modeling, and low-level kernel implementation:
- Generalized Neighborhood Attention (GNA): Extends Neighborhood Attention (NA) by allowing even window sizes and introducing a stride parameter. Stride groups neighboring queries to share the same local context window. When $\text{stride} = 1$, it behaves as classic sliding-window NA; when $\text{stride} = \text{window size}$, it simplifies into non-overlapping blocked attention (e.g., Swin Transformer's WSA).
- NATTENSim: An analytical simulator that evaluates hardware tile visits ($T_Q, T_{KV}$) under static vs. dynamic tiling and dimension constraints. It computes realistic tile-level speedup upper bounds (as opposed to naive FLOP counts) and identifies perfectly block-sparse configurations where tile boundaries perfectly match window boundaries.
- Blackwell FMHA Implementation: Built on top of CUTLASS for the NVIDIA Blackwell (B200) architecture:
- Instead of embedding complex multi-dimensional index math inside the inner loops, it uses a lightweight token permutation (re-layout) step prior to attention, allowing the main kernel to rely on fast, static 1-D hardware memory accesses (TMA).
- Automatically predicates out softmax masking whenever tiles are fully unmasked or fully sparse.
stride = 1x1 stride = 2x2 stride = window size
(Sliding Window / NA) (Strided Sliding Window) (Blocked Attention)
[Q1] [Q2] [Q3] [Q4] [ Q1 Q2 ] [ Q3 Q4 ] [ Q1 Q2 Q3 Q4 ]
| | | | \ / \ / \ | /
[===== Win 1 =====] [==== Shared Win 1 ====] [==== Single Block ====]
[===== Win 2 =====]
Datasets
Rather than training from scratch, the paper benchmarks off-the-shelf pretrained models:
- Video Generation: Evaluated on Cosmos-7B (5-second 720p generation) and HunyuanVideo using the VBench comprehensive evaluation benchmark.
- Image Generation: Evaluated on FLUX.1-dev at 4K resolution (using URAE adapters) across text-to-image prompts from the HPDv2 test set. Outputs were scored on GenEval (compositional and object alignment), MAN-IQA, and QualiCLIP.
Key Insights and Ideas
- Stride Increases Compute Density: Moving the attention window for every token wastes memory bandwidth and creates ragged tile boundaries. Introducing stride enables multiple queries to reuse loaded Key/Value tiles, maximizing computational density while retaining localized spatial receptive fields.
- Zero-Masking "Sweet Spots": Under dynamic KV tiling, whenever the KV tile size ($T_{KV}$) divides the window size and the Q tile size ($T_Q$) divides the stride, the attention pattern becomes perfectly block-sparse. In this state, inner-loop fine-grained masking logic can be completely turned off.
- Separating Permutation from Computation: Fusing multi-dimensional coordinate mapping directly inside modern FMHA kernels breaks hardware compiler assumptions. Decoupling it into an upfront token permutation costs $<2\%$ of runtime while unlocking near peak hardware utilization (up to 1.3 PFLOPS in FP16 on B200).
Key Results
- Operator Efficiency: In perfectly block-sparse settings, the B200 kernel captures nearly 100% of theoretical FLOP-wise speedup, reaching up to 11.1× op-level speedup at 91% sparsity on HunyuanVideo.
- End-to-End Speedups (Zero Fine-Tuning):
- HunyuanVideo (91% sparsity): Reaches 2.23× end-to-end speedup across all 50 diffusion steps, matching the theoretical FLOP limit, while maintaining a 82.04% total score on VBench (baseline: 83.08%).
- Cosmos-7B (56% sparsity): Achieves 1.26× end-to-end speedup (FLOP limit: 1.28×) when preserving dense self-attention for the first 12 diffusion steps.
- FLUX.1-dev 4K (90% sparsity): Delivers 1.45× end-to-end speedup (FLOP limit: 1.46×) across 19 of 28 diffusion steps, with negligible differences in GenEval (0.5785 vs. 0.5750 baseline) and human preference scores.
Limitations and Future Work
- Naive Memory Permutation: Current token permutation relies on standard PyTorch copy operations that utilize only ~1/8th of the B200's HBM bandwidth. Hand-tuned copy kernels could further minimize overhead.
- Sparsity vs. Quality Thresholds: Without fine-tuning, models cannot tolerate extreme sparsity indiscriminately (e.g., Cosmos-7B degrades beyond ~56% sparsity; initial diffusion steps must remain dense to preserve global scene layout).
- Architecture Specificity: The current implementation is written in CUTLASS specifically targeting NVIDIA Blackwell GPUs; backporting optimizations to Hopper (FlashAttention-3) and Ampere remains future work.
Summary updated