RACE Attention: A Strictly Linear-Time Attention for Long-Sequence Training

Sahil Joshi, Agniva Chowdhury, Amar Kanakamedala, Ekam Singh, Evan Tu, Anshumali Shrivastava

Executive Summary

RACE Attention is a novel attention mechanism that achieves strictly linear time and memory complexity by replacing the standard Softmax kernel with a differentiable "soft" hashing scheme. It allows today’s hardware to process sequences of up to 12 million tokens on a single GPU and 75 million tokens on a CPU—scaling orders of magnitude beyond the limits of state-of-the-art optimizations like FlashAttention.

The Quadratic Bottleneck of Softmax Attention

The "Achilles' heel" of the Transformer architecture is the Softmax Attention mechanism. Its computational cost grows quadratically ($O(N^2)$) with the sequence length ($N$). As the field moves toward "infinite context" applications—such as analyzing entire codebases, long-form videos, or massive document collections—this quadratic scaling becomes a prohibitive brick wall.

Even with highly optimized, exact kernels like FlashAttention-2/3, a single NVIDIA GH200 (96GB) GPU runs out of memory or becomes impractically slow once a sequence hits roughly 4 million tokens. While industrial labs throw massive distributed clusters at this problem, most researchers and practitioners are locked out. The authors argue that overcoming this barrier requires more than just better hardware acceleration; it demands a fundamental algorithmic rethink of how attention is calculated.

The RACE Attention Architecture

To solve this, the authors introduce RACE (Repeated Arrays-of-Count Estimators) Attention. The core innovation lies in bypassing the full attention matrix construction entirely.

Comparison of Softmax Attention and RACE Attention

RACE achieves this through two primary modifications:

  1. Kernel Substitution: They replace the standard exponential (Softmax) kernel with a sharpened angular similarity kernel. By raising the angular similarity to a power ($\gamma$), they mimic the "sharpness" of Softmax—ensuring the model can still focus intensely on specific tokens—while using a function that is much easier to approximate linearly.
  2. Soft Locality-Sensitive Hashing (LSH): Traditional LSH is "hard" (discrete), making it non-differentiable and difficult to train. RACE Attention introduces a smooth, differentiable relaxation of LSH.
  3. Instead of assigning a query to a single discrete "bucket," it uses a tanh-based soft assignment across $R = 2^P$ hypercube corners.
  4. It aggregates key-value statistics into these buckets without ever materializing the full $N \times N$ attention matrix.
  5. The final output is reconstructed by querying these "bucket summaries," resulting in a complexity of $O(N)$ rather than $O(N^2)$.

Evaluation Scope

The researchers evaluated RACE Attention across a wide variety of modalities and tasks to ensure its generalizability:

  • Language Modeling: WikiText-103 and PTB (Penn Tree Bank).
  • Masked Language Modeling: Tiny Stories.
  • Text Classification: QNLI, SST-2, IMDB, Yahoo, and a custom long-context variant of Arxiv (up to 64K tokens).
  • Image Classification: CIFAR-10, FashionMNIST, and Food-101 (using Vision Transformer architectures).
  • Long Range Arena (LRA): ListOps and Text Retrieval benchmarks.

Performance and Scaling Breakthroughs

  • Extreme Scaling: RACE successfully completed a forward-backward pass for 12 million tokens on a single GPU and 75 million tokens on a CPU. For context, FlashAttention-2/3 fails at ~4 million tokens on the same GPU.
  • Algorithm > Hardware Acceleration: One of the most striking findings is that a linear algorithm on a "weak" CPU can outperform a quadratic algorithm on a "powerful" GPU at scale. At 4 million tokens, RACE running on an Intel Xeon CPU was roughly 40x faster than FlashAttention-2 running on an NVIDIA GH200 GPU.
  • Massive GPU Speedups: At the 4-million token mark on the same hardware, RACE is approximately 5500x faster than FlashAttention-2 on GPUs.
  • Competitive Accuracy: In the 16K to 64K sequence length range (Arxiv classification), RACE ($P=4, L=4$) achieved 91.1% accuracy, outperforming FlashAttention (89.7%) and Linear Attention (87.3%).
  • Theoretical Guarantees: Unlike many approximate attention methods, RACE comes with a rigorous bias-variance analysis. The authors prove that the approximation error vanishes as the number of hash tables ($L$) and the temperature ($\beta$) increase.

Current Limitations and Future Directions

While RACE Attention offers a massive leap in scalability, the authors note a few areas for ongoing development:

  • Causal Theory Gap: While the authors provide an efficient implementation for causal (autoregressive) masking, their current theoretical error bounds strictly cover only the non-causal (bidirectional) case. Closing this theoretical gap is a priority for future work.
  • Hyperparameter Complexity: RACE introduces new hyperparameters, such as the number of hash tables ($L$) and hyperplanes ($P$). Finding the optimal balance between accuracy and speed for a specific new task may require additional tuning compared to standard Softmax.
  • Hardware-Specific Kernels: The current CUDA/OpenMP kernels are fast, but deeper integration with hardware-specific features (like those leveraged by FlashAttention) could push performance even further.

Summary updated

BibTeX
@inproceedings{joshi2026race,
  author = {Sahil Joshi and Agniva Chowdhury and Amar Kanakamedala and Ekam Singh and Evan Tu and Anshumali Shrivastava},
  title = {{RACE Attention: A Strictly Linear-Time Attention for Long-Sequence Training}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=RR8Lh8RHgA},
}
Figure