揭示旋转位置编码如何导致注意力中的斜线模式
Demystifying the Slash Pattern in Attention: The Role of RoPE
- 通过分析查询、键和旋转位置编码,发现斜线模式源于其特定组合
- 当查询键近似秩一且旋转编码主导中高频成分时,产生斜线注意力
- 理论证明梯度下降训练的浅层Transformer会自然出现该模式
大型语言模型常表现出斜线注意力模式,即注意力分数集中在某个偏移量Δ的次对角线上。这类模式对跨标记信息传递至关重要。本文从实证与理论双重视角揭示此类斜线主导头(SDHs)的成因。通过对开源LLM的分析,发现SDHs是模型内在特性,且可泛化至分布外提示。我们进一步分析查询、键与旋转位置编码(RoPE)的协同作用,发现两个关键特征:(1) 查询与键几乎为秩一矩阵;(2) RoPE主要由中高频率成分主导。在此条件下,不同标记间的查询键几乎相同,而中高频罗佩成分间的交互诱发了斜线模式。理论上,我们形式化这些条件作为建模假设,并证明在满足条件下,采用梯度下降训练的浅层Transformer必然产生SDHs,且该模式具有分布外泛化能力。
原文摘要 · Abstract (English)
Large Language Models (LLMs) often exhibit slash attention patterns, where attention scores concentrate along the $Δ$-th sub-diagonal for some offset $Δ$. These patterns play a key role in passing information across tokens. But why do they emerge? In this paper, we demystify the emergence of these Slash-Dominant Heads (SDHs) from both empirical and theoretical perspectives. First, by analyzing open-source LLMs, we find that SDHs are intrinsic to models and generalize to out-of-distribution prompts. To explain the intrinsic emergence, we analyze the queries, keys, and Rotary Position Embedding (RoPE), which jointly determine attention scores. Our empirical analysis reveals two characteristic conditions of SDHs: (1) Queries and keys are almost rank-one, and (2) RoPE is dominated by medium- and high-frequency components. Under these conditions, queries and keys are nearly identical across tokens, and interactions between medium- and high-frequency components of RoPE give rise to SDHs. Beyond empirical evidence, we theoretically show that these conditions are sufficient to ensure the emergence of SDHs by formalizing them as our modeling assumptions. Particularly, we analyze the training dynamics of a shallow Transformer equipped with RoPE under these conditions, and prove that models trained via gradient descent exhibit SDHs. The SDHs generalize to out-of-distribution prompts.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。