[Feature][Relax][ONNX] Support RotaryEmbedding (RoPE) operator in Relax ONNX frontend

Abierto
#20,967 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
58/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Start in python/tvm/relax/frontend/onnx/onnx_frontend.py and inspect how the Relax ONNX frontend maps operators to converters. Check the ONNX RotaryEmbedding operator specification and cover both standard ONNX and com.microsoft forms, including interleaved and partial rotation. Add converter tests for the described input layouts and attributes; done means importing these operators produces the expected output with pass-through dimensions preserved.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Feature Description

Support the ONNX RotaryEmbedding (Rotary Position Embedding / RoPE) operator in the Apache TVM Relax ONNX frontend (python/tvm/relax/frontend/onnx/onnx_frontend.py).

Motivation

Rotary Position Embedding (RoPE) has become the de facto standard positional encoding technique for modern Large Language Models (LLMs), including LLaMA (1, 2, 3), Mistral, Gemma, Qwen 2/2.5, and DeepSeek.

When exporting modern LLMs from PyTorch / Hugging Face Transformers to ONNX, attention modules frequently emit the RotaryEmbedding operator (both in standard ONNX opset 23+ and the common com.microsoft domain). Attempting to import these models into TVM Relax currently fails with:

NotImplementedError: The following operators are not supported: ['RotaryEmbedding']

Adding native converter support for RotaryEmbedding in the Relax ONNX frontend will enable direct compilation of state-of-the-art generative LLMs into Relax IR without requiring manual graph surgery or decomposition passes.

Operator Specification (ONNX Opset 23+ / com.microsoft)
  • Inputs:
    1. X: Input tensor of shape (batch_size, sequence_length, num_heads, head_size) or (batch_size, num_heads, sequence_length, head_size).
    2. pos_ids: 1D or 2D tensor specifying token position IDs for each sequence.
    3. cos_cache: Precomputed cosine frequency cache matrix.
    4. sin_cache: Precomputed sine frequency cache matrix.
  • Attributes:
    • interleaved: int (default 0) - whether real and imaginary components are interleaved (e.g. [-x2, x1, -x4, x3]) or separated along half the head dimension (e.g. [-x_half2, x_half1]).
    • num_heads: int (optional) - number of attention heads.
    • rotary_embedding_dim: int (optional) - dimension to rotate (can be smaller than head_size for partial rotary embeddings).
  • Outputs:
    1. Y: Output tensor with the same shape and dtype as X with rotary embeddings applied.
Expected Behavior

The Relax ONNX frontend should implement RotaryEmbedding by slicing the rotary dimension, rotating components according to the interleaved flag, multiplying with corresponding cos and sin tables, and concatenating any pass-through non-rotated dimensions.

Lenguaje dominante
Python
Estrellas
13.9k
Forks
4.1k
Merge medio
4 d 22 h
PR fusionados (30 d)
22

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/tvm

Todos los issues de apache/tvm

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.