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 \url{https://github.com/thu-nics/MoA}.

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="2406.14909")

Code

Syntology Ran 19 of 22 code samples harvested from 1 repository linked to this paper; 3 have no recorded run. Of those that ran: 19 ran with no contract checked.

By repository: official repository: 22 samples from 1 repository, 19 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

thu-nics/moa officialmentioned in papermentioned on GitHubpytorchMIT 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; 0 honoured the contract we drafted; 3 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.

19ran
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. “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.

Trainer_attention_grad_compute_loss thu-nics/moa/MoA/attention/sparse_mask.py official repository ran MIT (permissive) · b8258f95889e4952 · report
count_distinct_elements_per_row thu-nics/moa/MoA/attention/density_calculation.py official repository ran MIT (permissive) · 29414013ce12967c · report
find_subtensor_position thu-nics/moa/MoA/dataset/utils.py official repository ran MIT (permissive) · 061f1b20e4c107be · report
gen_band_pattern thu-nics/moa/MoA/attention/pattern.py official repository ran MIT (permissive) · 149e4b82b7620c4b · report
gen_block_sparse_layout_mask thu-nics/moa/MoA/attention/sparse_mask.py official repository ran MIT (permissive) · 6d1389e6b2d85469 · report
gen_global_pattern thu-nics/moa/MoA/attention/pattern.py official repository ran MIT (permissive) · 7e1d14c04aa0dc2d · report
head_index_to_split_index thu-nics/moa/MoA/kernels/flash_decoding_moa.py official repository ran MIT (permissive) · 2d84082c203b2b52 · report
hotpotQA_to_multi_round_qa thu-nics/moa/MoA/dataset/convert.py official repository ran MIT (permissive) · 21ce5f5f68d41dad · report
layout_to_lut thu-nics/moa/MoA/attention/convert.py official repository ran MIT (permissive) · 2866d7c2b62c260d · report
lut_to_permutation thu-nics/moa/MoA/attention/permutation_utils.py official repository ran MIT (permissive) · e6a764e7c48e4500 · report
mask_to_layout thu-nics/moa/MoA/attention/convert.py official repository ran MIT (permissive) · 8633f899e4d7407c · report
matrix_reserve_score thu-nics/moa/MoA/attention/sparse_mask.py official repository ran MIT (permissive) · 0bfc9650b5be48e8 · report
moa_config_to_cache_config thu-nics/moa/MoA/attention/cache_utils.py official repository ran MIT (permissive) · 1ada47e15f33f461 · report
moa_config_to_permutation thu-nics/moa/MoA/attention/permutation_utils.py official repository ran MIT (permissive) · 2cd7b8febe087a7d · report
multiNews_to_multi_round_qa thu-nics/moa/MoA/dataset/convert.py official repository ran MIT (permissive) · 3dca86fbcf33d8a4 · report
permute_lut thu-nics/moa/MoA/attention/permutation_utils.py official repository ran MIT (permissive) · 77491a1736272578 · report
qasper_to_multi_round_qa thu-nics/moa/MoA/dataset/convert.py official repository ran MIT (permissive) · 89ec645a857ef9af · report
streamingllm_attention_density thu-nics/moa/MoA/attention/density_calculation.py official repository ran fingerprinted MIT (permissive) · cd7b0c5e2a16d0cd · report
streamingllm_kv_cache_density thu-nics/moa/MoA/attention/density_calculation.py official repository ran fingerprinted MIT (permissive) · 758a42acae59b91f · report
block_sparse_to_dense thu-nics/moa/MoA/attention/convert.py official repository unverified MIT (permissive) · 98558d05575a5d9f · report
gen_causal_pattern thu-nics/moa/MoA/attention/pattern.py official repository unverified MIT (permissive) · ef170fe22d7a924e · report
update_model_function thu-nics/moa/MoA/models/interface.py official repository 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