Papers
Topics
Authors
Recent
Search
2000 character limit reached

ComRoPE: Scalable Rotary Position Encoding

Updated 9 November 2025
  • ComRoPE is a framework for trainable positional encoding in Transformers that replaces fixed rotations with learnable, commuting skew-symmetric matrices.
  • It preserves relative offset invariance by enforcing the commutativity of rotation generators, ensuring robust performance across sequential and multidimensional data.
  • Empirical results demonstrate that variants like ComRoPE-LD outperform traditional methods, achieving higher accuracy and enhanced robustness in diverse applications.

ComRoPE (Commuting Rotary Position Embedding) is a framework for positional encoding in Transformers that generalizes Rotary Positional Encoding (RoPE) by replacing fixed, hand-designed rotations with trainable, higher-dimensional rotations represented by commuting skew-symmetric matrices. This approach creates a scalable, robust, and theoretically principled method for embedding positional information in models handling sequential, spatial, or general multidimensional data. ComRoPE preserves the crucial “relative offset” property underpinning RoPE’s robustness, while enabling greater expressiveness and improved empirical performance in high-dimensional contexts.

1. Motivation and Limitations of Prior Methods

Absolute Positional Encoding (APE), such as sinusoidal encoding, is fixed after initialization and cannot be adapted during training. APE's fixed spectrum prevents generalization to longer or shifted input sequences and does not support learning of positional frequency content. Standard RoPE, as introduced in RoFormer, encodes positional information by applying a 2D rotation R(θ)R(\theta) to each (typically 2-dimensional) slice of the query/key. Here, θ\theta is a deterministic function of the position index. The corresponding rotation matrix is

R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}

This method is efficient and robust to absolute position offsets, but it is fundamentally limited by:

  • The use of 2D rotations (low expressivity in higher dimensions),
  • Manually fixed, non-trainable angles,
  • Restricted ability to extend to general rotation groups without losing offset-robustness.

The motivation for ComRoPE is to devise a parameterization of RoPE that is i) fully trainable, ii) robust to input offsets (shift-invariance), and iii) scalable to higher-dimensional embeddings.

2. Formalization: The RoPE Equation

ComRoPE is grounded in a formal definition of rotary positional encoding. Let f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d insert position x∈RN\mathbf{x} \in \mathbb{R}^N into query vector q∈Rd\mathbf{q} \in \mathbb{R}^d, and ρ(q,k)=q⊤k\rho(\mathbf{q},\mathbf{k}) = \mathbf{q}^\top \mathbf{k} be the standard dot-product similarity. The model requires a matrix-valued function Rf:RN→Rd×d\mathbf{R}_f : \mathbb{R}^N \to \mathbb{R}^{d\times d} such that:

  1. f(q,x)=Rf(x)qf(\mathbf{q},\mathbf{x}) = \mathbf{R}_f(\mathbf{x})\mathbf{q},
  2. ρ(q,k)=q⊤k\rho(\mathbf{q},\mathbf{k}) = \mathbf{q}^\top\mathbf{k},
  3. θ\theta0 captures the relative-positional similarity.

For RoPE to provide offset-invariant attention, the following “RoPE Equation” must hold (Proposition 2.1): θ\theta1 This guarantees that relative attention depends only on positional differences, not on absolute positions.

3. The Commutativity Constraint

ComRoPE parameterizes θ\theta2 using θ\theta3 skew-symmetric matrices θ\theta4: θ\theta5 The central result (Theorem 3.1) establishes that the RoPE Equation holds for all θ\theta6 if and only if all θ\theta7 pairwise commute: θ\theta8 This requirement is both necessary and sufficient. Commuting generators ensure exact offset-robustness because the matrix exponential exactly factorizes without higher-order cross-terms.

4. Parameterizations: Trainable Commuting Angle Matrices

Two distinct parameterizations are proposed to enforce the commutativity of skew-symmetric matrices:

4.1 Axial-Partition (ComRoPE-AP)

  • The embedding dimension θ\theta9 is divided into R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}0 blocks of size R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}1 (R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}2).
  • Each block R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}3 with R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}4 is associated with a trainable R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}5.
  • For each axis R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}6, the R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}7 are block-diagonal: R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}8 Each R(θ)=(cos⁡θ−sin⁡θ sin⁡θcos⁡θ)R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \ \sin\theta & \cos\theta \end{pmatrix}9 has at most one nonzero skew-symmetric block per position. All f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d0 are block-diagonal and commute.

4.2 Linearly-Dependent (ComRoPE-LD)

  • Learn a single base skew-symmetric f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d1 and, for each axis f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d2, a scalar f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d3.
  • Set f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d4. Since all f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d5 are scalar multiples of f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d6, they trivially commute.

Both constructions solve the RoPE Equation and guarantee offset-robustness.

5. Theoretical Foundations

Supporting lemmas demonstrate that for f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d7,

f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d8

This generalizes to any set f:Rd×RN→Rdf: \mathbb{R}^d \times \mathbb{R}^N \to \mathbb{R}^d9. Therefore, any collection of pairwise commuting skew-symmetric matrices produces a position-dependent transformation x∈RN\mathbf{x} \in \mathbb{R}^N0 that meets the RoPE Equation. The standard RoPE is a special case where all x∈RN\mathbf{x} \in \mathbb{R}^N1 are x∈RN\mathbf{x} \in \mathbb{R}^N2 blocks with hand-designed x∈RN\mathbf{x} \in \mathbb{R}^N3.

The theoretical framework further justifies that if x∈RN\mathbf{x} \in \mathbb{R}^N4 for all x∈RN\mathbf{x} \in \mathbb{R}^N5, attention reduces to unrotated, standard dot-product attention, and if x∈RN\mathbf{x} \in \mathbb{R}^N6 and x∈RN\mathbf{x} \in \mathbb{R}^N7 is fixed to the standard rotation generator, vanilla RoPE is recovered.

6. Empirical Performance

ComRoPE was evaluated on various benchmarks:

Method 2D Class. @224 (ImageNet-1K, ViT-B/16) 2D Class. @512 MS COCO Object Detection (ViT-S) 3D Classification (UCF-101)
APE ∼58.8% N/A AP = 44.0 Improved robustness
Vanilla RoPE ∼63.1% N/A N/A Improved robustness
LieRE 64.4% 61.2% AP = 44.5 Improved robustness
ComRoPE-AP 65.3% N/A N/A Improved robustness
ComRoPE-LD 65.5% 62.6% AP = 44.7 (+0.2) Improved robustness
  • ComRoPE-LD surpasses LieRE by 1.6% at training resolution and by 2.9% at higher resolution.
  • For object detection (MS COCO), ComRoPE-LD yields +0.2 AP over LieRE.
  • For 3D classification (UCF-101), ComRoPE variants maintain improved robustness under varying resolution.

These results establish that ComRoPE’s learnable, commuting-rotation approach produces consistent accuracy gains and stabilization as input resolution increases.

7. Generalization, Practical Recommendations, and Resources

ComRoPE unifies multiple positional encoding schemes:

  • If all x∈RN\mathbf{x} \in \mathbb{R}^N8, recovers standard dot-product attention.
  • Setting block size to 2 and x∈RN\mathbf{x} \in \mathbb{R}^N9 as the canonical generator recovers original RoPE.
  • Allows richer, learnable feature rotations in higher dimensions, which are optimized via backpropagation.

Practical implementation considerations include:

  • For images, positional coordinates are best represented in relative, normalized scale.
  • Centering patch coordinates and introducing synthetic perturbations at training further enhance robustness.
  • Block size q∈Rd\mathbf{q} \in \mathbb{R}^d0 balances rotation expressiveness and computational cost; empirical evidence suggests q∈Rd\mathbf{q} \in \mathbb{R}^d1 is effective.
  • An open-source reference implementation is available at https://github.com/Longin-Yu/ComRoPE.

ComRoPE offers a scalable, flexible, and rigorously justified method for positional encoding in Transformers, particularly beneficial for contexts requiring high-dimensional, trainable, and offset-robust representations.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to ComRoPE.