Skip to content

[Relax][ONNX] Support dynamic repeats for Tile#18878

Merged
tlopex merged 2 commits intoapache:mainfrom
LudovicoYIN:fix/onnx-tile-dynamic-repeats
Mar 6, 2026
Merged

[Relax][ONNX] Support dynamic repeats for Tile#18878
tlopex merged 2 commits intoapache:mainfrom
LudovicoYIN:fix/onnx-tile-dynamic-repeats

Conversation

@LudovicoYIN
Copy link
Contributor

@LudovicoYIN LudovicoYIN commented Mar 6, 2026

Summary

Support dynamic repeats for ONNX Tile in the Relax frontend.

Changes

  • add a dynamic Tile conversion path for ONNX when repeats is a graph input
  • expose topi.dyn_tile to the Python/packed TOPI interface
  • add frontend tests for dynamic repeats

Validation

  • tests/python/relax/test_frontend_onnx.py -k test_tile_dynamic_repeats -q
  • local end-to-end repro matches ONNX Runtime

Issue

Fixes #18752

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Relax frontend's ONNX support by enabling the Tile operator to handle dynamic repeats values. Previously, repeats had to be a constant, limiting the flexibility of models. The changes introduce a new conversion path that dynamically computes the output shape and utilizes a new topi.dyn_tile primitive, significantly improving the compatibility with ONNX models that use dynamic tiling patterns.

Highlights

  • Dynamic Repeats for ONNX Tile: Implemented support for dynamic repeats in the ONNX Tile operator within the Relax frontend, allowing the repeats input to be a graph input rather than a constant.
  • TOPI Integration: Exposed a new topi.dyn_tile function to the Python and packed TOPI interface to handle dynamic tiling operations.
  • Frontend Tests: Added new frontend tests to validate the correct behavior of dynamic repeats for the ONNX Tile operator.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/tvm/relax/frontend/onnx/onnx_frontend.py
    • Added a new static method _tensor_length to extract the length of a tensor's first dimension if it's a constant integer.
    • Modified the Tile._impl_v13 method to handle dynamic reps inputs by calculating the output shape dynamically and emitting a call to topi.dyn_tile.
  • python/tvm/topi/transform.py
    • Introduced a new Python function dyn_tile which serves as a wrapper for the C++ cpp.dyn_tile function, enabling dynamic tiling with a specified output shape and repeat dimension.
  • src/topi/transform.cc
    • Registered the topi.dyn_tile function to the TVM FFI, allowing it to be called from Python with tensor, shape, and integer arguments.
  • tests/python/relax/test_frontend_onnx.py
    • Added a new test case test_tile_dynamic_repeats to verify the functionality of the ONNX Tile operator with dynamic repeats for both static and dynamic input shapes.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for dynamic repeats in the ONNX Tile operator frontend for Relax, introducing a new dynamic conversion path in onnx_frontend.py and exposing topi.dyn_tile. A critical security vulnerability has been identified where the ONNX frontend lacks validation of input tensor ranks and shapes, potentially leading to a Denial of Service (DoS) attack via resource exhaustion from malicious ONNX models. Furthermore, there's a potential issue in how the input tensor's shape is retrieved for certain dynamic shapes, and the test suite should be expanded to cover more edge cases, especially concerning rank differences between input and repeats tensors.

Comment on lines +2004 to +2005
data_shape = list(data.struct_info.shape.values)
data_shape_tensor = bb.normalize(relax.op.shape_to_tensor(relax.ShapeExpr(data_shape)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation to get the shape of the input tensor data relies on data.struct_info.shape being a ShapeExpr. However, data.struct_info.shape can be None if the shape is not fully known (e.g., when only ndim is available), which would cause an AttributeError. A more robust and idiomatic way to get the shape of a tensor as a new tensor is to use relax.op.shape_of(data). This simplifies the code and correctly handles cases where shape information is not statically available as a ShapeExpr.

Suggested change
data_shape = list(data.struct_info.shape.values)
data_shape_tensor = bb.normalize(relax.op.shape_to_tensor(relax.ShapeExpr(data_shape)))
data_shape_tensor = bb.normalize(relax.op.shape_of(data))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the implementation to use relax.op.shape_of(data) followed by shape_to_tensor, instead of assuming data.struct_info.shape is always a ShapeExpr. This makes the dynamic Tile path more robust when only runtime shape information is available.

Copy link
Member

@tlopex tlopex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks

@tlopex tlopex merged commit 14e41c6 into apache:main Mar 6, 2026
12 checks passed
@LudovicoYIN
Copy link
Contributor Author

@tlopex thanks your review.

@LudovicoYIN LudovicoYIN deleted the fix/onnx-tile-dynamic-repeats branch March 6, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Frontend][ONNX] Tile operator incorrectly requires 'repeats' to be a constant tensor

2 participants