#161 · Primary category: Deep Learning Frameworks

native-sparse-attention-pytorch

artificial-intelligence attention deep-learning sparse-attention

Implementation of the sparse attention pattern proposed by the Deepseek team in their "Native Sparse Attention" paper

Project last updated:08/15/25

GitHub Stars

811

Forks

52

Contributors

5

License

MIT

Why we included this project

Transformer training costs grow quadratically with context length, and this library is a direct, pip-installable answer: it reproduces the sparse attention scheme DeepSeek laid out in their Native Sparse Attention paper. You instantiate a SparseAttention module, set a few hyperparameters for the sliding window and the compression and selection blocks, and swap it in where you would normally use full attention. Because the kernels are built on Triton and PyTorch's Flex Attention rather than hand-written CUDA, the code doubles as a readable reference for prototyping hardware-aligned sparse attention. The bundled Enwik8 language-modeling example trains the module end to end, so teams testing long-context efficiency can see it work before committing to a production kernel.

Articles for this project

No articles for this project yet.

To suggest a topic or contribute an article, contact us.

Related projects in this category