Mega

Mega combines gated attention with exponential moving average so that attention gains a local sequential inductive bias while retaining flexible content-dependent sequence mixing.

Metadata

FieldValue
PaperMega: Moving Average Equipped Gated Attention
AuthorsXuezhe Ma, Chunting Zhou, Xiang Kong, Junxian He, Liangke Gui, Graham Neubig, Jonathan May, Luke Zettlemoyer
Year2022 preprint; 2023 conference
VenueICLR 2023
arXiv2209.10655
OpenReviewqNLe3iq2El
Codefacebookresearch/mega
Statusfull note started

Question

Self-attention is flexible because it learns pairwise interactions:

But this flexibility comes with two pressures:

PressureMeaning
weak local inductive biasattention does not assume nearby tokens should matter more
quadratic sequence costfull attention materializes or computes an interaction pattern

Mega asks:

Its answer is:

Main Claim

Mega’s durable architecture claim is:

The paper positions Mega against Transformers and recent state-space models. It reports results across Long Range Arena, machine translation, autoregressive language modeling, image classification, and raw speech classification.

The important architecture point is not only the benchmark table. It is that Mega makes local memory an explicit part of the attention block:

This makes Mega a bridge between Attention Is All You Need, S4, Hyena, RetNet, and Mamba.

Architecture Contract

ItemContract
Inputordered token or feature sequence
Outputcontextual sequence representation
Target replacementTransformer self-attention block
Local biasexponential moving average over sequence positions
Content mixinggated single-head attention
Efficiency variantMega-chunk with fixed-size chunks
Main comparisonTransformer variants, S4, long-sequence sequence models

Mega is not a pure RNN, not a pure SSM, and not a standard Transformer. It keeps attention-style content mixing but adds a recurrent/convolution-like local smoothing path.

Exponential Moving Average

The basic EMA recurrence is:

Equivalently, the current output is a decayed weighted sum of past inputs:

This has an explicit positional bias:

The bias is useful for local sequential structure, but a fixed EMA alone is too rigid for general sequence modeling. Mega therefore uses a more flexible multi-dimensional damped EMA and feeds the result into gated attention.

Why EMA Helps Attention

Attention learns dependencies from data:

EMA provides a decayed local summary:

Mega uses the EMA path to create position-aware representations before the attention-style operation. In plain terms:

MechanismWhat It Adds
attentioncontent-dependent interaction
EMAlocal sequential inductive bias
gatingmultiplicative control over information flow
chunkinglower sequence complexity for long inputs

The combination is different from simply adding relative position bias. EMA gives a stateful local smoothing operator, not only a score offset.

Gated Attention View

Mega uses a gated attention unit rather than standard multi-head attention. A simplified block can be read as:

The exact paper formulation has more detail, but the reusable architecture idea is:

This is why Mega should be read together with Gating, Attention, and Convolution.

Mega-Chunk

Full attention over length has quadratic cost:

Mega-chunk reduces the cost by splitting the sequence into fixed-size chunks:

Within chunks, the model applies gated attention. Across the sequence, the EMA path helps preserve contextual continuity:

This gives a useful architecture pattern:

The paper reports that this linear-time variant loses little quality relative to full Mega under its evaluated settings.

Relation to Transformer, S4, Hyena, RetNet, and Mamba

PaperCore MixerMain Bias
Transformermulti-head self-attentionflexible pairwise token interaction
S4structured state-space layerlong-range linear state dynamics
Hyenagated implicit long convolutionlong convolution plus data-controlled gates
MegaEMA-equipped gated attentionlocal decayed memory plus content mixing
RetNetretentiondecayed key-value state with recurrent form
Mambaselective SSM scaninput-dependent state-space recurrence

Mega is especially useful for understanding a design pattern that later appears in several forms:

It is not the same as Mamba or RetNet, but it belongs in the same long-sequence architecture shelf.

Evidence to Read Carefully

EvidenceWhat It SupportsWhat To Check
Long Range Arena resultslong-sequence modeling qualitytask-specific inductive bias and baseline tuning
machine translation and language modelinggeneral sequence modeling beyond synthetic taskstraining budget and architecture parity
image and speech classificationmodality transfer of sequence blocktokenization and preprocessing differences
Mega-chunk resultschunking can reduce cost with limited quality losschunk size, context boundary, and memory path
comparison to S4 and Transformer variantsbroad competitivenesswhether implementation maturity differs

The key audit is:

Do not attribute every result to a single component unless an ablation isolates it.

Practical Interpretation

Use Mega as a reference when reading papers that:

  • add moving-average, decay, or local memory to attention;
  • replace multi-head attention with gated single-head variants;
  • combine chunked attention with recurrent or convolution-like memory;
  • compare attention against SSMs or long-convolution sequence models;
  • claim long-sequence improvements from local inductive bias.

Mega is a useful reminder that not all efficient sequence models remove attention. Some keep attention but make its inductive bias less blank.

Limitations

  • EMA favors local decayed dependencies, which may not match every task.
  • Chunking changes information flow at chunk boundaries.
  • Single-head gated attention should be compared against well-tuned multi-head baselines.
  • Results across modalities depend on tokenization, resolution, sequence length, and training recipe.
  • Later SSM/selective-scan models may have different hardware behavior and scaling profiles.

Why It Belongs in Architecture Papers

Mega contributes a reusable sequence block:

The paper is not merely an evaluation or application paper. It adds a concrete architectural primitive for long-sequence modeling.