Formula

Element-wise Formula for RoPE Rotation

The Rotary Positional Embedding (RoPE) transformation can be expressed as an element-wise operation on a d-dimensional vector x\mathbf{x}. This formulation calculates the rotated vector, Ro(x,tθ)\mathrm{Ro}(\mathbf{x}, t\theta), by summing two vectors derived from Hadamard products (element-wise multiplication). The first vector is the product of the input vector x\mathbf{x} and a cosine vector. The second is the product of a permuted input vector ([x2,x1,,xd,xd1][-x_2, x_1, \dots, -x_d, x_{d-1}]) and a sine vector. The complete formula is: Ro(x,tθ)=(x1x2xd1xd)(costθ1costθ1costθd/2costθd/2)+(x2x1xdxd1)(sintθ1sintθ1sintθd/2sintθd/2)\mathrm{Ro}(\mathbf{x}, t\theta) = \begin{pmatrix} x_1 \\ x_2 \\ \vdots \\ x_{d-1} \\ x_d \end{pmatrix} \odot \begin{pmatrix} \cos t\theta_1 \\ \cos t\theta_1 \\ \vdots \\ \cos t\theta_{d/2} \\ \cos t\theta_{d/2} \end{pmatrix} + \begin{pmatrix} -x_2 \\ x_1 \\ \vdots \\ -x_d \\ x_{d-1} \end{pmatrix} \odot \begin{pmatrix} \sin t\theta_1 \\ \sin t\theta_1 \\ \vdots \\ \sin t\theta_{d/2} \\ \sin t\theta_{d/2} \end{pmatrix} where \odot denotes the Hadamard product.

Image 0

0

1

Updated 2026-05-02

Contributors are:

Who are from:

Tags

Ch.3 Prompting - Foundations of Large Language Models

Foundations of Large Language Models

Foundations of Large Language Models Course

Computing Sciences

Ch.2 Generative Models - Foundations of Large Language Models

Related
Learn After