Mixture of Attention

Optimizing LLM Inference Efficiency with Heterogeneous Sliding-Window Lengths.

3.9x
Effective Context / Avg. Attention Span
6.6-8.2x
Decode Throughput vs. FlashAttention2
1.7-1.9x
Decode Throughput vs. vLLM

Overview

Short attention spans can still preserve long-context behavior.

Uniform sliding windows give every head the same local budget. MoA assigns each head its own elastic span rule so local heads stay cheap and global heads keep enough context.

Uniform spans misallocate budget. Some heads mainly need local context, while others require broad context to preserve retrieval and understanding.

MoA searches per-head elastic rules. Attention span becomes a head-specific function of input length under a target density constraint.

The method is training-free. A calibration pass profiles attention influence, then an optimizer selects the best heterogeneous span plan.

MoA overview: attention patterns and elastic rules

The Discovery

Attention is heterogeneous in two ways.

Profiling pre-trained LLMs reveals two facts about attention heads. Together they explain why a single uniform sliding window cannot serve a whole model.

Observation 01

Different heads have different spans.

At a fixed input length, some heads concentrate in a narrow band near the diagonal, while others spread across the entire input. A uniform window truncates the global heads and breaks long-range retrieval, yet still overspends compute and KV cache on the local ones. At 25% attention density and 8k input length, heterogeneous elastic rules raise retrieval accuracy from 25% to 98%.

Attention matrices of three Vicuna-7B heads: a local head, a medium-span head, and a global head
Attention matrices from three Vicuna-7B heads, each averaged over 256 LongEval items: local, medium, and global spans coexist in one model.
Observation 02

Spans scale differently as the input grows.

At short lengths, many heads look identically dense, and the difference only appears once the input stretches. Some heads keep a fixed local span no matter how long the input gets, while others expand in proportion to it. MoA models each head's span as a linear rule S = α + β · N and searches α and β per head.

Attention matrix per head
Input length 4k
4k 8k 12k 16k
Head A

Local, fixed

S = 1.6k (β = 0)

40% of input

Head B

Medium, fixed

S = 5.6k (β = 0)

100% of input

Head C

Global, elastic

S = 0.9 · N (β > 0)

90% of input

Illustrative N×N causal attention matrices. Blue cells are kept by each head's rule; faint cells are masked. Heads B and C look alike at 4k. By 16k, one has stayed put while the other has kept growing.

Method

Search a heterogeneous attention-span plan.

MoA constructs a search space of elastic span rules, profiles attention influence on long-context calibration data, and selects the optimal rule for each head.

MoA workflow
MoA profiles attention influence, optimizes per-head elastic rules, and deploys the resulting heterogeneous sliding-window mask.

Elastic Search Space

Each attention head selects from rules that map input length to a hardware-friendly sliding-window span.

Influence Profiling

First-order gradient profiling estimates how masking attention positions changes the prediction loss.

Automatic Optimization

A density-constrained optimizer finds the best per-head plan, then validates it at an unseen sequence length.

Calibration

Useful profiling must test long-context dependence.

MoA calibrates on multi-document summarization and uses the dense model's own summaries as references. Profiling then measures how compression affects predictions that depend on distant context.

Long-range content

Summaries depend on evidence across documents.

Dependent output loss

Compute loss on the generated summary.

Model-aligned reference

Use dense-model summaries as supervision.

Weak Profiling

RedPajama context

0.25 retrieval / 4.95 PPL

MoA Profiling

MultiNews + dense reference

0.95 retrieval / 3.96 PPL
MoA calibration dataset ablation
Table 2: calibration ablation at 25% attention density and 8k input length. Long-range dependence and dense-model alignment both improve the result.

Experiments

MoA improves the accuracy-efficiency frontier.

Experiments cover long-context retrieval, LV-Eval, LongBench, perplexity, throughput, memory, and search-space ablations.

1.5-7.1x
Retrieval accuracy relative to uniform-window baselines across Vicuna and Llama3.
6.6-8.2x
Decode throughput speedup over FlashAttention2 at 50% density.
1.7-1.9x
Decode throughput speedup over vLLM at 50% density.
Overall Long-Context Performance

At 50% density, MoA stays close to full attention across retrieval accuracy, LV-Eval, LongBench, and perplexity. It reduces maximum relative drops to 5% on LV-Eval and 3% on LongBench, while the average retrieval drop stays below 1%.

For Vicuna-7B, effective context reaches up to 3.9× the average attention span across heads (Figure 7). Effective context is the longest input with retrieval accuracy above 90%.

MoA comparative performance results
Table 4 from the COLM 2025 version compares MoA with H2O, InfLLM, and StreamingLLM across Vicuna-7B, Vicuna-13B, Llama3-8B, and Llama3-70B.
Runtime and Memory Efficiency

MoA reduces attention computation and bounds KV cache size, allowing larger batches. A dedicated CUDA kernel supports its heterogeneous windows. The throughput comparison uses the largest supported batch size for each method, rather than a fixed batch size.

MoA decode throughput comparison
Table 5: Vicuna-7B and Vicuna-13B decoding on A100-80GB GPUs at 50% attention density. MoA reaches 6.6–8.2× throughput over FlashAttention2 and 1.7–1.9× over vLLM.
Search Space Ablation

Starting from a uniform mask, MoA progressively adds layer heterogeneity, head heterogeneity, and elastic rules. Head heterogeneity and elasticity deliver the largest retrieval improvements at 25% density.

MoA ablation study
Elastic heterogeneous rules improve retrieval accuracy from 0.25 to 0.98 at 8k input length under a 25% density budget.

Demo

From calibration to efficient long-context inference.

Calibrate once, search a model-specific attention plan, then use it for long-context decoding within the chosen KV cache budget.

01

Profile an LLM with a model-aligned long-context calibration set.

02

Search per-layer, per-head elastic window rules under the density budget.

03

Serve with a static, sparse, heterogeneous KV cache plan.

Team

Meet the researchers.

1Tsinghua University 2Infinigence-AI 3Stanford University 4Shanghai Jiao Tong University

*Equal contribution. Genghan Zhang made contributions while at Tsinghua University.

Citation

Cite our work.

If you find MoA useful for your research, please consider citing our paper.

BibTeX
@inproceedings{fu2025moa,
  title={Mixture of Attention Spans: Optimizing LLM Inference Efficiency with Heterogeneous Sliding-Window Lengths},
  author={Fu, Tianyu and Huang, Haofeng and Ning, Xuefei and Zhang, Genghan and Chen, Boju and Wu, Tianqi and Wang, Hongyi and Huang, Zixiao and Li, Shiyao and Yan, Shengen and Dai, Guohao and Yang, Huazhong and Wang, Yu},
  booktitle={Conference on Language Modeling},
  year={2025},
  url={https://arxiv.org/abs/2406.14909}
}