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

转了一圈又一圈!是什么让旋转位置编码如此有用?

Round and Round We Go! What makes Rotary Positional Encodings useful?

University of Oxford(牛津大学);Google DeepMind(谷歌DeepMind)

Federico Barbero, Alex Vitvitskyi, Christos Perivolaropoulos, Razvan Pascanu, Petar Veličković

AI总结:

本文通过分析 Gemma 7B 内部机制并结合数学证明,揭示 RoPE 主要利用高频形成位置注意力、低频承载语义,进而提出改进 RoPE 以修复问题并提升性能。

摘要:

位置编码(PEs)是基于 Transformer 的大语言模型(LLMs)的关键组成部分,为注意力机制提供重要的序列位置信息。当前 LLMs 中最常用的编码类型之一是旋转位置编码(RoPE),它根据查询和键的相对距离对其进行旋转。一种普遍看法认为,RoPE 之所以有用,是因为它有助于随着相对距离增加而衰减 token 依赖。在本研究中,我们认为这不太可能是核心原因。我们研究了一个经过训练的 Gemma 7B 模型的内部机制,以理解 RoPE 在机械层面上是如何被使用的。我们发现,Gemma 学会利用 RoPE 的最高频率来构建稳健的“位置”注意力模式。我们还发现,总体而言,Gemma 非常倾向于使用 RoPE 的最低频率,我们怀疑这些频率被用于承载语义信息。我们从数学上证明了 RoPE 的一些有趣行为,并开展实验验证我们的发现,同时提出了一种 RoPE 修改方案,可修复所揭示的部分问题并提升性能。我们认为,这项工作是更好地理解 LLMs 中 PEs 的有趣一步,而这对于将 LLMs 扩展到更大规模和更长上下文长度具有关键价值。

英文摘要:

Positional Encodings (PEs) are a critical component of Transformer-based Large Language Models (LLMs), providing the attention mechanism with important sequence-position information. One of the most popular types of encoding used today in LLMs are Rotary Positional Encodings (RoPE), that rotate the queries and keys based on their relative distance. A common belief is that RoPE is useful because it helps to decay token dependency as relative distance increases. In this work, we argue that this is unlikely to be the core reason. We study the internals of a trained Gemma 7B model to understand how RoPE is being used at a mechanical level. We find that Gemma learns to use RoPE to construct robust "positional" attention patterns by exploiting the highest frequencies. We also find that, in general, Gemma greatly prefers to use the lowest frequencies of RoPE, which we suspect are used to carry semantic information. We mathematically prove interesting behaviours of RoPE and conduct experiments to verify our findings, proposing a modification of RoPE that fixes some highlighted issues and improves performance. We believe that this work represents an interesting step in better understanding PEs in LLMs, which we believe holds crucial value for scaling LLMs to large sizes and context lengths.

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

↑