arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2309.08646cs.LGcs.AIcs.CL
收藏

CoCA:在 Transformers 中融合位置嵌入与共线约束注意力以扩展长上下文窗口

CoCA: Fusing Position Embedding with Collinear Constrained Attention in Transformers for Long Context Window Extending

Ant Group(蚂蚁集团)

Shiyi Zhu, Jing Ye, Wei Jiang, Siqiao Xue, Qi Zhang, Yifan Wu, Jianguo Li

AI总结:

本文提出 CoCA 共线约束注意力,通过在 $Q$、$K$ 间加入共线约束融合 RoPE 与自注意力,以低成本实现超长上下文外推,并在 GPT 与 LLaMA-7B 上验证可达 32K。

摘要:

自注意力和位置嵌入是基于 transformer 的大语言模型(LLM)中的两个关键模块。然而,二者之间的潜在关系仍远未得到充分研究,尤其是在长上下文窗口扩展方面。事实上,我们的工作揭示,Rotary Position Embedding(RoPE,旋转位置嵌入)与普通自注意力之间存在损害长上下文外推的异常行为。为解决这一问题,我们提出了一种新型注意力机制 CoCA(Collinear Constrained Attention,共线约束注意力)。具体而言,我们在 $Q$ 与 $K$ 之间施加共线约束,以无缝整合 RoPE 和自注意力。该集成仅增加极小的计算与空间复杂度,却显著增强了长上下文窗口外推能力。我们提供了优化实现,使其可作为任何现有基于 transformer 的模型的即插即用替代方案。大量实验表明,CoCA 在扩展上下文窗口方面表现极其出色。一个基于 CoCA 的 GPT 模型在上下文长度为 512 的条件下训练后,无需任何微调即可将上下文窗口无缝扩展至 32K(60倍)。此外,通过将 CoCA 直接用于 LLaMA-7B,我们仅在 2K 训练长度下就实现了最高 32K 的外推。我们的代码已公开发布于:https://github.com/codefuse-ai/Collinear-Constrained-Attention

英文摘要:

Self-attention and position embedding are two key modules in transformer-based Large Language Models (LLMs). However, the potential relationship between them is far from well studied, especially for long context window extending. In fact, anomalous behaviors harming long context extrapolation exist between Rotary Position Embedding (RoPE) and vanilla self-attention unveiled by our work. To address this issue, we propose a novel attention mechanism, CoCA (Collinear Constrained Attention). Specifically, we enforce a collinear constraint between $Q$ and $K$ to seamlessly integrate RoPE and self-attention. While only adding minimal computational and spatial complexity, this integration significantly enhances long context window extrapolation ability. We provide an optimized implementation, making it a drop-in replacement for any existing transformer-based models. Extensive experiments show that CoCA performs extraordinarily well in extending context windows. A CoCA-based GPT model, trained with a context length of 512, can seamlessly extend the context window up to 32K (60$\times$), without any fine-tuning. Additionally, by dropping CoCA in LLaMA-7B, we achieve extrapolation up to 32K within only 2K training length. Our code is publicly available at: https://github.com/codefuse-ai/Collinear-Constrained-Attention

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

↑