Introduction
Standard Transformer architectures rely on softmax attention, which presents two significant scaling challenges. First, its computational complexity is quadratic ($O(n^2)$) relative to sequence length, making long-context tasks like high-resolution image processing or document analysis prohibitively expensive. Second, softmax attention is only row-stochastic; it ensures each query's weights sum to one but does not regulate the "mass" received by individual keys. This often results in "token overfocusing," where the model fixates on a small subset of tokens, potentially ignoring relevant information and reducing robustness.
LOTFormer addresses these issues by introducing a "doubly stochastic" linear-time attention mechanism. By balancing attention weights across both queries (rows) and keys (columns) through a set of learnable "pivots," LOTFormer achieves the robustness of balanced attention without the quadratic overhead.
Methodology: Low-Rank Optimal Transport
The core innovation of LOTFormer is the Low-Rank Optimal Transport (LOT) framework. Instead of computing a direct $n \times n$ relationship between all queries and keys, the model routes attention through a small set of $r$ learnable pivots ($r \ll n$).
The "Glued" Coupling
The attention mechanism is decomposed into two smaller, efficient Optimal Transport problems:
- Queries to Pivots: Mapping input queries to the learnable pivot points.
- Pivots to Keys: Mapping those same pivots to the input keys.
By "gluing" these two transport plans together, the model forms a complete attention matrix that is provably doubly stochastic. This composition ensures that both rows and columns sum to one, preventing any single token from dominating the attention map or being entirely neglected.
Linear Complexity and Learnability
Because the attention matrix factorizes through the $r$ pivots, the computational complexity is reduced to $O(nr)$, which is linear in sequence length. Unlike previous landmark-based methods that used fixed points, LOTFormer learns the locations and importance (masses) of these pivots end-to-end. Additionally, a specialized [CLS] Polarization technique is employed to prevent the global aggregation token from being overly diluted by the balancing constraints.
Experimental Evaluation
LOTFormer was evaluated across a diverse range of benchmarks, including ImageNet-1K (Vision), Long Range Arena (Long-Context), and GLUE (NLP).
Performance and Scalability
On ImageNet-1K, LOTFormer consistently outperformed standard softmax and other linear baselines. For instance, using a DeiT-Tiny backbone, LOTFormer achieved 74.8% Top-1 accuracy, a significant improvement over the 72.2% achieved by standard softmax.
In the Long Range Arena (LRA) suite, LOTFormer reached an average score of 62.90, surpassing competitive models like Mamba2 (62.21) and DeltaNet (61.19). Crucially, runtime analysis confirms that LOTFormer scales linearly, remaining functional at sequence lengths as high as $2^{17}$ (131,072 tokens), where quadratic methods like Sinkformer fail due to memory constraints.
Key Insights
- Attention as Resource Allocation: By framing attention as an Optimal Transport problem, the authors treat information flow as a resource-allocation task. This perspective leads to more balanced and robust representations.
- Object-Centric Emergence: Visualizations indicate that as the number of pivots ($r$) increases, attention maps naturally become more "object-centric," identifying semantically relevant image regions without explicit supervision.
- Plug-and-Play Compatibility: LOTFormer demonstrates remarkable transferability. A pre-trained BERT-base model can have its attention mechanism swapped for LOTFormer, recovering 99.7% of its original performance with minimal additional training.
Conclusion and Future Work
While LOTFormer excels in encoder-based tasks (like BERT or Vision Transformers), the doubly stochastic constraints are currently incompatible with the causal masking required for auto-regressive text generation. Future research will focus on relaxing these constraints to support generative decoders and developing custom CUDA kernels to further optimize wall-clock performance, bridging the gap with highly optimized quadratic kernels like FlashAttention.
Summary updated