[Paper Review] Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention
NSA introduces a tri-branch native sparse attention with compression, selection, and sliding-window strategies, plus hardware-aligned kernels, enabling end-to-end training and fast long-context modeling, outperforming baselines in long-context tasks.
Long-context modeling is crucial for next-generation language models, yet the high computational cost of standard attention mechanisms poses significant computational challenges. Sparse attention offers a promising direction for improving efficiency while maintaining model capabilities. We present NSA, a Natively trainable Sparse Attention mechanism that integrates algorithmic innovations with hardware-aligned optimizations to achieve efficient long-context modeling. NSA employs a dynamic hierarchical sparse strategy, combining coarse-grained token compression with fine-grained token selection to preserve both global context awareness and local precision. Our approach advances sparse attention design with two key innovations: (1) We achieve substantial speedups through arithmetic intensity-balanced algorithm design, with implementation optimizations for modern hardware. (2) We enable end-to-end training, reducing pretraining computation without sacrificing model performance. As shown in Figure 1, experiments show the model pretrained with NSA maintains or exceeds Full Attention models across general benchmarks, long-context tasks, and instruction-based reasoning. Meanwhile, NSA achieves substantial speedups over Full Attention on 64k-length sequences across decoding, forward propagation, and backward propagation, validating its efficiency throughout the model lifecycle.
Motivation & Objective
- Motivate long-context modeling and reduce attention bottlenecks in transformers.
- Develop a native sparse attention mechanism that is trainable end-to-end.
- Balance global context and local precision via hierarchical token remapping (compression, selection, sliding window).
- Achieve hardware-efficient implementations that maximize arithmetic intensity on modern accelerators.
- Demonstrate comparable or superior performance to full attention across general and long-context benchmarks while delivering substantial speedups.
Proposed method
- Introduce three parallel attention branches: compression, selection, and sliding window, combined via gated aggregation.
- Compute compressed keys/values with blockwise token compression using learned MLPs.
- Select top blocks based on block-level importance scores derived from compressed attention, with scores aggregated for shared KV caches.
- Maintain a sliding-window branch for local context to preserve local information.
- Provide kernel design that loads groupwise queries and shared KV blocks to maximize Tensor Core utilization and memory efficiency.
- Train NSA end-to-end on long sequences using a 27B-parameter backbone with GQA and MoE, enabling hardware-aligned sparse computations.
Experimental results
Research questions
- RQ1Can native sparse attention with hierarchical remapping maintain or improve performance relative to full attention on long-context tasks?
- RQ2Do hardware-aligned implementations and trainable sparsity enable end-to-end training with significant speedups across decoding, forward, and backward passes?
- RQ3How do compression, selection, and sliding-window branches contribute to global context awareness versus local precision?
- RQ4Is end-to-end training of sparse attention viable without non-trainable components that hinder gradient flow?
- RQ5Does NSA scale to very long contexts (64k+) while preserving accuracy on general and reasoning benchmarks?
Key findings
- NSA achieves comparable or superior performance to full attention on general benchmarks and long-context tasks.
- On 64k-length sequences, NSA attains substantial speedups over full attention in decoding, forward, and backward passes, with speedups increasing for longer sequences.
- Pretraining with NSA yields gains in reasoning benchmarks (e.g., DROP and GSM8K) and maintains strong performance across MMLU, CMMLU, and coding tasks.
- Long-context evaluation shows NSA attaining perfect retrieval accuracy across 64k context in needle-in-a-haystack tests.
- In LongBench, NSA achieves the highest average score among evaluated methods, outperforming Full Attention and Exact-Top.
- In chain-of-thought style evaluation, NSA-R surpasses Full Attention-R at 8k and 16k contexts for AIME-style mathematical reasoning.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.