arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2612.06276cs.LG
收藏

并非每个Token都需要Softmax

Not Every Token Deserves Softmax

NVIDIA(英伟达)

Aviv Bick, Arshia Afzal, Roger Waleffe, Aakash Lahoti, Mostofa Patwary, Mohammad Shoeybi, Bryan Catanzaro, Eric P. Xing, Albert Gu

AI总结:

本文提出注意力路由核(Ark)架构,为每个Token单独选择核函数,在4亿至20亿参数规模下性能与Transformer等相当,内存大幅降低,长上下文解码速度显著提升。

摘要:

Softmax与线性注意力处于内存权衡的两端,因为它们采用不同的核函数比较Token:前者使用指数核并缓存所有Token,内存随序列长度线性增长;后者使用线性核,可因式分解将过去信息压缩为固定大小的循环状态,但召回能力有限。两种方法的核函数均固定,无法根据输入调整计算或内存。本文提出注意力路由核(Ark)架构,该架构在每一层及每个KV组中为每个Token单独选择核函数:学习得到的路由将每个Token分配到两个内存之一,需要指数核的Token保留在KV缓存中,其余Token折叠为固定大小的循环状态,每个查询会读取两个内存。路由拆分控制计算成本:训练时结合线性时间的循环传递与保留键的成对注意力,推理时维护固定大小的循环状态加KV缓存中的保留条目。在4亿至20亿参数规模下,Ark与Transformer、以及交替使用Softmax和线性注意力层的混合模型性能相当,但内存分别减少约90%和25%-53%。Ark的更小内存加速了长上下文解码:在64K长度下,20亿参数的Ark模型比GLA混合模型快1.8倍,比FlashAttention-4快3.8倍。代码可在该httpsURL获取。

英文摘要:

Softmax and linear attention sit at opposite ends of a memory tradeoff because they compare tokens with different kernels. The former uses an exponential kernel and caches every token, growing memory linearly with length; the latter uses a linear kernel, which factorizes so that the past compresses into a fixed-size recurrent state, at the cost of limited recall. In both cases the kernel is fixed, so neither adapts computation or memory to the input. We introduce Attention Routing Kernels (Ark), an architecture that chooses the kernel separately for each token, in every layer and KV group. A learned router sends each token to exactly one of two memories: tokens that need the exponential kernel stay in a KV cache, and the rest are folded into a fixed-size recurrent state. Every query reads both memories. The routing split governs cost: training combines a linear-time recurrent pass with pairwise attention over retained keys, while inference carries a fixed-size recurrent state plus the retained entries in the KV cache. Across 400M--2B parameters, Ark is competitive with Transformers and with hybrids that interleave softmax- and linear-attention layers, while storing about 90% and 25--53% less memory, respectively. Ark's smaller memory thus speeds up long-context decoding: at 64K, the 2B model is $1.8\times$ faster than a GLA hybrid and $3.8\times$ faster than FlashAttention-4. Code is available at https://github.com/goombalab/ark.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑