cs.LGApr 10, 2026

Efficient Matrix Implementation for Rotary Position Embedding

Authors: Chen Minqi, Zhongqi Yue, Shihao Zhang, Yun Xu, Peng Wu, kaixiang Xu, Zeyi Huang, Hanwang Zhang

Organizations: Huawei Technologies · Nanyang Technological University

Abstract

Rotary Position Embedding (RoPE) has become a core component of modern Transformer architectures across language, vision, and 3D domains. However, existing implementations rely on vector-level split and merge operations that introduce non-negligible computational overhead, often overlooked in attention optimization. The problem is further amplified in multi-dimensional settings (e.g., 2D and 3D RoPE), where additional vector operations and uneven feature partitions degrade hardware utilization. To overcome these limitations, we propose RoME (Rotary Matrix position Embedding), a mathematically equivalent yet computationally efficient reformulation of RoPE that replaces vector operations with unified matrix transformations. RoME eliminates dimension-specific operations, simplifies implementation, and enables fused parallel execution across Cube and Vector units on modern NPUs. Experiments show that RoME delivers substantial acceleration at both the operator and full-model levels. The implementation is available at https://gitcode.com/cann/ops-transformer/blob/master/experimental/posembedding/rope_matrix/README.md.

Figures & tables

Explore similar work

CardsList
  1. Higher-Dimensional Rotary Position Embedding

    Aug 30, 2026Yixing Li, Ruobing Xie, Yudong Zhang +3Rotary Positional EmbeddingsTransformer Attention

  2. nD-RoPE: A Generalized RoPE for n-Dimensional Position Embedding

    Jun 10, 2026Boyang Li, Yulin Wu, Sizhe Xu +5Rotary Positional EmbeddingsPositional Encoding

  3. Fractional Rotation, Full Potential? Investigating Performance and Convergence of Partial RoPE

    Mar 12, 2026Mohammad Aflah Khan, Krishna P. Gummadi, Manish Gupta +1Rotary Positional EmbeddingsPositional Encoding