Skip to content

Conversation

@tlopex
Copy link
Member

@tlopex tlopex commented Oct 29, 2025

This pr fixes softmax, softsign, softshrink, tril, triu, div, batchnorm2d,addmm, baddbmm, bmm

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tlopex, 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 PyTorch frontend by introducing support for decomposed operators. This change allows for a more granular representation of complex PyTorch operations within the Relax Intermediate Representation (IR), improving flexibility and optimization opportunities. It also includes specific fixes and parameter additions for operators like batchnorm2d and matmul to ensure accurate translation.

Highlights

  • Decomposed Operator Support: Implemented decomposition logic for several PyTorch operators, including softmax, softsign, softshrink, tril, triu, div, batchnorm2d, addmm, baddbmm, and bmm, within the Relax PyTorch frontend.
  • New _scalar_tensor Handler: Added a new internal handler _scalar_tensor to correctly translate torch.scalar_tensor operations into Relax constants.
  • IR Test Updates: Updated numerous tests to reflect the new decomposed IR for the affected operators and enabled decomposition verification.
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 enhances the PyTorch frontend in Relax by adding support for decomposed operators. It introduces a handler for scalar_tensor and adds a new mapping for _softmax.default. The majority of the changes are within the test suite, where tests for several operators (softmax, softsign, softshrink, tril, triu, div, batchnorm2d, addmm, baddbmm, bmm) have been updated to execute with run_ep_decomposition=True. This required updating the expected Relax IR to align with the output from the decomposed PyTorch operators. The changes are well-aligned with the PR's objectives. I have included a few suggestions to enhance the conciseness and readability of the updated test IRs.

Comment on lines +1169 to 1171
lv5: R.Tensor((1, 3, 10, 10), dtype="float32") = R.multiply(
input, R.const(0.0, "float32")
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using R.zeros_like(input) would be more idiomatic and clearer to express the intent of creating a zero tensor with the same shape and dtype as input.

                lv5: R.Tensor((1, 3, 10, 10), dtype="float32") = R.zeros_like(input)

Comment on lines +1201 to +1204
lv2: R.Tensor((10,), dtype="int64") = R.arange(
R.prim_value(0), R.prim_value(10), R.prim_value(1), dtype="int64"
)
lv3: R.Tensor((10, 1), dtype="int64") = R.expand_dims(lv2, axis=[-1])
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The arange call to create lv2 is redundant, as lv created on line 1197 is identical. You can reuse lv to create lv3 and remove the definition of lv2 to make the IR more concise and avoid a redundant operation. This same issue is present in expected_triu as well.

                lv3: R.Tensor((10, 1), dtype="int64") = R.expand_dims(lv, axis=[-1])

Comment on lines +1231 to +1234
lv2: R.Tensor((10,), dtype="int64") = R.arange(
R.prim_value(0), R.prim_value(10), R.prim_value(1), dtype="int64"
)
lv3: R.Tensor((10, 1), dtype="int64") = R.expand_dims(lv2, axis=[-1])
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to expected_tril, the arange call to create lv2 is redundant. You can reuse lv (defined on line 1227) to create lv3 and remove the definition of lv2.

                lv3: R.Tensor((10, 1), dtype="int64") = R.expand_dims(lv, axis=[-1])

@tlopex
Copy link
Member Author

tlopex commented Oct 29, 2025

@tvm-bot rerun

@tlopex
Copy link
Member Author

tlopex commented Oct 30, 2025

cc @mshr-h

@mshr-h mshr-h merged commit be37afd into apache:main Oct 30, 2025
13 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