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.
On this page
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.
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)
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
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.