Papers › Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention

Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention

16 Feb 2025arXiv:2502.11089archive 2025-07-28

Jingyang Yuan, Huazuo Gao, Damai Dai, Junyu Luo, Liang Zhao, Zhengyan Zhang, Zhenda Xie, Y. X. Wei, Lean Wang, Zhiping Xiao, Yuqing Wang, Chong Ruan, Ming Zhang, Wenfeng Liang, Wangding Zeng

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.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2502.11089")

Code

Syntology Ran 4 of 19 code samples harvested from 2 repositories linked to this paper; 15 have no recorded run. Of those that ran: 1 ran · our draft was wrong; 3 ran with no contract checked.

By repository: community (archive-listed): 19 samples from 2 repositories, 4 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

britacatalin/bsa mentioned on GitHubpytorch report
microsoft/seerattention mentioned on GitHubpytorchMIT report
sandai-org/magiattention mentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

19 samples harvested; 4 ran; 0 honoured the contract we drafted; 15 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · our draft was wrong
3ran
15unverified

Licence: 0 of the 19 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

NativeSparseAttention britacatalin/bsa/nsa/native_sparse_attention.py community (archive-listed) ran MIT (permissive) · b93448058eb3a756 · report
StaticGatedAttention britacatalin/bsa/nsa/native_sparse_attention.py community (archive-listed) ran MIT (permissive) · f36889830d661d6f · report
TokenGatedAttention britacatalin/bsa/nsa/native_sparse_attention.py community (archive-listed) ran MIT (permissive) · d9f141ee5201879b · report
rotate_half microsoft/seerattention/seer_attn/modules/common.py community (archive-listed) ran · our draft was wrong fingerprinted MIT (permissive) · e03d53ba9d4f9ae5 · report
apply_chat_template microsoft/seerattention/distillation_decode.py community (archive-listed) unverified MIT (permissive) · 202aa55ac60ff1f6 · report
apply_rotary_pos_emb microsoft/seerattention/seer_attn/modules/common.py community (archive-listed) unverified MIT (permissive) · 8c7b215a2004bfc6 · report
apply_rotary_pos_emb_single microsoft/seerattention/seer_attn/modules/common.py community (archive-listed) unverified MIT (permissive) · 89cf2076c1b8ce86 · report
average_groups microsoft/seerattention/eval/longbench/average_sparsity.py community (archive-listed) unverified MIT (permissive) · a8c8717e85efa3ea · report
build_optimized_chunks microsoft/seerattention/distillation_decode.py community (archive-listed) unverified MIT (permissive) · 4334f4eeb6104bee · report
calculate_averages_by_range microsoft/seerattention/eval/longbench/average_score.py community (archive-listed) unverified MIT (permissive) · e9c41059655ed7e3 · report
generate_base_sparsity_mask microsoft/seerattention/eval/efficiency/benchmark_sparse_attn.py community (archive-listed) unverified MIT (permissive) · 8498177d23b25d59 · report
get_tensors microsoft/seerattention/eval/efficiency/benchmark_sparse_attn.py community (archive-listed) unverified MIT (permissive) · 09bb2cb546d9e69e · report
layer_norm_ref microsoft/seerattention/seer_attn/modules/layernorm.py community (archive-listed) unverified MIT (permissive) · 2ce8fcf5bedd19ec · report
load_json microsoft/seerattention/eval/longbench/average_score.py community (archive-listed) unverified MIT (permissive) · cc892598a14c82a5 · report
ref_program_fa microsoft/seerattention/eval/efficiency/decode_kernel_eval.py community (archive-listed) unverified MIT (permissive) · ea5becf731d3b58d · report
rms_norm_ref microsoft/seerattention/seer_attn/modules/layernorm.py community (archive-listed) unverified MIT (permissive) · ab802ae3195c6316 · report
run_benchmark microsoft/seerattention/eval/efficiency/benchmark_sparse_attn.py community (archive-listed) unverified MIT (permissive) · 046184b390b18314 · report
tokenize_fn microsoft/seerattention/distillation_decode.py community (archive-listed) unverified MIT (permissive) · 3ef366d8b91a362a · report
tokenize_fn microsoft/seerattention/distillation_prefill.py community (archive-listed) unverified MIT (permissive) · f9963e3bc9860eda · report

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AttentionSoftmax

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections