arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2604.09742cs.LGcs.CV
收藏

旋转位置嵌入的高效矩阵实现

Efficient Matrix Implementation for Rotary Position Embedding

Huawei Technologies(华为技术有限公司);Nanyang Technological University(南洋理工大学)

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

AI总结:

本文提出RoME,通过矩阵变换替代向量操作,提升旋转位置嵌入的计算效率,实现跨Cube和Vector单元的并行执行。

摘要:

旋转位置嵌入(RoPE)已成为现代Transformer架构的核心组件。然而,现有实现依赖向量级拆分和合并操作,导致显著的计算开销。本文提出RoME,通过数学等效的矩阵变换替代向量操作,简化实现并提升硬件利用率。实验表明,RoME在操作和完整模型层面均实现了显著加速。实现细节见https://gitcode.com/cann/ops-transformer/blob/master/experimental/posembedding/rope_matrix/README.md。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑