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

Landmark Attention:用于Transformers的随机访问无限上下文长度

Landmark Attention: Random-Access Infinite Context Length for Transformers

EPFL(洛桑联邦理工学院)

Amirkeivan Mohtashami, Martin Jaggi

AI总结:

提出Landmark Attention方法,通过landmark token表示输入块并直接利用注意力机制检索相关块,在保留随机访问灵活性的同时支持无限上下文长度,微调LLaMA 7B将上下文扩展至32k tokens。

摘要:

尽管Transformers在自然语言处理中取得了显著成功,但其注意力机制的大内存需求限制了其处理更长上下文的能力。先前的方法,如循环记忆或基于检索的增强,要么损害了注意力的随机访问灵活性(即在整个上下文中选择任意token的能力),要么依赖独立机制检索相关上下文,这可能无法与模型的注意力兼容。本文提出了一种新颖方法,允许访问完整上下文同时保留随机访问灵活性,非常接近在整个上下文上运行注意力。我们的方法使用一个landmark token表示输入的每个块,并训练注意力利用它选择相关块,从而直接通过注意力机制检索块,而非依赖独立机制。该方法与专用数据结构和系统内存层次结构无缝集成,能够处理任意长度的上下文。我们证明,该方法可获得与Transformer-XL相当的性能,同时显著减少每步检索的token数量。最后,我们展示了使用该方法对LLaMA 7B进行微调,成功将其上下文长度容量扩展到超过32k个token,允许在GPT-4的上下文长度下进行推理。我们在https://github.com/epfml/landmark-attention/发布了landmark attention的实现及复现实验的代码。

英文摘要:

While Transformers have shown remarkable success in natural language processing, their attention mechanism's large memory requirements have limited their ability to handle longer contexts. Prior approaches, such as recurrent memory or retrieval-based augmentation, have either compromised the random-access flexibility of attention (i.e., the capability to select any token in the entire context) or relied on separate mechanisms for relevant context retrieval, which may not be compatible with the model's attention. In this paper, we present a novel approach that allows access to the complete context while retaining random-access flexibility, closely resembling running attention on the entire context. Our method uses a landmark token to represent each block of the input and trains the attention to use it for selecting relevant blocks, enabling retrieval of blocks directly through the attention mechanism instead of by relying on a separate mechanism. Our approach seamlessly integrates with specialized data structures and the system's memory hierarchy, enabling processing of arbitrarily long context lengths. We demonstrate that our method can obtain comparable performance with Transformer-XL while significantly reducing the number of retrieved tokens in each step. Finally, we show that fine-tuning LLaMA 7B with our method successfully extends its context length capacity to over 32k tokens, allowing for inference at the context lengths of GPT-4. We release the implementation of landmark attention and the code to reproduce our experiments at https://github.com/epfml/landmark-attention/.

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

↑