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

Đang mở
#20,967 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
58/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, machine-learning

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
13.9k
Fork
4.1k
Merge trung bình
4 ngày 22 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/tvm

Tất cả issue của apache/tvm

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.