TL;DR
Generalized Neighborhood Attention (GNA) introduces a customizable "stride" parameter to sliding-window attention, grouping queries together to achieve hardware-friendly block sparsity. By pairing this framework with an analytical simulator (NATTENSim) and a highly optimized kernel for NVIDIA Blackwell GPUs, the authors unlock up to 46% end-to-end speedups in state-of-the-art generative models like FLUX and HunyuanVideo without any fine-tuning.
What Problem Does This Paper Address?
Standard self-attention scales quadratically ($O(n^2)$) with sequence length, creating a massive computational bottleneck for foundation models handling high-resolution images and videos. While sparse attention mechanisms (like sliding windows) theoretically reduce the required FLOPs, they rarely translate into actual wall-clock speedups on modern GPUs.
This disconnect stems from the "curse of multi-dimensionality." When multi-dimensional data (like 2D images or 3D video volumes) is processed using standard 1D hardware tiling, a huge portion of the mathematically skipped operations still get computed because they fall inside dense hardware execution tiles. They are only masked out after the expensive matrix multiplication is already done, wasting massive amounts of hardware compute.
Methods
The authors tackle this hardware-software mismatch through a three-part contribution:
- Generalized Neighborhood Attention (GNA): GNA extends standard Neighborhood Attention by adding a stride parameter. Instead of shifting the sliding window for every single token, a stride $>1$ forces a group of neighboring queries to share the exact same context window. This aligns the boundaries of their attention windows, transforming irregular sparse masks into clean, dense blocks that hardware can accelerate.
- NATTENSim: An analytical simulator that models tile-level behavior rather than raw FLOP counts. It abstracts away low-level implementation details to help researchers find optimal tile sizes, strides, and layouts that achieve perfect block-sparsity for specific model architectures.
- Blackwell Kernel Implementation: A high-performance GNA kernel built on top of CUTLASS’s Fused Multi-Headed Attention (FMHA) for the NVIDIA Blackwell architecture. Crucially, it moves multi-dimensional token re-layout (token permutation) outside the core attention kernel. This keeps the inner attention loops clean and allows the implementation to fully exploit hardware features like the Tensor Memory Accelerator (TMA).
Datasets
The authors evaluate GNA by plugging it directly into off-the-shelf, state-of-the-art generative foundation models:
- Cosmos-7B (World Foundation Model)
- HunyuanVideo (Video Generation), evaluated quantitatively using the VBench benchmark suite.
- FLUX-1.dev (Image Generation), evaluated at 4K resolution using MAN-IQA (image quality), QualiCLIP (aesthetic alignment), and GenEval (compositional text-to-image alignment).
Key Insights and Ideas
- Striding Bridges the Gap: Traditional sliding windows are too fine-grained for modern Tensor Cores, while blocked attention completely destroys cross-block interactions. GNA’s stride parameter acts as a tunable knob between the two, restoring hardware efficiency while maintaining local context.
- The Tiling-Sparsity Mismatch: A method can claim 90% algorithmic sparsity, but if those sparse elements are scattered randomly across dense hardware tiles, the GPU still does 100% of the work. True speedup requires aligning algorithmic boundaries with hardware tile boundaries.
- Out-of-Kernel Permutation: Instead of forcing complex multi-dimensional indexing inside the highly optimized attention kernel, permuting the tokens in memory beforehand keeps the inner loops clean and fast enough to hit "Speed-of-Light" hardware utilization.
Key Results
- Hardware Efficiency: The Blackwell GNA kernel achieves an effective utilization of 1.3 petaFLOPs/second in FP16.
- Operation-Level Speedups: In perfectly block-sparse configurations, GNA matches or nearly reaches the theoretical maximum speedup dictated by its sparsity ratio (e.g., achieving a 10.2x speedup at 90% sparsity for FLUX 4K, as seen in the figure above).
- End-to-End Performance: When integrated into off-the-shelf models on an NVIDIA B200 GPU (retaining full self-attention only for the initial diffusion steps to preserve global structure), GNA delivers substantial end-to-end speedups:
- Cosmos-7B: Up to 1.46x speedup (at 56% sparsity).
- HunyuanVideo: Up to 1.72x speedup (or 2.23x when applied across all diffusion steps).
- FLUX-1.dev (4K): Up to 1.45x speedup.
- Quality Preservation: Quantitative benchmarks (VBench and GenEval) confirm that GNA preserves generation quality on par with full self-attention baselines without requiring any model retraining or fine-tuning.
Limitations and Future Work
- Token Permutation Overhead: The token re-layout step is currently implemented naively in PyTorch, utilizing only about 1/8th of the B200's peak memory bandwidth. Optimizing this with specialized copy kernels is a key area for future work.
- Masking Overhead: For configurations that are not perfectly block-sparse, fine-grained masking in the softmax stage still introduces non-negligible computational overhead.
- Cross-Architecture Porting: The current high-performance implementation is specific to NVIDIA's Blackwell architecture; porting these design principles back to Hopper (FlashAttention-3) and Ampere (FlashAttention-2) remains an open direction.
Summary updated