MoSAR: Mixture of Semantic Attention Regimes for Learning Adaptive and Approximable Attention Geometries
Organizations: Department of Computer Science Università degli Studi di Bari Aldo Moro Bari, 70121, Italy
Abstract
The quadratic complexity of dense self-attention remains a central bottleneck for long-context language modeling. Many efficient alternatives address this cost by deciding in advance where attention should be sparse or local. We argue that attention approximation should instead be approached as a geometric problem, with the relevant interaction geometry learned from data: natural-language dependencies are input-dependent and difficult to prescribe in advance, so the model should learn where positional relevance can decay and where broader interactions must be preserved. We introduce Mixture of Semantic Attention Regimes (MoSAR), which learns such an adaptive, controlled-decay geometry over query--key interactions. Input-conditioned query and key routers, applied after positional encoding, select mixtures over short, medium, and global regimes, inducing a continuous distance-dependent attention field rather than a fixed sparsity pattern. This geometry is learned during training and can subsequently be discretized through top-1 routing. In controlled pre-training experiments with matched 500M-parameter models, MoSAR learns a substantially lower-reach attention geometry without degrading language-modeling quality, improving perplexity over dense RoPE at the training context length. Under length extrapolation, MoSAR achieves the best perplexity among all evaluated variants, including strong baselines such as ALiBi. Moreover, the learned geometry remains stable under deterministic top-1 discretization, suggesting that it is not only adaptive, but also amenable to low-cost approximation at inference time.
Figures & tables
| Method | Data- learned | Input adaptive | Token- wise | Attention approx. | Cost loss | Learned routing | Distance decay | Learned decay |
| Efficient and approximate attention | ||||||||
| Reformer ( Kitaev et al., 2020 ) | ✓ | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ | |
| Linformer ( Wang et al., 2020 ) | ✓ | ✗ | ✗ | ✓ | ✗ | ✗ | ✗ | ✗ |
| Longformer ( Beltagy et al., 2020 ) | ✗ | ✗ | ✗ | ✓ | ✗ | ✗ | ✗ | ✗ |
| Positional and geometric modifications | ||||||||
| ALiBi ( Press et al., 2021 ) | ✗ | ✗ | ✗ | ✗ | ✗ | ✗ | ✓ | ✗ |
| Method | LM loss | PPL@2k | PPL@4k | PPL@8k | @2k | @8k | Reach |
| MoSAR (ours) | 2.5071 | 12.269 | 11.753 | 12.208 | -1.99 | -19.6 | 0.2210 |
| ALiBi | 2.5186 | 12.411 | 11.873 | 12.232 | -0.85 | -19.4 | 1.0000 |
| Fixed-S (ours) | 2.5107 | 12.313 | 11.864 | 12.453 | -1.63 | -17.9 | 0.0625 |
| Fixed-M (ours) | 2.5069 | 12.267 | 11.827 | 12.520 | -2.00 | -17.5 | 0.2500 |
| RoPE-M-mask | 2.5419 | 12.703 | 12.212 | 12.584 | +1.49 | -17.1 | 0.2500 |
| MoSAR-Cost (ours) | 2.5299 | 12.553 | 12.053 | 13.276 | +0.28 | -12.5 | 0.0897 |
| Model | Length | Soft PPL | Top-1 PPL | Gap | Soft reach | Top-1 reach | ||||
| MoSAR | 2k | 12.269 | 12.703 | +3.5% | 0.2193 | 0.1544 | 0.741 | 0.108 | 0.681 | 0.166 |
| MoSAR | 4k | 11.753 | 12.216 | +3.9% | 0.1878 | 0.1276 | 0.734 | 0.114 | 0.666 | 0.180 |
| MoSAR | 8k | 12.208 | 12.872 | +5.4% | 0.1690 | 0.1038 | 0.734 | 0.115 | 0.640 | 0.181 |
| MoSAR-Cost | 2k | 12.553 | 13.123 | +4.5% | 0.0887 | 0.0724 | 0.955 | 0.010 | 0.890 | 0.021 |
| MoSAR-Cost | 4k | 12.053 | 12.737 | +5.7% | 0.0562 | 0.0424 | 0.934 | 0.017 | 0.878 | 0.020 |
| MoSAR-Cost | 8k | 13.276 | 13.795 | +3.9% | 0.0858 | 0.0481 | 0.812 | 0.079 | 0.794 | 0.051 |
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
| Mathematical object | Implementation | Compatibility condition |
|---|---|---|
| Configuration | mosar/config.py : MoSARConfig | Values and validation must match the experimental configuration. |
| mosar/routers.py : PostPositionRouter.forward | Inputs must be post positional; key heads must be unexpanded GQA heads. | |
| and | mosar/routers.py | Separate Q and K parameters; GELU MLP; final temperature scaled softmax. |
| Router initialization | mosar/routers.py : PostPositionRouter.reset_parameters | std , std , all biases zero. |
| mosar/regimes.py : pair_geometry | Arithmetic means and transition definitions must match the equations. | |
| mosar/regimes.py : RegimeKernel.forward | Non increasing non GG gates in ; exact . |
| Requirement | |
|---|---|
| Query routing is computed from post-positional query representations. | |
| Key routing is computed from post-positional, unexpanded key representations. | |
| Query and key routers are separately parameterized. | |
| Each router ends in a temperature-scaled softmax over regimes. | |
| Router MLP biases do not bypass the final softmax. | |
| The factorized pair weights are . |
Attention Mechanisms
Attention mechanisms let neural networks weight information from other tokens or regions according to relevance, enabling context-dependent processing.
See all 513 papers