Papers › MoA: Mixture of Sparse Attention for Automatic Large Language Model Compression

MoA: Mixture of Sparse Attention for Automatic Large Language Model Compression

21 Jun 2024arXiv:2406.14909archive 2025-07-28

Tianyu Fu, Haofeng Huang, Xuefei Ning, Genghan Zhang, Boju Chen, Tianqi Wu, Hongyi Wang, Zixiao Huang, Shiyao Li, Shengen Yan, Guohao Dai, Huazhong Yang, Yu Wang

Sparse attention can effectively mitigate the significant memory and throughput demands of Large Language Models (LLMs) in long contexts. Existing methods typically employ a uniform sparse attention mask, applying the same sparse pattern across different attention heads and input lengths. However, this uniform approach fails to capture the diverse attention patterns inherent in LLMs, ignoring their distinct accuracy-latency trade-offs. To address this challenge, we propose the Mixture of Attention (MoA), which automatically tailors distinct sparse attention configurations to different heads and layers. MoA constructs and navigates a search space of various attention patterns and their scaling rules relative to input sequence lengths. It profiles the model, evaluates potential configurations, and pinpoints the optimal sparse attention compression plan. MoA adapts to varying input sizes, revealing that some attention heads expand their focus to accommodate longer sequences, while other heads consistently concentrate on fixed-length local contexts. Experiments show that MoA increases the effective context length by 3.9× with the same average attention span, boosting retrieval accuracy by 1.5-7.1× over the uniform-attention baseline across Vicuna-{7B,13B}, and Llama3-{8B,70B} models. Moreover, MoA narrows the capability gaps between sparse and dense models, reducing the maximum relative performance drop from 9%-36% to within 5% across two long-context understanding benchmarks. MoA achieves a 1.2-1.4× GPU memory reduction, boosting decode throughput by 6.6-8.2× and 1.7-1.9× compared to FlashAttention2 and vLLM, with minimal impact on performance. Our code is available at https://github.com/thu-nics/MoA.

PaperPDFCodeCode Syntology ran

In Syntology View this paper on Syntology, its page in Syntology's graph. That page adds which of its functions are also present in other papers' code Syntology holds, with dates, and its dated run record as JSON and a README badge. It also lists the repositories linked to the paper, the abstract and the calls for agents.

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

For agents, on Syntology's MCP service (how to connect):

Code

Syntology 22 code samples harvested from 1 repository linked to this paper: 19 ran (of which 0 constructed an object rather than computing a result; 10 with no instrument failure: 0 honoured, 0 violated, 10 with no contract checked; 9 where Syntology's instrument failed) · 3 unverified. Where Syntology's instrument failed: 9 where our contract draft was wrong; failures of Syntology's instrument, not of the code.

By repository: official repository: 22 samples from 1 repository, 19 ran (10 with no instrument failure; 9 where Syntology's instrument failed). The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

Levels written on 2026-09-24 (UTC): the dates Syntology's graph wrote each sample's verification level, not when the code executed.

thu-nics/moa officialmentioned in papermentioned on GitHubpytorchMITSyntology: 22 samples, 19 ran (9 instrument-failed) · 3 unverified 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

22 samples harvested: 19 ran (of which 0 constructed an object rather than computing a result; 10 with no instrument failure: 0 honoured, 0 violated, 10 with no contract checked; 9 where Syntology's instrument failed) · 3 unverified. “Where Syntology's instrument failed” counts failures of Syntology's instrument, not of the code. Syntology's record for this page last changed ; when this build read Syntology's graph is in the build record. That date is not when the samples ran.

9ran · our draft was wrong
10ran
3unverified

Licence: 0 of the 22 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 thu-nics/moa. “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. A line beginning “fixture:” under a sample that ran gives the arguments Syntology's fixture called the sample with, each as name:type/rank/element kind (? where none was recorded), and the type of what the fixture's run returned, exactly as the harness recorded them; the arguments and the returned type were recorded by two separate runs of the same fixture. No output value is shown, and a returned type says nothing about whether the output was right. “Level recorded” gives the UTC date when Syntology's graph wrote the sample's verification level, not when the code executed; where the level was written before Syntology's graph kept that date, the row says “level recorded, date not recorded”. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself. “Our draft was wrong” and “the contract check could not run” are failures of Syntology's instrument, not of the code: the sample ran on Syntology's synthesized input, and then the drafted contract did not describe it, or the check itself raised an error (RAISES), lacked a dependency (DEP_MISSING) or ran out of time (TIMEOUT); hover the label for which. A metamorphic tier, where shown, is evidence of the output's shape, not that the sample implements the method.

Each sample ends with its code_sha256. A sample's code_sha256 is Syntology's identity for that exact code. It is printed in full (16 hexadecimal characters for every sample in this build), and get_code(code_sha256="…") takes it exactly as printed. An agent calls it on Syntology's MCP service (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 are grouped by repository: a repository marked official first, then by how directly the repository is tied to the paper, then in the archive's order; never by how many ran. 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 six 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; the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar); this paper's copy was not located, so its licence is not recorded; or this paper's copy is cleared, but the stored copy of the same code that Syntology serves is not. 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.

thu-nics/moa official repository 22 samples, 19 ran (9 instrument-failed) · 3 unverified
Trainer_attention_grad_compute_loss MoA/attention/sparse_mask.py ran MIT (permissive) · b8258f95889e4952 · report fixture: signature self:MockTrainer/0/?, model:callable/0/?, inputs:dict/0/?, return_outputs:bool/0/bool · returned Tensor · level recorded 2026-09-24
count_distinct_elements_per_row MoA/attention/density_calculation.py ran · our draft was wrong MIT (permissive) · 29414013ce12967c · report fixture: signature lut:Tensor/2/int · returned Tensor · level recorded 2026-09-24
find_subtensor_position MoA/dataset/utils.py ran · our draft was wrong MIT (permissive) · 061f1b20e4c107be · report fixture: signature sub_tensor:Tensor/1/int, main_tensor:Tensor/2/int · returned list · level recorded 2026-09-24
gen_band_pattern MoA/attention/pattern.py ran MIT (permissive) · 149e4b82b7620c4b · report fixture: signature num_query:int/0/int, num_key:int/0/int, band_width:int/0/int, dtype:dtype/0/?, num_layer:int/0/int, num_head:int/0/int · returned Tensor · level recorded 2026-09-24
gen_block_sparse_layout_mask MoA/attention/sparse_mask.py ran MIT (permissive) · 6d1389e6b2d85469 · report fixture: signature matrix:Tensor/3/float, num_block_x:int/0/int, num_block_y:int/0/int, block_keep_num:Tensor/1/int, row_balance:bool/0/bool, block_aggregation_func:callable/0/?, is_causal:bool/0/bool · returned tuple · level recorded 2026-09-24
gen_global_pattern MoA/attention/pattern.py ran MIT (permissive) · 7e1d14c04aa0dc2d · report fixture: signature num_query:int/0/int, num_key:int/0/int, key_pos:list/1/int, dtype:dtype/0/?, num_layer:int/0/int, num_head:int/0/int · returned Tensor · level recorded 2026-09-24
head_index_to_split_index MoA/kernels/flash_decoding_moa.py ran · our draft was wrong MIT (permissive) · 2d84082c203b2b52 · report fixture: signature head_index:Tensor/1/int, split_size:int/0/int · returned Tensor · level recorded 2026-09-24
hotpotQA_to_multi_round_qa MoA/dataset/convert.py ran · our draft was wrong MIT (permissive) · 21ce5f5f68d41dad · report fixture: signature entry:dict/0/? · returned dict · level recorded 2026-09-24
layout_to_lut MoA/attention/convert.py ran · our draft was wrong MIT (permissive) · 2866d7c2b62c260d · report fixture: signature layout:Tensor/4/bool · returned tuple · level recorded 2026-09-24
lut_to_permutation MoA/attention/permutation_utils.py ran MIT (permissive) · e6a764e7c48e4500 · report fixture: signature lut_list:list/1/Tensor, num_heads:int/0/int, num_key_value_groups:int/0/int · returned tuple · level recorded 2026-09-24
mask_to_layout MoA/attention/convert.py ran · our draft was wrong MIT (permissive) · 8633f899e4d7407c · report fixture: signature mask:Tensor/3/float, block_size:int/0/int · returned Tensor · level recorded 2026-09-24
matrix_reserve_score MoA/attention/sparse_mask.py ran MIT (permissive) · 0bfc9650b5be48e8 · report fixture: signature matrix:Tensor/3/float, mask:Tensor/3/float, is_causal:bool/0/bool, norm_score:bool/0/bool · returned Tensor · level recorded 2026-09-24
moa_config_to_cache_config MoA/attention/cache_utils.py ran MIT (permissive) · 1ada47e15f33f461 · report fixture: signature moa_config:dict/0/?, seq_len:int/0/int, max_new_token:int/0/int, sink_size:int/0/int, minimum_cache_size:int/0/int, split_size:int/0/int, verbose:bool/0/bool · returned dict · level recorded 2026-09-24
moa_config_to_permutation MoA/attention/permutation_utils.py ran · our draft was wrong MIT (permissive) · 2cd7b8febe087a7d · report fixture: signature moa_config:dict/0/? · returned tuple · level recorded 2026-09-24
multiNews_to_multi_round_qa MoA/dataset/convert.py ran · our draft was wrong MIT (permissive) · 3dca86fbcf33d8a4 · report fixture: signature entry:dict/0/? · returned dict · level recorded 2026-09-24
permute_lut MoA/attention/permutation_utils.py ran MIT (permissive) · 77491a1736272578 · report fixture: signature lut:Tensor/2/float, permutation:Tensor/1/int, num_heads:int/0/int · returned Tensor · level recorded 2026-09-24
qasper_to_multi_round_qa MoA/dataset/convert.py ran · our draft was wrong MIT (permissive) · 89ec645a857ef9af · report fixture: signature entry:dict/0/? · returned dict · level recorded 2026-09-24
streamingllm_attention_density MoA/attention/density_calculation.py ran fingerprinted MIT (permissive) · cd7b0c5e2a16d0cd · report fixture: signature global_size:int/0/int, band_size:int/0/int, kv_seq_len:int/0/int · returned float · level recorded 2026-09-24
streamingllm_kv_cache_density MoA/attention/density_calculation.py ran fingerprinted MIT (permissive) · 758a42acae59b91f · report fixture: signature global_size:int/0/int, band_size:int/0/int, kv_seq_len:int/0/int · returned float · level recorded 2026-09-24
block_sparse_to_dense MoA/attention/convert.py unverified MIT (permissive) · 98558d05575a5d9f · report
gen_causal_pattern MoA/attention/pattern.py unverified MIT (permissive) · ef170fe22d7a924e · report
update_model_function MoA/models/interface.py unverified MIT (permissive) · e55fe24f97290938 · report

Tasks

Language ModelingLanguage ModellingLarge Language ModelLong-Context UnderstandingModel Compression

1 archive task tag without a task page not shown.

Datasets

Introduced by this paper, per the archive.

MoA

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AttentionFocusSoftmax

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