# Native Sparse Attention: Trainable compression, selection and sliding windows

> NSA combines compressed global tokens, selected important blocks and local sliding windows. Its trainable, hardware-aligned design targets long-context speed without losing global information.

- URL: https://dmxsf.com/en/blog/native-sparse-attention/
- [DMXSF](https://dmxsf.com/en/about/)
- Published: 2025-02-26
- Updated: 2026-11-13
- Paper notes
- Paper: [Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention](https://arxiv.org/abs/2502.11089) (Jingyang Yuan, Huazuo Gao, Damai Dai, et al. · arXiv, 2025)

Native Sparse Attention incorporates sparsity during pretraining rather than pruning attention only after training. The DeepSeek team co-designs the method with hardware execution.

## How it works

Compression summarizes blocks, selection retains important blocks and a sliding window preserves local detail. Gated outputs combine the three paths, with block sizes and kernels designed for real GPU throughput.

## What the evidence shows

The paper reports competitive or improved long-context modeling, retrieval and reasoning with faster training and decoding. It is not purely local attention: compression and selection still carry global information.

## A reproducible check

This snippet checks a public formula or configuration; it does not reproduce full training.

```python
n, block, selected, window = 131072, 64, 16, 512
full = n*n
sparse = n*(n//block + selected*block + window)
print("full attention score units =", full)
print("NSA approximate score units =", sparse)
print("ratio =", sparse/full)
```

```text
full attention score units = 17179869184
NSA approximate score units = 469762048
ratio = 0.02734375
```

The arithmetic is reproducible, but model quality still depends on the full experiments in the paper.

## Limitations and common misreadings

Theoretical sparsity does not guarantee speed; selection and management have overhead. Gains depend on kernels, sequence length and batch size.

## The key takeaway

The key ideas are native trainability and three complementary paths: coarse global context, selected detail and local continuity.

## Further reading

- [Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention](https://arxiv.org/abs/2502.11089)
- [FlashAttention](https://dmxsf.com/en/blog/flashattention-fast-and-memory-efficient-exact-attention/)
- [Long-context information use](https://dmxsf.com/en/blog/lost-in-the-middle/)

## FAQ

### What are NSA’s three branches?

Global compression, important-block selection and a local sliding window, combined by gates.

### What does natively trainable mean?

The sparse pattern participates in optimization from pretraining rather than being added only afterward.

### Why hardware alignment?

Real speed requires blocks, memory access and kernels to turn reduced arithmetic into throughput.
