Home RoPE + YARN
Post
Cancel

RoPE + YARN

1. RoPE(旋转位置编码)

将二维向量 $(x_1, x_2)$ 绕原点旋转 $\theta$ 角度,用矩阵乘法表示如下:

\[\begin{pmatrix} x_1' \\ x_2' \end{pmatrix} = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix} \begin{pmatrix} x_1 \\ x_2 \end{pmatrix}\]

令 $M(\theta)$ 表示旋转矩阵

\[M(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}\]

对于RoPE,做的事就是在位置为 $m$ 的输入向量 $x\in\mathcal{R}^{D}$ 上,每两两元素(2维向量 $\times \frac{D}{2}$ 个),根据当前位置 $m$ 和2维向量所在位置 $i$ 实施 $m\theta_i$ 角度的旋转。可表示如下:

\[\]
This post is licensed under CC BY 4.0 by the author.

秋招记录-胡言乱语

-