RACE 注意力:一种严格线性时间的注意力层,用于在极端长上下文中训练
RACE Attention: A Strictly Linear-Time Attention Layer for Training on Outrageously Large Contexts
AI总结:
RACE 注意力通过替代指数核为锐化角相似性,并利用高斯随机投影和软局部敏感哈希,实现线性时间复杂度的注意力层,适用于超长上下文训练,同时减少时间和内存消耗。
摘要:
Softmax 注意力在序列长度上具有二次时间复杂度,这在长上下文上变得不可行,即使使用高度优化的 GPU 内核。例如,FlashAttention-2/3(Softmax 注意力的精确、GPU 优化实现)在 NVIDIA GH200(96 GB)上,当上下文超过 ~400 万 token 时,无法完成单个注意力层的前向-反向传递。我们引入了重复数组计数估计器(RACE)注意力,这是一种受内核启发的 Softmax 注意力 替代方案,其时间复杂度严格与序列长度和嵌入大小成线性关系。RACE 注意力用锐化角相似性替代指数核,并通过高斯随机投影和软局部敏感哈希(LSH)近似注意力输出,避免构建完整的注意力矩阵。在语言建模、掩码语言建模和文本/图像分类中,RACE 注意力在 64K 序列长度内匹配或优于强基线,同时减少墙钟时间和内存使用。此外,我们对单个注意力层进行了受控扩展研究,并在 NVIDIA GH200 GPU 上处理了 1200 万 token,在 Intel Xeon Gold 5220R CPU 上处理了 7500 万 token,这远远超出了当前最先进注意力实现的能力。RACE 注意力因此为在当今硬件上进行长上下文训练提供了一种实用且理论严谨的机制。我们发布代码在 https://github.com/sahiljoshi515/RACE_Attention。
英文摘要:
Softmax Attention has a quadratic time complexity in sequence length, which becomes prohibitive to run at long contexts, even with highly optimized GPU kernels. For example, FlashAttention-2/3 (exact, GPU-optimized implementations of Softmax Attention) cannot complete a single forward-backward pass of a single attention layer once the context exceeds ~4 million tokens on an NVIDIA GH200 (96 GB). We introduce Repeated Arrays-of-Count Estimators (RACE) Attention, a kernel-inspired alternative to Softmax Attention that is strictly linear in sequence length and embedding size. RACE Attention replaces the exponential kernel with a sharpened angular similarity, and approximates attention outputs via Gaussian random projections and soft Locality-Sensitive Hashing (LSH), avoiding construction of the full attention matrix. Across language modeling, masked language modeling, and text/image classification, RACE Attention matches or outperforms strong baselines up to 64K seqeuence length while reducing wall-clock time and memory usage. In addition, we conduct a controlled scaling study on a single attention layer and demonstrate processing of up to 12 million tokens on an NVIDIA GH200 GPU and 75 million tokens on an Intel Xeon Gold 5220R CPU in a single forward-backward pass, which is well beyond the capabilities of current state-of-the-art attention implementations. RACE Attention thus offers a practical and theoretically grounded mechanism for long-context training on today's hardware. We release our code at https://github.com/sahiljoshi515/RACE_Attention.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。