用Z曲线加速注意力计算,让长序列处理更快更省资源。
ZETA: Leveraging Z-order Curves for Efficient Top-k Attention
- 用Z阶曲线将键值投影到一维空间,实现并行排序选Top-k
- 在长序列任务上性能接近标准注意力,训练效率提升明显
- 适合需要高效处理长文本的场景,如语言建模和长距离依赖
近年来,Transformer已成为序列建模的核心架构。然而其自注意力机制的内存与计算开销随序列长度N呈平方增长,使长序列处理代价高昂。顶-k注意力通过仅保留最相关的k个标记,在显著降低空间和计算需求的同时保持了与标准注意力相当的性能。但因果掩码要求当前查询仅关注过去标记,现有顶-k方法难以并行搜索,限制了训练效率。本文提出ZETA,利用Z阶曲线实现高效顶-k注意力,可在空间和时间复杂度均为O(N log N)下并行查询整个序列的过去标记。我们首先理论分析了键与查询维度选择在维度灾难与相对距离保留之间的权衡,据此建议降低键和查询的维度,而保留值的高维表示。进一步利用Z阶曲线将低维键与查询映射至一维空间,支持并行排序,极大提升顶-k标记选择效率。实验表明,ZETA在合成的多查询关联记忆任务上性能媲美标准注意力,在长程区域(Long Range Arena)和WikiText-103语言建模任务上优于标准注意力及其变体。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。