Papers › Mixture of Attention Heads: Selecting Attention Heads Per Token

Mixture of Attention Heads: Selecting Attention Heads Per Token

11 Oct 2022arXiv:2210.05144archive 2025-07-28

Xiaofeng Zhang, Yikang Shen, Zeyu Huang, Jie zhou, Wenge Rong, Zhang Xiong

Mixture-of-Experts (MoE) networks have been proposed as an efficient way to scale up model capacity and implement conditional computing. However, the study of MoE components mostly focused on the feedforward layer in Transformer architecture. This paper proposes the Mixture of Attention Heads (MoA), a new architecture that combines multi-head attention with the MoE mechanism. MoA includes a set of attention heads that each has its own set of parameters. Given an input, a router dynamically selects a subset of k attention heads per token. This conditional computation schema allows MoA to achieve stronger performance than the standard multi-head attention layer. Furthermore, the sparsely gated MoA can easily scale up the number of attention heads and the number of parameters while preserving computational efficiency. In addition to the performance improvements, MoA also automatically differentiates heads' utilities, providing a new perspective to discuss the model's interpretability. We conducted experiments on several important tasks, including Machine Translation and Masked Language Modeling. Experiments have shown promising results on several tasks against strong baselines that involve large and very deep models.

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

Code

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

By repository: official repository: 5 samples from 1 repository, 5 ran; community (archive-listed): 1 sample from 1 repository, 1 ran; found in paper text by Syntology: 11 samples from 1 repository, 0 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

yikangshen/moa officialmentioned in paperpytorchBSD-3-Clause report
yikangshen/megablocks 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

17 samples harvested; 6 ran; 1 honoured the contract we drafted; 11 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 · honoured contract
3ran · our draft was wrong
2ran
11unverified

Licence: 0 of the 17 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 3 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.

Embedding yikangshen/moa/transformer_base.py official repository ran · our draft was wrong BSD-3-Clause (permissive) · 96cbb5e9ca5b6be0 · report
Linear yikangshen/moa/transformer_decoder.py official repository ran · our draft was wrong BSD-3-Clause (permissive) · 8cd8cb0d1e9e63e4 · report
label_smoothed_nll_loss yikangshen/moa/moa_loss.py official repository ran · our draft was wrong BSD-3-Clause (permissive) · 96b6713ff1c322ca · report
module_name_fordropout yikangshen/moa/transformer_encoder.py official repository ran fingerprinted BSD-3-Clause (permissive) · c3fcda996a38b833 · report
module_name_fordropout yikangshen/moa/transformer_decoder.py official repository ran fingerprinted BSD-3-Clause (permissive) · e63f8c52be2a8547 · report
promote_scalar yikangshen/megablocks/megablocks/layers/moa.py community (archive-listed) ran · honoured contract fingerprinted Apache-2.0 (permissive) · 7630a3eb1f9be798 · report
accumulate_flops sovrasov/flops-counter.pytorch/ptflops/pytorch_engine.py found in paper text by Syntology unverified MIT (permissive) · 17cd6272d876a166 · report
addmm_flop sovrasov/flops-counter.pytorch/ptflops/aten_ops.py found in paper text by Syntology unverified MIT (permissive) · 81acb062e01cd209 · report
bert_input_constructor sovrasov/flops-counter.pytorch/samples/bert.py found in paper text by Syntology unverified MIT (permissive) · dcd80b80811a2b5b · report
flops_to_string sovrasov/flops-counter.pytorch/ptflops/utils.py found in paper text by Syntology unverified MIT (permissive) · 10741db0a4b99b7e · report
get_flops_pytorch sovrasov/flops-counter.pytorch/ptflops/pytorch_engine.py found in paper text by Syntology unverified MIT (permissive) · 46f8ed51e754d72a · report
get_model_complexity_info sovrasov/flops-counter.pytorch/ptflops/flops_counter.py found in paper text by Syntology unverified MIT (permissive) · 46e7df6447a3d499 · report
matmul_flop sovrasov/flops-counter.pytorch/ptflops/aten_ops.py found in paper text by Syntology unverified MIT (permissive) · 55836471a41bf03e · report
params_to_string sovrasov/flops-counter.pytorch/ptflops/utils.py found in paper text by Syntology unverified MIT (permissive) · 492162380895ff7c · report
print_model_with_flops sovrasov/flops-counter.pytorch/ptflops/pytorch_engine.py found in paper text by Syntology unverified MIT (permissive) · de6b5f2a68a9e570 · report
prod sovrasov/flops-counter.pytorch/ptflops/aten_ops.py found in paper text by Syntology unverified MIT (permissive) · 185b3f3ea726676d · report
rnn_flops sovrasov/flops-counter.pytorch/ptflops/pytorch_ops.py found in paper text by Syntology unverified MIT (permissive) · 4883be8641ea59fd · report

Tasks

Computational EfficiencyLanguage ModelingLanguage ModellingMachine TranslationMasked Language ModelingMixture-of-Experts

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Absolute Position EncodingsAdamAttentionBPEDense ConnectionsDropoutLabel SmoothingLayer NormalizationLinear LayerMulti-Head AttentionPosition-Wise Feed-Forward LayerResidual ConnectionSoftmaxTransformer

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