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

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Piękos, Piotr, Csordás, Róbert, Schmidhuber, Jürgen
Format: Preprint
Veröffentlicht: 2025
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866916715797938176
author Piękos, Piotr
Csordás, Róbert
Schmidhuber, Jürgen
author_facet Piękos, Piotr
Csordás, Róbert
Schmidhuber, Jürgen
contents Recent advances in large language models highlighted the excessive quadratic cost of self-attention. Despite the significant research efforts, subquadratic attention methods still suffer from inferior performance in practice. We hypothesize that dynamic, learned content-based sparsity can lead to more efficient attention mechanisms. We present Mixture of Sparse Attention (MoSA), a novel approach inspired by Mixture of Experts (MoE) with expert choice routing. MoSA dynamically selects tokens for each attention head, allowing arbitrary sparse attention patterns. By selecting $k$ tokens from a sequence of length $T$, MoSA reduces the computational complexity of each attention head from $O(T^2)$ to $O(k^2 + T)$. This enables using more heads within the same computational budget, allowing higher specialization. We show that among the tested sparse attention variants, MoSA is the only one that can outperform the dense baseline, sometimes with up to 27% better perplexity for an identical compute budget. MoSA can also reduce the resource usage compared to dense self-attention. Despite using torch implementation without an optimized kernel, perplexity-matched MoSA models are simultaneously faster in wall-clock time, require less memory for training, and drastically reduce the size of the KV-cache compared to the dense transformer baselines.
format Preprint
id arxiv_https___arxiv_org_abs_2505_00315
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Mixture of Sparse Attention: Content-Based Learnable Sparse Attention via Expert-Choice Routing
Piękos, Piotr
Csordás, Róbert
Schmidhuber, Jürgen
Machine Learning
Computation and Language
Recent advances in large language models highlighted the excessive quadratic cost of self-attention. Despite the significant research efforts, subquadratic attention methods still suffer from inferior performance in practice. We hypothesize that dynamic, learned content-based sparsity can lead to more efficient attention mechanisms. We present Mixture of Sparse Attention (MoSA), a novel approach inspired by Mixture of Experts (MoE) with expert choice routing. MoSA dynamically selects tokens for each attention head, allowing arbitrary sparse attention patterns. By selecting $k$ tokens from a sequence of length $T$, MoSA reduces the computational complexity of each attention head from $O(T^2)$ to $O(k^2 + T)$. This enables using more heads within the same computational budget, allowing higher specialization. We show that among the tested sparse attention variants, MoSA is the only one that can outperform the dense baseline, sometimes with up to 27% better perplexity for an identical compute budget. MoSA can also reduce the resource usage compared to dense self-attention. Despite using torch implementation without an optimized kernel, perplexity-matched MoSA models are simultaneously faster in wall-clock time, require less memory for training, and drastically reduce the size of the KV-cache compared to the dense transformer baselines.
title Mixture of Sparse Attention: Content-Based Learnable Sparse Attention via Expert-Choice Routing
topic Machine Learning
Computation and Language
url https://arxiv.org/abs/2505.00315