Paper Reading AI Learner

Replacing Softmax Similarity with a Sharpened Angular Similarity: Theory and Practice of Scaling To Billion-Context Attention

2025-10-05 02:57:40
Sahil Joshi, Agniva Chowdhury, Amar Kanakamedala, Ekam Singh, Evan Tu, Anshumali Shrivastava

Abstract

Softmax Attention has a quadratic time complexity, which becomes prohibitive to run at long contexts, even with highly optimized GPU kernels. For example, FlashAttention (an exact, GPU-optimized implementation of Softmax Attention) cannot complete a single forward-backward pass of a multi-head attention layer once the context exceeds ~4 million tokens on an NVIDIA GH200 (96 GB). We introduce RACE Attention, a kernel-inspired alternative to Softmax Attention that is linear in sequence length and embedding dimension. RACE Attention replaces the exponential kernel with a sharpened angular (cosine) similarity, and approximates attention outputs via randomized projections and soft Locality-Sensitive Hashing (LSH). Across language modeling, masked language modeling, and text classification, RACE Attention matches the accuracy of strong baselines while reducing runtime and memory. In a controlled scale test, it processes up to 12 million tokens during a single forward-backward pass on an NVIDIA GH200 GPU and 75 million tokens on an Intel Xeon Gold 5220R CPU, well beyond the practical limits of the current state-of-the-art attention implementations. RACE Attention thus offers a practical, theoretically grounded mechanism for outrageously long context windows on today's hardware. We hope that it gets adopted in practice.

Abstract (translated)

Softmax注意力机制的时间复杂度为二次方,这在处理长上下文时变得非常不可行,即使使用了高度优化的GPU内核也是如此。例如,FlashAttention(一种精确且经过GPU优化的Softmax Attention实现)在NVIDIA GH200 GPU上一旦上下文超过约4百万令牌,就无法完成多头注意力层的一次前向-反向传递。 我们引入了一种名为RACE Attention的新方法,这是一种受内核启发的替代方案,它的时间复杂度与序列长度和嵌入维度呈线性关系。RACE Attention通过使用锐化的余弦相似度(即角相似度)来替换指数核,并且通过随机投影和软局部敏感哈希(LSH)近似注意力输出。 在语言建模、遮蔽语言建模以及文本分类等多种任务中,RACE Attention能够在减少运行时间和内存消耗的同时与强大的基准模型达到相同的准确性。在一个受控的规模测试中,在NVIDIA GH200 GPU上处理多达1.2亿个令牌,在Intel Xeon Gold 5220R CPU上处理多达7.5亿个令牌的一次前向-反向传递,远远超过了当前最先进的注意力机制实现的实际限制。 因此,RACE Attention为当今硬件上的极长上下文窗口提供了理论上合理且实用的解决方案。我们希望它能在实践中被采用。

URL

https://arxiv.org/abs/2510.04008

PDF

https://arxiv.org/pdf/2510.04008.pdf


Tags
3D Action Action_Localization Action_Recognition Activity Adversarial Agent Attention Autonomous Bert Boundary_Detection Caption Chat Classification CNN Compressive_Sensing Contour Contrastive_Learning Deep_Learning Denoising Detection Dialog Diffusion Drone Dynamic_Memory_Network Edge_Detection Embedding Embodied Emotion Enhancement Face Face_Detection Face_Recognition Facial_Landmark Few-Shot Gait_Recognition GAN Gaze_Estimation Gesture Gradient_Descent Handwriting Human_Parsing Image_Caption Image_Classification Image_Compression Image_Enhancement Image_Generation Image_Matting Image_Retrieval Inference Inpainting Intelligent_Chip Knowledge Knowledge_Graph Language_Model LLM Matching Medical Memory_Networks Multi_Modal Multi_Task NAS NMT Object_Detection Object_Tracking OCR Ontology Optical_Character Optical_Flow Optimization Person_Re-identification Point_Cloud Portrait_Generation Pose Pose_Estimation Prediction QA Quantitative Quantitative_Finance Quantization Re-identification Recognition Recommendation Reconstruction Regularization Reinforcement_Learning Relation Relation_Extraction Represenation Represenation_Learning Restoration Review RNN Robot Salient Scene_Classification Scene_Generation Scene_Parsing Scene_Text Segmentation Self-Supervised Semantic_Instance_Segmentation Semantic_Segmentation Semi_Global Semi_Supervised Sence_graph Sentiment Sentiment_Classification Sketch SLAM Sparse Speech Speech_Recognition Style_Transfer Summarization Super_Resolution Surveillance Survey Text_Classification Text_Generation Time_Series Tracking Transfer_Learning Transformer Unsupervised Video_Caption Video_Classification Video_Indexing Video_Prediction Video_Retrieval Visual_Relation VQA Weakly_Supervised Zero-Shot