arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.01651cs.CLcs.AI
收藏

面向长上下文语言建模的基于因果检索的高效长度泛化注意力机制

Efficient Length-Generalizable Attention via Causal Retrieval for Long-Context Language Modeling

ShanghaiTech University(上海科技大学);Fudan University(复旦大学)

Xiang Hu, Zhihao Teng, Jun Zhao, Wei Wu, Kewei Tu

AI总结:

针对Transformer长上下文处理中长度泛化差、自注意力复杂度高的问题,提出分组交叉注意力GCA,通过端到端学习的因果检索用固定注意力窗口实现长距离信息访问,可泛化至预训练长度1000倍的16M上下文,显著降低计算与内存成本。

摘要:

尽管Transformer已取得成功,但由于自注意力的长度泛化能力有限且复杂度呈二次方增长,处理长上下文仍然颇具挑战。因此,Transformer通常需要在更大的注意力窗口下进行训练后调整,这会显著提升计算与内存成本。本文提出一种基于动态上下文的新型注意力机制——分组交叉注意力(Grouped Cross Attention,GCA),它能够泛化至预训练上下文长度的1000倍,同时在注意力窗口大小恒定的情况下保留访问远距离信息的能力。对于给定的输入序列,我们将其分割为多个块,并用每个块检索前k个最相关的历史块,用于后续的文本生成。具体而言,与大多数采用现成检索器的已有工作不同,我们的核心创新在于让检索器以端到端的方式学习如何检索能更好最小化后续token自回归损失的历史块。该机制用固定大小的注意力窗口容纳检索到的块,实现长距离信息访问,大幅降低了训练与推理阶段的计算和内存成本。实验表明,基于GCA的模型在16M上下文长度的passkey检索任务中达到接近完美的准确率,该长度是训练长度的1000倍。

英文摘要:

Despite the success of Transformers, handling long contexts remains challenging due to the limited length generalization and quadratic complexity of self-attention. Thus Transformers often require post-training with a larger attention window, significantly increasing computational and memory costs. In this paper, we propose a novel attention mechanism based on dynamic context, Grouped Cross Attention (GCA), which can generalize to 1000 times the pre-training context length while maintaining the ability to access distant information with a constant attention window size. For a given input sequence, we split it into chunks and use each chunk to retrieve top-k relevant past chunks for subsequent text generation. Specifically, unlike most previous works that use an off-the-shelf retriever, our key innovation allows the retriever to learn how to retrieve past chunks that better minimize the auto-regressive loss of subsequent tokens in an end-to-end manner. Such a mechanism accommodates retrieved chunks with a fixed-size attention window to achieve long-range information access, significantly reducing computational and memory costs during training and inference. Experiments show that GCA-based models achieve near-perfect accuracy in passkey retrieval for 16M context lengths, which is 1000 times the training length.

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

↑