arXiv:2410.06205cs.CLcs.LG2024-10ICLR被引 121

揭示旋转位置编码的真正作用机制,挑战传统认知。

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

  • 通过分析训练后的模型发现,RoPE利用高频成分构建位置注意力模式。
  • 模型主要依赖低频分量传递语义信息,而非仅用于衰减远距离依赖。
  • 提出改进方案并验证其性能提升,对长序列建模有重要启发。

位置编码(PEs)是基于Transformer的大语言模型(LLMs)的关键组件,为注意力机制提供序列位置信息。目前最流行的编码方式之一是旋转位置编码(RoPE),它根据相对距离旋转查询和键。普遍观点认为,RoPE有效是因为能随相对距离增加而衰减令牌依赖关系。本文通过研究训练好的Gemma 7B模型内部机制,发现实际上模型利用最高频成分构建稳健的“位置”注意力模式。同时,模型显著偏好使用最低频成分,推测其用于携带语义信息。我们数学证明了RoPE的若干有趣行为,并通过实验验证发现,现有设计存在可改进之处。为此,我们提出一种修改版RoPE,修复关键问题并提升性能。本工作为理解大型语言模型中位置编码的作用提供了新视角,对扩展模型规模与上下文长度具有重要意义。

原文摘要 · Abstract (English)

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.

位置编码TransformerRoPE模型机制

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。