Skip to content

Conversation

@guan404ming
Copy link
Member

Why

The ONNX Unique operator supports four optional outputs (unique values, indices, inverse_indices, and counts), but the TVM ONNX frontend only returned the unique values output.

How

  • Updated Unique._impl_v11 to check the number of expected outputs via attr["tvm_custom"]["num_outputs"]
  • Pass return_index, return_inverse, and return_counts parameters to relax.op.unique
  • Return a relax.Tuple containing all requested outputs

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @guan404ming, 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 TVM Relax ONNX frontend by extending its support for the ONNX Unique operator. Previously, only the primary unique values output was handled, limiting the utility of the operator within TVM. With these changes, the frontend can now correctly parse and generate Relax expressions for all optional outputs of the Unique operator, including indices, inverse indices, and counts. This improvement allows for more complete and accurate ONNX model conversions involving the Unique operation, enabling broader compatibility and functionality within the TVM ecosystem.

Highlights

  • Expanded ONNX Unique Operator Support: The TVM ONNX frontend now fully supports all four optional outputs of the ONNX Unique operator: unique values, indices, inverse indices, and counts.
  • Dynamic Output Generation: The Unique._impl_v11 converter has been updated to dynamically determine and generate the requested optional outputs based on the num_outputs custom attribute.
  • Unified Output Handling: The converter now returns a relax.Tuple containing all requested outputs, ensuring proper type and shape inference for each.
  • Comprehensive Testing: New test cases have been added to test_frontend_onnx.py to validate the correct handling of Unique with varying numbers of optional outputs (1 to 4), including different axis and sorted parameters.

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

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 the optional outputs of the ONNX Unique operator. The implementation correctly handles passing the flags to relax.op.unique and constructing a tuple of outputs. However, I've identified a critical correctness issue regarding the shapes of the indices and counts outputs when an axis is specified. According to the ONNX specification, these outputs must always be 1-D. I have provided suggestions to correct this in both the implementation and the corresponding tests. Additionally, I've included some minor suggestions to improve code clarity by simplifying index calculations.

@guan404ming guan404ming changed the title [Relax][ONNX] Add support for Unique optional outputs [Relax][ONNX] add support for unique optional outputs Jan 12, 2026
@guan404ming guan404ming force-pushed the onnx-unique-optional-outputs branch 2 times, most recently from d3f8fbd to 19ad697 Compare January 16, 2026 06:33
@guan404ming guan404ming force-pushed the onnx-unique-optional-outputs branch from 19ad697 to b01c8db Compare January 16, 2026 09:58
@guan404ming guan404ming force-pushed the onnx-unique-optional-outputs branch from 1542378 to 8ce0bca Compare January 16, 2026 13:53
@guan404ming guan404ming marked this pull request as ready for review January 16, 2026 17:28
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.

1 participant