You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "tlopex (via GitHub)" <gi...@apache.org> on 2025/10/29 16:15:31 UTC
[PR] [Relax][PyTorch] Add support for decomposed operators and fix IR of ops tests(2) [tvm]
tlopex opened a new pull request, #18403:
URL: https://github.com/apache/tvm/pull/18403
This pr fixes `softmax`, `softsign`, `softshrink`, `tril`, `triu`, `div`, `batchnorm2d`,`addmm`, `baddbmm`, `bmm`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Relax][PyTorch] Add support for decomposed operators and fix IR of ops tests(2) [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #18403:
URL: https://github.com/apache/tvm/pull/18403#issuecomment-3468669667
cc @mshr-h
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Relax][PyTorch] Add support for decomposed operators and fix IR of ops tests(2) [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #18403:
URL: https://github.com/apache/tvm/pull/18403#issuecomment-3462526005
## Summary of Changes
Hello @tlopex, I'm Gemini Code Assist[^1]! 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.
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
<b>Invoking Gemini</b>
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.
<b>Customization</b>
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](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: 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](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
<b>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](https://cloud.google.com/products/gemini/code-assist).</b>
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Relax][PyTorch] Add support for decomposed operators and fix IR of ops tests(2) [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #18403:
URL: https://github.com/apache/tvm/pull/18403#discussion_r2474140433
##########
tests/python/relax/test_frontend_from_exported_program.py:
##########
@@ -1198,16 +1190,27 @@ def forward(self, input):
class expected_tril:
@R.function
def main(
- input_1: R.Tensor((10, 10), dtype="float32")
+ input: R.Tensor((10, 10), dtype="float32")
) -> R.Tuple(R.Tensor((10, 10), dtype="float32")):
# block 0
with R.dataflow():
- lv: R.Tensor((10, 10), dtype="float32") = R.tril(input_1, 1)
- gv: R.Tuple(R.Tensor((10, 10), dtype="float32")) = (lv,)
+ lv: R.Tensor((10,), dtype="int64") = R.arange(
+ R.prim_value(0), R.prim_value(10), R.prim_value(1), dtype="int64"
+ )
+ lv1: R.Tensor((1, 10), dtype="int64") = R.expand_dims(lv, axis=[-2])
+ 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])
Review Comment:

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.
```python
lv3: R.Tensor((10, 1), dtype="int64") = R.expand_dims(lv, axis=[-1])
```
##########
tests/python/relax/test_frontend_from_exported_program.py:
##########
@@ -1217,16 +1220,27 @@ def forward(self, input):
class expected_triu:
@R.function
def main(
- input_1: R.Tensor((10, 10), dtype="float32")
+ input: R.Tensor((10, 10), dtype="float32")
) -> R.Tuple(R.Tensor((10, 10), dtype="float32")):
# block 0
with R.dataflow():
- lv: R.Tensor((10, 10), dtype="float32") = R.triu(input_1, 1)
- gv: R.Tuple(R.Tensor((10, 10), dtype="float32")) = (lv,)
+ lv: R.Tensor((10,), dtype="int64") = R.arange(
+ R.prim_value(0), R.prim_value(10), R.prim_value(1), dtype="int64"
+ )
+ lv1: R.Tensor((1, 10), dtype="int64") = R.expand_dims(lv, axis=[-2])
+ 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])
Review Comment:

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`.
```python
lv3: R.Tensor((10, 1), dtype="int64") = R.expand_dims(lv, axis=[-1])
```
##########
tests/python/relax/test_frontend_from_exported_program.py:
##########
@@ -1159,32 +1159,24 @@ def main(
input: R.Tensor((1, 3, 10, 10), dtype="float32"),
) -> R.Tuple(R.Tensor((1, 3, 10, 10), dtype="float32")):
with R.dataflow():
- lv: R.Tensor((1, 3, 10, 10), dtype="float32") = R.subtract(
- input, R.const(0.5, "float32")
- )
- lv1: R.Tensor((1, 3, 10, 10), dtype="bool") = R.greater(
- input, R.const(0.5, "float32")
+ lv: R.Tensor((1, 3, 10, 10), dtype="float32") = R.abs(input)
+ lv1: R.Tensor((1, 3, 10, 10), dtype="bool") = R.greater(lv, R.const(0.5, "float32"))
+ lv2: R.Tensor((1, 3, 10, 10), dtype="float32") = R.sign(input)
+ lv3: R.Tensor((1, 3, 10, 10), dtype="float32") = R.multiply(
+ lv2, R.const(0.5, "float32")
)
- lv2: R.Tensor((1, 3, 10, 10), dtype="float32") = R.astype(lv1, "float32")
- lv3: R.Tensor((1, 3, 10, 10), dtype="float32") = R.multiply(lv, lv2)
-
- lv4: R.Tensor((1, 3, 10, 10), dtype="float32") = R.add(
- input, R.const(0.5, "float32")
+ lv4: R.Tensor((1, 3, 10, 10), dtype="float32") = R.subtract(input, lv3)
+ lv5: R.Tensor((1, 3, 10, 10), dtype="float32") = R.multiply(
+ input, R.const(0.0, "float32")
)
Review Comment:

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`.
```python
lv5: R.Tensor((1, 3, 10, 10), dtype="float32") = R.zeros_like(input)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Relax][PyTorch] Add support for decomposed operators and fix IR of ops tests(2) [tvm]
Posted by "mshr-h (via GitHub)" <gi...@apache.org>.
mshr-h merged PR #18403:
URL: https://github.com/apache/tvm/pull/18403
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Relax][PyTorch] Add support for decomposed operators and fix IR of ops tests(2) [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #18403:
URL: https://github.com/apache/tvm/pull/18403#issuecomment-3462824369
@tvm-bot rerun
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org