Mixture of Sparse Attention: Content-Based Learnable Sparse Attention via Expert-Choice Routing

Piotr Piekos, Róbert Csordás, Firas Laakom, Li Nanbo, Jürgen Schmidhuber

TL;DR

Mixture of Sparse Attention (MoSA) introduces a dynamic, content-based sparse attention mechanism that uses expert-choice routing to let individual attention heads select a subset of tokens to process. This reduces attention head complexity from quadratic to subquadratic ($O(k^2 + T)$), allowing models to deploy more specialized heads within the same compute budget and outperform dense baselines by up to 27% in perplexity.

What Problem Does This Paper Address?

The standard self-attention mechanism in Transformers scales quadratically ($O(T^2)$) with sequence length $T$, creating a massive computational and memory bottleneck for long-context Large Language Models (LLMs).

While subquadratic alternatives exist—such as State Space Models (SSMs), linear attention, and static sparse attention (e.g., block-sparse patterns)—they often suffer from inferior practical performance. Static sparse methods use rigid, data-independent patterns that force lossy compression of tokens. Existing dynamic, content-based sparse attention methods (like the Routing Transformer) can learn data-dependent patterns but rely on slow-converging clustering algorithms like online K-means and still require computing full projections before clustering.

Methods

The authors propose Mixture of Sparse Attention (MoSA), an approach inspired by Mixture of Experts (MoE) architectures. Instead of tokens choosing which attention heads to attend to, MoSA flips the routing paradigm using Expert-Choice Routing.

Each attention head acts as an independent "expert" and uses a lightweight router network to select its own top-$k$ most relevant tokens from the input sequence.

MoSA layer architecture compared to dense attention

Key algorithmic details include:

  1. Selective Projections: Linear projections for queries, keys, and values are calculated only for the selected $k$ tokens, dropping the rest. This slashes the computational complexity of a head to $O(k^2 + T)$.
  2. Hybridization: The authors discovered that a "pure" MoSA model fails to converge because the router and attention weights face a chicken-and-egg training dilemma. To stabilize learning, MoSA uses a hybrid setup, combining sparse heads with a small number of standard dense heads (or local attention heads for ultra-long sequences).

Datasets

Models were pre-trained on the C4 (Colossal Clean Crawled Corpus) dataset. To evaluate downstream zero-shot capabilities, the authors tested the models across six standard benchmarks: LAMBADA, WinoGrande, BLiMP, HellaSwag, PIQA, and AI2ARC.

Key Insights and Ideas

  • Perfect Load Balancing by Design: By inverting the routing mechanism (heads choosing tokens), MoSA guarantees perfectly balanced token selection across heads without needing complex auxiliary load-balancing losses.
  • The Power of Head Specialization: Because MoSA heads are computationally cheap, a model can scale up the total number of heads under a fixed FLOP budget. This allows individual heads to highly specialize in specific types of token relationships.
  • Dense Heads as an Anchor: Purely sparse attention models suffer from training instabilities. Retaining a few dense heads acts as a representation safety net, allowing the sparse routers the stability they need to converge on meaningful token selections.

Key Results

  • IsoFLOP Superiority: In a strict FLOP-matched setup across scales from 28M to 516M parameters, MoSA was the only sparse attention variant that consistently outperformed the dense baseline, achieving up to a 27% improvement in perplexity.
Perplexity of FLOP-matched models under different sparsities
  • Wall-Clock and Memory Efficiency: In perplexity-matched evaluations, a vanilla PyTorch implementation of MoSA delivered up to a 12.9% wall-clock speedup and a 10% reduction in training memory usage compared to dense baselines.
  • Drastic KV-Cache Reduction: MoSA reduced the total number of key-value pairs stored in memory by 51.1% to 69.5%, directly alleviating the primary memory bottleneck for LLM inference deployment.

Limitations and Future Work

  • Non-Autoregressive Routing: Because the top-$k$ selection requires a global operation over the sequence, MoSA is inherently non-autoregressive. To use it for causal, token-by-token generation, future work must integrate causal routing predictors (similar to techniques used in Mixture-of-Depths).
  • Short Sequence Performance Drop: MoSA underperforms on datasets with extremely short inputs (like BLiMP) due to a distribution mismatch; heads trained to select a tiny fraction of tokens from a long sequence are forced to select a much larger relative percentage in short sequences.
  • Hardware Optimization: The current implementation relies entirely on standard PyTorch operations. Writing specialized CUDA kernels represents a clear path to unlocking even greater wall-clock speedups.

Summary updated

BibTeX
@article{piekos2026mixture,
  author = {Piotr Piekos and Róbert Csordás and Firas Laakom and Li Nanbo and Jürgen Schmidhuber},
  title = {{Mixture of Sparse Attention: Content-Based Learnable Sparse Attention via Expert-Choice Routing}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2026},
}
Figure