Papers › Mega: Moving Average Equipped Gated Attention

Mega: Moving Average Equipped Gated Attention

21 Sep 2022arXiv:2209.10655archive 2025-07-28

Xuezhe Ma, Chunting Zhou, Xiang Kong, Junxian He, Liangke Gui, Graham Neubig, Jonathan May, Luke Zettlemoyer

The design choices in the Transformer attention mechanism, including weak inductive bias and quadratic computational complexity, have limited its application for modeling long sequences. In this paper, we introduce Mega, a simple, theoretically grounded, single-head gated attention mechanism equipped with (exponential) moving average to incorporate inductive bias of position-aware local dependencies into the position-agnostic attention mechanism. We further propose a variant of Mega that offers linear time and space complexity yet yields only minimal quality loss, by efficiently splitting the whole sequence into multiple chunks with fixed length. Extensive experiments on a wide range of sequence modeling benchmarks, including the Long Range Arena, neural machine translation, auto-regressive language modeling, and image and speech classification, show that Mega achieves significant improvements over other sequence models, including variants of Transformers and recent state space 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="2209.10655")

Code

Syntology Ran 12 of 13 code samples harvested from 3 repositories linked to this paper; 1 has no recorded run. Of those that ran: 2 ran · our draft was wrong; 2 ran · fixture could not drive it; 8 ran with no contract checked.

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

facebookresearch/mega officialmentioned in papermentioned on GitHubpytorchMIT report
ZIZUN/MAFiD mentioned on GitHubpytorch report
ethanbar11/ssm_2d mentioned on GitHubpytorch report
huggingface/transformers mentioned on GitHubpytorch report
linghao-jin/canmt-challenges mentioned on GitHubpytorch report
lucidrains/gated-state-spaces-pytorch mentioned on GitHubpytorch report
pwc-1/Paper-9 mindspore 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

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

2ran · our draft was wrong
2ran · fixture could not drive it
8ran
1unverified

Licence: 8 of the 13 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 facebookresearch/mega/fairseq/models/mega.py official repository ran · our draft was wrong MIT (permissive) · 96cbb5e9ca5b6be0 · report
Linear facebookresearch/mega/fairseq/models/mega.py official repository ran · our draft was wrong MIT (permissive) · 8cd8cb0d1e9e63e4 · report
safe_readline facebookresearch/mega/fairseq/binarizer.py official repository ran MIT (permissive) · 82bdf940665aeeb4 · report
DSS lucidrains/gated-state-spaces-pytorch/gated_state_spaces_pytorch/gss.py community (archive-listed) ran · metamorphic tier: invariant MIT (permissive) · 7cf1fc5a8fb4711f · report
GSS lucidrains/gated-state-spaces-pytorch/gated_state_spaces_pytorch/gss.py community (archive-listed) ran · metamorphic tier: invariant MIT (permissive) · e0fb8682bea0936e · report
LaplacianAttnFn ZIZUN/MAFiD/src/model.py community (archive-listed) ran fingerprinted no licence file found · pointer only · 28048afa2b58e989 · report
MultiHeadedEMA ZIZUN/MAFiD/src/model.py community (archive-listed) ran no licence file found · pointer only · d65478e4afde1394 · report
OffsetScale ZIZUN/MAFiD/src/model.py community (archive-listed) ran no licence file found · pointer only · fd172a441158b8cf · report
SingleHeadedAttention ZIZUN/MAFiD/src/model.py community (archive-listed) ran no licence file found · pointer only · bf0381787b2cfd85 · report
T5RelativePositionBias ZIZUN/MAFiD/src/model.py community (archive-listed) ran fingerprinted no licence file found · pointer only · 75a6e13f59e67f7e · report
append_dims ZIZUN/MAFiD/src/model.py community (archive-listed) ran · fixture could not drive it fingerprinted no licence file found · pointer only · af830e39fdd08afa · report
conv1d_fft ZIZUN/MAFiD/src/model.py community (archive-listed) ran · fixture could not drive it no licence file found · pointer only · c3e96d57908b9ca9 · report
MegaLayer ZIZUN/MAFiD/src/model.py community (archive-listed) unverified no licence file found · pointer only · cfbd8ca4d8912d27 · report

Tasks

Image ClassificationInductive BiasLanguage ModelingLanguage ModellingListOpsLong-range modelingMachine TranslationState Space Models

1 archive task tag without a task page not shown.

Results from the paper archive 2025-07-28

TaskDatasetModelMetricValueRank at snapshotLeaderboardReport
Image Classification ImageNet Mega Number of params 90M #543 of 1060 Archive leaderboard report
Image Classification ImageNet Mega Top 1 Accuracy 82.4% #543 of 1060 Archive leaderboard report
Language Modelling WikiText-103 Mega Number of params 252M #30 of 89 Archive leaderboard report
Language Modelling WikiText-103 Mega Test perplexity 18.07 #30 of 89 Archive leaderboard report
Machine Translation WMT2014 English-German Mega BLEU score 29.01 #33 of 91 Archive leaderboard report
Machine Translation WMT2014 English-German Mega Number of Params 67M #33 of 91 Archive leaderboard report
Machine Translation WMT2014 English-German Mega SacreBLEU 27.96 #33 of 91 Archive leaderboard report
Machine Translation WMT2014 German-English Mega BLEU score 33.12 #4 of 16 Archive leaderboard report

Ranks are positions in the archive's leaderboards as they stood at the 2025-07-28 snapshot. Results published since then are not among these rows, so a rank here is not a current standing.

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