ZETA:利用 Z-order 曲线实现高效的 Top-k 注意力
ZETA: Leveraging Z-order Curves for Efficient Top-k Attention
AI总结:
本文提出 ZETA 框架,利用 Z-order 曲线将低维键和查询映射到一维空间以实现并行排序,从而解决了因果掩码下 top-k 注意力无法高效并行查询的问题,提升了长序列处理的效率并在多项任务上取得优异表现。
摘要:
近年来,Transformer 已成为序列建模架构的基础构建块。然而其核心是自注意力的使用,其内存和计算成本随序列长度 $N$ 呈二次增长,使得对于长序列而言代价过高。一种有前景的方法是 top-$k$ 注意力,它仅选择 $k$ 个最相关的 token,在显著降低空间和计算需求的同时,实现了与标准自注意力相当的性能。然而,因果掩码要求当前查询 token 仅关注过去的 token,这阻碍了现有的 top-$k$ 注意力方法并行搜索最相关的 token,从而限制了训练效率。在本研究中,我们提出 ZETA,利用 Z-Order 曲线实现高效的 Top-k Attention,以支持对整个序列的过去 token 进行并行查询。我们首先在理论上证明,键和查询维度的选择涉及维度灾难与投影后相对距离保持之间的权衡。基于这一洞察,我们提出降低键和查询的维度(与值相反),并进一步利用 Z-order 曲线将低维的键和查询映射到一维空间,从而允许并行排序,大幅提升了 top-$k$ token 选择的效率。实验结果表明,ZETA 在合成的 Multi-Query Associative Recall 任务上匹配了标准注意力的性能,并在 Long Range Arena 和 WikiText-103 语言建模上优于注意力及其变体。
英文摘要:
Over recent years, the Transformer has become a fundamental building block for sequence modeling architectures. Yet at its core is the use of self-attention, whose memory and computational cost grow quadratically with the sequence length $N$, rendering it prohibitively expensive for long sequences. A promising approach is top-$k$ attention, which selects only the $k$ most relevant tokens and achieves performance comparable to vanilla self-attention while significantly reducing space and computational demands. However, causal masks require the current query token to only attend to past tokens, preventing the existing top-$k$ attention method from efficiently searching for the most relevant tokens in parallel, thereby limiting training efficiency. In this work, we propose ZETA, leveraging \textbf{Z}-Order Curves for \textbf{E}fficient \textbf{T}op-$k$ \textbf{A}ttention, to enable parallel querying of past tokens for entire sequences. % in both space and time complexity of $\mathcal{O}(N \log N)$. We first theoretically show that the choice of key and query dimensions involves a trade-off between the curse of dimensionality and the preservation of relative distances after projection. In light of this insight, we propose reducing the dimensionality of keys and queries in contrast to values and further leverage $Z$-order curves to map low-dimensional keys and queries into \emph{one}-dimensional space, which permits parallel sorting, thereby largely improving the efficiency for top-$k$ token selection. Experimental results demonstrate that ZETA matches the performance of standard attention on the synthetic \textsc{Multi-Query Associative Recall} task and outperforms attention and its variants on \textsc{Long Range Arena} and \textsc{WikiText-103} language modeling.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。