Papers
Topics
Authors
Recent
Search
2000 character limit reached

Learnable Angle Matrices (ComRoPE)

Updated 16 December 2025
  • Learnable Angle Matrices (ComRoPE) are trainable skew-symmetric matrices that generalize rotary positional encodings to ensure robust relative positioning.
  • They employ axial-partition and linearly dependent parameterizations to guarantee commutativity, supporting both one- and multi-dimensional inputs.
  • ComRoPE leverages efficient block-structured Givens rotations and round-robin scheduling for scalable transformer implementations on high-resolution tasks.

Learnable Angle Matrices, or Commuting Rounds of Parallelized Elementary rotations (ComRoPE), generalize rotary positional encodings (RoPE) by parameterizing position-dependent rotations using trainable angle (skew-symmetric) matrices with strict commutativity requirements. ComRoPE is designed to address the limitations of fixed rotary mechanisms in transformer architectures, guaranteeing robustness to position offsets, scalability to high-resolution domains, and adaptability across one- and multi-dimensional structured inputs. The theoretical foundation relies on the algebra of commuting skew-symmetric generators that define families of orthogonal transformations satisfying essential properties of relative positional encoding, and supports efficient implementation via block-structured Givens rotations or round-robin decompositions. Empirical results demonstrate ComRoPE's superiority on tasks including large-scale image classification and object detection, with strict gains in both in-distribution and out-of-distribution settings (Yu et al., 4 Jun 2025).

1. Theoretical Foundations: Rotary Positional Embedding and the RoPE Equation

Rotary Positional Embedding (RoPE) integrates positional information into the attention mechanism through block-diagonal rotation matrices acting on embedding vectors. Standard RoPE operates by partitioning the embedding dimension dd into d/2d/2 independent 2×22\times2 blocks, each corresponding to a planar rotation with manually designed angle schedules:

R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)

with

Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}

The attention calculation involves rotated queries and keys q=R(pq)qq' = R(p_q)q, k=R(pk)kk' = R(p_k)k, yielding

qk=qR(pq)R(pk)k.q'^\top k' = q^\top R(p_q)^\top R(p_k) k.

A central constraint for robust, relative positional encoding is the RoPE equation: R(pq)R(pk)=R(pkpq)for all positionsR(p_q)^\top R(p_k) = R(p_k - p_q) \quad \text{for all positions} which guarantees attention only depends on relative offset, thereby ensuring shift-invariance and scalability to arbitrary input lengths or resolutions.

ComRoPE generalizes R(p)R(p) to

d/2d/20

where d/2d/21 are d/2d/22 real skew-symmetric matrices in d/2d/23, and d/2d/24 encodes position along each axis. The necessity and sufficiency theorem (Theorem 3.1, (Yu et al., 4 Jun 2025)) asserts that d/2d/25 satisfies the RoPE equation for arbitrary offsets if and only if all d/2d/26 commute: d/2d/27 for all d/2d/28. This property enables consistent relative position encoding for both 1D and multidimensional data.

2. Constructing and Parameterizing Learnable Commuting Angle Matrices

ComRoPE provides explicit parameterizations that guarantee commutativity, leading to two principal variants:

Axial-Partition (AP) Parameterization

Partition d/2d/29 into 2×22\times20 blocks of size 2×22\times21, 2×22\times22. For each axis 2×22\times23 and block 2×22\times24,

2×22\times25

where 2×22\times26 is an unconstrained trainable 2×22\times27 matrix. Then,

2×22\times28

Only one axis contributes a non-zero skew block per partition, enforcing 2×22\times29.

Linearly Dependent (LD) Parameterization

Produce a single base skew-symmetric matrix R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)0 and per-axis scalars R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)1. Form

R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)2

with R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)3 repeats per axis. Since all R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)4 are scalar multiples of a common block, they trivially commute.

Both parameterizations scale efficiently, use learnable blocks of small matrix size, and result in R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)5 or R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)6 free parameters.

3. Efficient Implementation: Givens Rotations, Round-Robin Scheduling, and GPU Utilization

ComRoPE extends the classical FFT-like or round-robin decompositions of orthogonal matrices using angle-parameterized Givens rotations (Mathieu et al., 2014, Hamze, 2021). For head dimension R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)7, a rotation matrix R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)8 is represented as

R(p)=diag(R1(p),R2(p),,Rd/2(p))SO(d)R(p) = \operatorname{diag}\bigl(R_1(p), R_2(p), \dots, R_{d/2}(p)\bigr) \in SO(d)9

Here, each Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}0 is a block-sparse matrix applying independent planar rotations (Givens) on disjoint pairs. The index-pair schedule is engineered in a "butterfly" or "round-robin" pattern for maximal parallelism; with Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}1 rotations per layer and Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}2 layers, the approach yields Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}3 total operations for forward and backward passes (Mathieu et al., 2014).

In the round-robin method (Hamze, 2021), all Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}4 Givens rotations are organized into Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}5 blocks of Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}6 non-overlapping pairs, admitting Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}7 sequential depth in forward computation and Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}8 for backpropagation, ideally suited to GPU architectures.

Common implementation steps:

  • Store and update only the angle parameters and small per-block intermediates.
  • Forward and backward passes update activations layer/block by layer/block without forming full dense matrices.
  • After each update, re-project Rj(p)=(cosθj(p)sinθj(p) sinθj(p)cosθj(p)),θj(p)=p100002j/dR_j(p) = \begin{pmatrix} \cos\theta_j(p) & -\sin\theta_j(p) \ \sin\theta_j(p) & \cos\theta_j(p) \end{pmatrix}, \quad \theta_j(p) = \frac{p}{10000^{2j/d}}9 blocks to q=R(pq)qq' = R(p_q)q0 to ensure orthogonality.
  • Runtime overhead is negligible (q=R(pq)qq' = R(p_q)q1 FLOPs per vector for q=R(pq)qq' = R(p_q)q2).

4. Integration into Transformers and Attention Mechanisms

Within transformer-based models, ComRoPE replaces fixed RoPE with dynamically learned, commuting angle-based rotations. For each token (or patch) and each axis, positional coordinates modulate the associated angle matrices:

q=R(pq)qq' = R(p_q)q3

The query/key embeddings at position q=R(pq)qq' = R(p_q)q4 are updated to q=R(pq)qq' = R(p_q)q5, q=R(pq)qq' = R(p_q)q6. Standard attention proceeds using q=R(pq)qq' = R(p_q)q7, q=R(pq)qq' = R(p_q)q8:

q=R(pq)qq' = R(p_q)q9

All rotation parameters are shared across the batch and sequence dimensions, with gradients accumulated during backpropagation. Practical instantiations initialize k=R(pk)kk' = R(p_k)k0 using FFT "twiddle" factors, RoPE sinusoids, or uniform randomization.

5. Empirical Performance and Robustness

ComRoPE's effectiveness is most evident in settings where positional robustness and extrapolation to out-of-distribution resolutions or input lengths are critical.

Classification and Detection

On ImageNet-1K using ViT-B/16, at k=R(pk)kk' = R(p_k)k1 input, ComRoPE-LD yields 65.49% top-1 accuracy (+2.4% absolute over LieRE), and at k=R(pk)kk' = R(p_k)k2 extrapolated resolution, 55.29% (+2.9% absolute) (Yu et al., 4 Jun 2025). Object detection experiments (MS COCO, ViT-S backbone) yield ComRoPE-LD at 44.7 AP, slightly outperforming LieRE at 44.5 AP, using approximately half the additional parameters.

Ablation and Stress Testing

  • ComRoPE variants display invariance to coordinate shifts, while non-commuting formulations (e.g., LieRE) degrade under uniform coordinate perturbations.
  • Optimal block size k=R(pk)kk' = R(p_k)k3 balances performance and computational cost, peaking near k=R(pk)kk' = R(p_k)k4.
  • Robustness to training-time position perturbation is intrinsic in ComRoPE; gains from artificial perturbation are minimal compared to vulnerable baselines (APE +19.5% vs. ComRoPE-LD +2.9%).

6. Generalization Properties and Relation to Prior Work

ComRoPE formally subsumes both absolute and rotary positional encoding as special cases:

  • If all k=R(pk)kk' = R(p_k)k5, the mechanism reduces to absolute position encoding.
  • With k=R(pk)kk' = R(p_k)k6 and fixed k=R(pk)kk' = R(p_k)k7 skew-symmetric blocks, standard RoPE is recovered. Thus, ComRoPE constitutes a strict superset of previous rotary-based encodings (Yu et al., 4 Jun 2025).

Expressivity is governed by parameter count and block size; larger blocks allow richer, higher-dimensional transformations at increased computational overhead.

7. Future Directions and Open Problems

Key avenues for future research highlighted include:

  • Developing optimized routines for small-matrix exponentiation (exact closed-form, lookup tables) to minimize computational cost for block sizes k=R(pk)kk' = R(p_k)k8.
  • Investigating weaker commutativity constraints that may permit a wider space of trainable angle matrices.
  • Extending the approach to more general structured data (multi-dimensional grids, point clouds, videos) and scaling to LLMs where efficient exponentiation is paramount.

A plausible implication is that such directions may enhance generalization, facilitate efficient fine-tuning for new modalities, and support architectures requiring relative encoding over long spatial-temporal contexts.


Summary Table: ComRoPE Parameterizations

Variant Structure Parameters (per block)
AP One axis per block k=R(pk)kk' = R(p_k)k9
LD Shared skew matrix qk=qR(pq)R(pk)k.q'^\top k' = q^\top R(p_q)^\top R(p_k) k.0

ComRoPE establishes a mathematically principled, scalable, and empirically robust foundation for learnable rotary embeddings in transformer models, unifying previous positional encoding strategies and advancing state-of-the-art accuracy and generalization (Yu et al., 4 Jun 2025, Hamze, 2021, Mathieu et al., 2014).

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 Learnable Angle Matrices (ComRoPE).