Introduction
As Large Language Models (LLMs) evolve towards processing massive context windows, the standard "Full Attention" mechanism has become a significant computational bottleneck. Its quadratic scaling with sequence length and heavy memory bandwidth requirements during decoding—necessitating the loading of the entire Key-Value (KV) cache for every new token—limit the practical deployment of long-context models. While sparse attention methods have been proposed, they often suffer from hardware inefficiency due to fragmented memory access or performance degradation because they are applied post-training.
DeepSeek-AI addresses these challenges with Native Sparse Attention (NSA), a hierarchical attention mechanism designed to be hardware-optimized and natively trainable. NSA achieves significant speedups while maintaining or even improving upon the accuracy of full-attention models.
Methodology: The NSA Architecture
NSA employs a dynamic hierarchical strategy that processes information through three parallel branches, ensuring a balance between global context and local precision.
- Token Compression: Blocks of keys and values are aggregated into compressed representations using a learnable MLP. This provides the model with a coarse-grained global view at a minimal computational cost.
- Selected Attention: Utilizing attention scores from the compressed branch, the model identifies and fetches the most critical fine-grained blocks in their original detail.
- Sliding Window: A standard local window provides high-precision access to the most recent tokens.
To ensure hardware efficiency, NSA utilizes specialized Triton kernels and Group-Centric Data Loading. By sharing sparse KV blocks across heads in a group within fast SRAM, NSA maximizes arithmetic intensity and keeps GPU Tensor Cores utilized, overcoming the fragmentation issues of previous sparse methods.
Experimental Setup
The researchers evaluated NSA using a 27B-parameter model (3B active parameters via Mixture-of-Experts) trained on 260B tokens. The evaluation spanned:
- General Benchmarks: MMLU, CMMLU, BBH, GSM8K, MATH, and HumanEval.
- Long-Context: LongBench and the "Needle-in-a-Haystack" test.
- Reasoning: NSA-R, a variant fine-tuned on 10B tokens of mathematical reasoning traces distilled from DeepSeek-R1.
Key Results and Discussion
NSA demonstrates that sparsity can act as a regularizer. By forcing the model to select relevant information during pre-training, it filters noise from irrelevant tokens, often leading to better performance than dense models.
Performance and Accuracy
On the LongBench suite, NSA achieved an average score of 0.469, notably higher than the Full Attention baseline of 0.437. It also maintained 100% accuracy on the "Needle-in-a-Haystack" test up to 64k tokens. In mathematical reasoning (AIME 24), the NSA-variant significantly outperformed the baseline, proving its capability in complex logic tasks.
Hardware Efficiency
The hardware-aligned design yields dramatic efficiency gains at 64k sequence lengths:
- 11.6x speedup in decoding.
- 9.0x speedup in forward propagation.
- 6.0x speedup in backward propagation.
Conclusion
Native Sparse Attention represents a shift toward "native" sparsity, where models are built to be efficient from the ground up. While current evaluations focus on 64k contexts, the architecture's design suggests scalability to even longer sequences. Future work will explore scaling to millions of tokens and optimizing gating mechanisms across different model layers to further refine the balance between local and global attention.
Summary updated