MonarchAttention: Zero-Shot Conversion to Fast, Hardware-Aware Structured Attention

Can Yaras, Alec S Xu, Pierre Abillama, Changwoo Lee, Laura Balzano

Abstract

MonarchAttention introduces a sub-quadratic attention mechanism designed for "zero-shot" integration into pre-trained Transformers. By approximating standard attention matrices using hardware-efficient Monarch matrices, the method achieves up to an 8.2x speedup over FlashAttention-2. Crucially, it maintains high accuracy across vision, language, and generative tasks without requiring expensive retraining, bridging the gap between theoretical algorithmic efficiency and practical hardware performance.

The Quadratic Bottleneck in Transformers

The Transformer architecture is fundamentally limited by a "quadratic bottleneck": as input sequence length ($N$) increases, the computational cost of the attention mechanism grows by $N^2$. This scaling makes processing long-form documents or high-resolution images prohibitively expensive. While various efficient attention alternatives (e.g., linear attention, low-rank approximations) have been proposed, they typically suffer from poor transferability—failing to mimic the strongly diagonal patterns of pre-trained softmax attention—and hardware inefficiency, often performing poorly on modern GPUs due to excessive data movement.

Methods: Monarch Matrices and Variational Softmax

MonarchAttention addresses these issues by approximating the attention matrix using Monarch matrices. These structured matrices represent complex patterns through a sequence of batched dense matrix multiplications, which are the primary operations optimized for GPU Tensor Cores.

Technical Innovations

  • Variational Softmax: The authors replace the standard softmax formula with a variational optimization problem that maximizes an objective involving Shannon entropy.
  • Alternating Maximization: An iterative algorithm solves for the optimal Monarch matrix approximation with a complexity of $\Theta(N\sqrt{N}d)$, significantly better than the standard $O(N^2)$.
  • Hardware-Aware Implementation: Custom Triton kernels ensure operations remain "fused" within the GPU's fast SRAM, minimizing high-bandwidth memory (HBM) access and outperforming FlashAttention-2.

Zero-Shot Expressivity

A key advantage of MonarchAttention is its ability to capture the essential features of a pre-trained attention head immediately. Unlike other efficient baselines that produce noise when swapped into a pre-trained model, MonarchAttention's structure is expressive enough to preserve the sparse, diagonal importance found in standard attention maps.

MonarchAttention map showing preserved diagonal structure.

In Vision Transformer (ViT) benchmarks, this expressivity allows for an 80% reduction in attention FLOPs with only a 5% drop in accuracy, achieved without any additional training.

Key Results and Performance

The authors evaluated MonarchAttention across diverse benchmarks, including ImageNet-1K (ViT-B), SQuAD v1.1 (RoBERTa-B), and long-sequence summarization (BART-B).

  • Speed: MonarchAttention scales exceptionally well, providing a 1.4x speedup for short sequences ($N=256$) and reaching a massive 8.2x speedup for long sequences ($N=16K$) compared to FlashAttention-2.
  • Generative Quality: In Diffusion Transformers (DiT), MonarchAttention successfully generated high-quality images where other efficient baselines, such as Nyströmformer, failed and produced unrecognizable noise.
  • Long Contexts: For summarization tasks with sequences of $N=8192$, MonarchAttention outperformed standard softmax attention at lower costs, suggesting the structured approximation may act as a beneficial regularizer.

Limitations and Future Work

While highly effective for encoder-style processing, MonarchAttention currently faces challenges in autoregressive decoding (step-by-step token generation) and the efficient incorporation of causal masking. Future research may explore "finer-grained" approximations to allocate more parameters to critical regions of the attention map, further improving accuracy in complex tasks.

Summary updated

BibTeX
@inproceedings{yaras2025monarchattention,
  author = {Can Yaras and Alec S Xu and Pierre Abillama and Changwoo Lee and Laura Balzano},
  title = {{MonarchAttention: Zero-Shot Conversion to Fast, Hardware-Aware Structured Attention}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=XfHfTqeXfZ},
}
Figure