Abstract
To overcome the quadratic cost of self-attention, recent works have proposed various sparse attention modules, most of which fall under one of two groups: 1) sparse attention under a hand-crafted patterns and 2) full attention followed by a sparse variant of softmax such as $\alpha$-entmax. Unfortunately, the first group lacks adaptability to data while the second still requires quadratic cost in training. In this work, we propose SBM-Transformer, a model that resolves both problems by endowing each attention head with a mixed-membership Stochastic Block Model (SBM). Then, each attention head data-adaptively samples a bipartite graph, the adjacency of which is used as an attention mask for each input. During backpropagation, a straight-through estimator is used to flow gradients beyond the discrete sampling step and adjust the probabilities of sampled edges based on the predictive loss. The forward and backward cost are thus linear to the number of edges, which each attention head can also choose flexibly based on the input. By assessing the distribution of graphs, we theoretically show that SBM-Transformer is a universal approximator for arbitrary sequence-to-sequence functions in expectation. Empirical evaluations under the LRA and GLUE benchmarks demonstrate that our model outperforms previous efficient variants as well as the original Transformer with full attention.
Introduction
The Transformer architecture has revolutionized machine learning, yet its primary mechanism—self-attention—suffers from a fundamental scalability issue. The quadratic $O(n^2)$ complexity relative to sequence length makes processing high-resolution images or long documents computationally prohibitive.
Existing attempts to mitigate this cost generally fall into two categories. The first involves fixed, hand-crafted sparsity patterns (e.g., sliding windows), which are efficient but lack the ability to adapt to specific data features. The second involves learnable sparsity (e.g., $\alpha$-entmax), which is adaptive but often requires calculating the full $N \times N$ attention matrix during training to determine which elements to prune, negating the computational savings. The SBM-Transformer introduces a novel approach that is both data-adaptive and computationally efficient during both training and inference.
The SBM-Transformer Architecture
The core innovation of the SBM-Transformer is the integration of a Stochastic Block Model (SBM) into the attention mechanism. Instead of computing all possible pairwise interactions, the model treats the attention mask as a bipartite graph sampled from an SBM.
Data-Adaptive Graph Sampling
In this framework, tokens are assigned to latent clusters. The probability of an edge (an attention connection) existing between two tokens is determined by their respective cluster memberships. To maintain efficiency, the researchers utilize the fastRG algorithm, which allows for the sampling of $m$ edges in $O(m + n)$ time. This ensures that the computational cost is proportional to the number of connections the model chooses to make, rather than the total possible connections.
Differentiable Training via STE
Because sampling a graph is a discrete and non-differentiable operation, standard backpropagation cannot be applied directly. The SBM-Transformer overcomes this by using a Straight-Through Estimator (STE). This technique allows gradients to flow from the final task loss back to the SBM parameters, effectively training the model to "learn" which attention edges are most beneficial for the given task.
Universal Approximation
Beyond empirical performance, the authors provide theoretical grounding for the SBM-Transformer. They demonstrate that by assessing the distribution of the sampled graphs, the model remains a universal approximator for arbitrary sequence-to-sequence functions in expectation, matching the expressive power of full-attention Transformers.
Experimental Evaluation
The SBM-Transformer was evaluated across three distinct benchmarks to test its adaptability, efficiency, and general language understanding.
Long Range Arena (LRA)
On the LRA benchmark, which focuses on long-sequence tasks (up to 4,000 tokens), the SBM-Transformer achieved an average score of 59.93. This outperformed several prominent efficient variants, including Nyströmformer and Reformer, as well as the standard Full Attention Transformer. Notably, on the ListOps task, the model achieved competitive accuracy while utilizing only 7% of the FLOPs required by full attention.
Synthetic Stress Test
To test whether the model could adaptively increase its density when necessary, the researchers used a "Finding Repeated Tokens" task. While other efficient models like Performer or Linformer struggled, the SBM-Transformer successfully learned to increase its mask density toward 100% to solve the problem, demonstrating its unique ability to use compute only when the task demands it.
GLUE Benchmark
On standard natural language understanding tasks (SST-2, QQP, MNLI, QNLI), the SBM-Transformer maintained performance levels comparable to the original Transformer, ensuring that the efficiency gains do not come at the cost of general linguistic capability.
Discussion and Insights
Qualitative analysis of the model revealed layer-wise specialization. Lower layers tended to utilize denser attention patterns to capture broad global context, while upper layers became highly sparse and specialized. This behavior, which mimics the structure of large-scale models like BERT, emerges automatically through the learned SBM parameters.
Furthermore, the model converged to an average attention density of 20% to 30% on LRA tasks without any explicit sparsity penalty. This suggests that learned sparsity may act as a form of regularization, helping the model filter out noise in long sequences.
Conclusion
The SBM-Transformer represents a significant step toward flexible, efficient attention. By treating attention as a sampled graph problem, it achieves a balance between data-adaptivity and linear computational cost. While current hardware is heavily optimized for dense matrix operations—presenting a practical hurdle for unstructured sparse models—the SBM-Transformer provides a theoretical and empirical foundation for the next generation of efficient sequence models. As sparse-optimized GPU kernels continue to mature, the practical speedups of this approach are expected to grow significantly.
Summary updated