Skip to content

[Relax][ONNX] Add image.resize3d op and wire 5D Resize#18931

Merged
tlopex merged 2 commits into
apache:mainfrom
Dayuxiaoshui:main
Mar 26, 2026
Merged

[Relax][ONNX] Add image.resize3d op and wire 5D Resize#18931
tlopex merged 2 commits into
apache:mainfrom
Dayuxiaoshui:main

Conversation

@Dayuxiaoshui

Copy link
Copy Markdown
Contributor

Summary

  • Add Relax image.resize3d end-to-end: attrs, C++ op registration/inference, Python API, and legalization to topi.image.resize3d.
  • Update ONNX 5D Resize to emit relax.image.resize3d instead of direct emit_te(topi.image.resize3d).
  • Reuse the existing resize2d implementation pattern, which let us move faster while keeping behavior consistent and risk low.
  • Add tests for op inference, TVMScript parser, legalization, ONNX import, and resize3d negative/error cases.

Test Plan

  • python3 -m pytest -q tests/python/relax/test_op_image.py -k 'resize3d'
  • python3 -m pytest -q tests/python/relax/test_transform_legalize_ops_image.py -k 'resize3d'
  • python3 -m pytest -q tests/python/relax/test_tvmscript_parser_op_image.py -k 'resize3d'
  • python3 -m pytest -q tests/python/relax/test_frontend_onnx.py -k 'resize_nd_sizes or resize_5d_emits_relax_resize3d'

Add Relax image.resize3d end-to-end (attrs, C++ registration, Python API, and legalization to TOPI), then route ONNX 5D Resize through the new Relax op instead of direct emit_te. Expand tests across op inference, parser, legalization, ONNX import, and resize3d negative cases to lock behavior and reduce review risk.
@gemini-code-assist

Copy link
Copy Markdown
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 significantly enhances the image processing capabilities within Relax by introducing a new resize3d operator. This addition enables 3D image scaling, crucial for applications involving volumetric data. The integration with the ONNX frontend ensures that 5D Resize operations from ONNX models are correctly mapped to this new Relax operator, providing a more robust and native handling of such transformations. The implementation follows established patterns and is thoroughly tested to ensure correctness and stability.

Highlights

  • New Operator: Introduced the relax.image.resize3d operator with full end-to-end support, including attributes, C++ registration, Python API, and legalization.
  • ONNX Integration: Updated the ONNX 5D Resize operator to directly emit relax.image.resize3d, streamlining the import process.
  • Consistent Implementation: Leveraged the existing resize2d implementation pattern to ensure consistency and reduce development risk.
  • Comprehensive Testing: Added extensive tests covering operator inference, TVMScript parsing, legalization, ONNX import, and various error conditions for resize3d.

🧠 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.

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.

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.

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

Copy link
Copy Markdown
Contributor

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 introduces a new resize3d operator to the TVM Relax framework, extending image processing capabilities to 3D tensors. The changes involve defining new attributes for the resize3d operation, implementing its Python frontend and C++ backend, including operator registration, type inference, and layout inference. The ONNX frontend is updated to utilize this new operator for 5D tensor resizing, and comprehensive test cases have been added to validate its functionality and integration. A critical issue was identified in the resize3d C++ implementation where the argument count validation is incorrect, potentially leading to a crash due to out-of-bounds access if only one argument is passed, which also suggests a similar bug in the resize2d implementation.

Comment thread src/relax/op/image/resize.cc Outdated
@Dayuxiaoshui

Copy link
Copy Markdown
Contributor Author

@tlopex Because there was a reference, the task was completed quickly. Next, I hope to take on the PyTorch fixes, but before that, I need to wait for this PR to be reviewed.

Comment thread src/relax/op/image/resize.cc Outdated

@tlopex tlopex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks good to me, could you correct the point that gemini suggested?

InferStructInfo previously allowed one argument due to a flawed size check, which could lead to out-of-bounds access on args[1]. Align checks with set_num_inputs(2) for both resize2d and resize3d.
@Dayuxiaoshui

Copy link
Copy Markdown
Contributor Author

@tlopex We have resolved the issue and are awaiting approval.

@tlopex tlopex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now it looks good. Thank you @Dayuxiaoshui

@tlopex tlopex merged commit 4d36a45 into apache:main Mar 26, 2026
9 checks passed
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.

2 participants