[Relax][ONNX] Support dynamic repeats for Tile#18878
Conversation
Summary of ChangesHello, 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 Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| data_shape = list(data.struct_info.shape.values) | ||
| data_shape_tensor = bb.normalize(relax.op.shape_to_tensor(relax.ShapeExpr(data_shape))) |
There was a problem hiding this comment.
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.
| 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)) |
There was a problem hiding this comment.
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.
|
@tlopex thanks your review. |
Summary
Support dynamic
repeatsfor ONNX Tile in the Relax frontend.Changes
repeatsis a graph inputtopi.dyn_tileto the Python/packed TOPI interfacerepeatsValidation
tests/python/relax/test_frontend_onnx.py -k test_tile_dynamic_repeats -qIssue
Fixes #18752