You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "eaten-cake (via GitHub)" <gi...@apache.org> on 2025/09/28 10:45:13 UTC
[PR] [Relax][Frontend][Torch] Fix parsing error when input dimension of unbind is 1 [tvm]
eaten-cake opened a new pull request, #18351:
URL: https://github.com/apache/tvm/pull/18351
fix issue #18338
When the input dimension of unbind is 1, we should directly apply squeeze instead of performing split followed by squeeze. This issue has been fixed, and a corresponding regression test has been added.
Previously, the error occurred because when the output of split contains only a single tensor, the `struct_info` of the expression is `TensorStructInfo` rather than `TupleStructInfo`. As a result, the `TupleGetItem` node generated at https://github.com/apache/tvm/blob/f68651f035d08024c05f218182b5c003ad814eb5/python/tvm/relax/frontend/torch/base_fx_graph_translator.py#L1279-L1280 would fail.
--
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][Frontend][Torch] Fix parsing error when input dimension of unbind is 1 [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #18351:
URL: https://github.com/apache/tvm/pull/18351#issuecomment-3342876205
## Summary of Changes
Hello @eaten-cake, 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 addresses a specific parsing error within the TVM Relax frontend for Torch, which occurred when processing `torch.unbind` operations on tensors with a dimension of size one. The fix streamlines the translation of this edge case by directly applying a `squeeze` operation, avoiding an incorrect `split` behavior that led to `TupleGetItem` failures. A new test case has been included to validate this correction and maintain stability.
### Highlights
* **Bug Fix**: Resolved a parsing error in the Relax frontend for Torch when the `unbind` operation is applied to an input tensor where the target dimension has a size of 1.
* **Optimized `unbind` handling**: Modified the `_unbind` method to directly apply a `squeeze` operation when the input dimension for unbinding is 1, instead of performing a `split` followed by `squeeze`.
* **Regression Test**: Added a new regression test case to ensure the correct behavior of `unbind` when the input dimension is 1, preventing future regressions.
<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][Frontend][Torch] Fix parsing error when input dimension of unbind is 1 [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #18351:
URL: https://github.com/apache/tvm/pull/18351#discussion_r2385411934
##########
tests/python/relax/test_frontend_from_exported_program.py:
##########
@@ -3251,9 +3251,23 @@ def main(
R.output(gv)
return gv
+ @tvm.script.ir_module
+ class expected3:
+ @R.function
+ def main(data: R.Tensor((3, 1, 3), dtype="float32")) -> R.Tuple(R.Tensor((3, 3), dtype="float32")):
+ with R.dataflow():
+ lv: R.Tensor((3, 3), dtype="float32") = R.squeeze(data, axis=[1])
+ lv1: R.Tuple(R.Tensor((3, 3), dtype="float32")) = (lv,)
+ lv2: R.Tensor((3, 3), dtype="float32") = lv1[0]
+ gv: R.Tuple(R.Tensor((3, 3), dtype="float32")) = (lv2,)
+ R.output(gv)
Review Comment:

The IR in `expected3` seems unnecessarily verbose. The sequence of creating a tuple, unpacking it, and then repacking it can be simplified. This would make the test clearer and more maintainable.
If the frontend generates this verbose IR, this might point to an opportunity for simplification in the translator itself. However, simplifying the test's expected IR is a good first step for readability.
```suggestion
lv: R.Tensor((3, 3), dtype="float32") = R.squeeze(data, axis=[1])
gv: R.Tuple(R.Tensor((3, 3), dtype="float32")) = (lv,)
R.output(gv)
```
--
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][Frontend][Torch] Fix parsing error when input dimension of unbind is 1 [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #18351:
URL: https://github.com/apache/tvm/pull/18351
--
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][Frontend][Torch] Fix parsing error when input dimension of unbind is 1 [tvm]
Posted by "eaten-cake (via GitHub)" <gi...@apache.org>.
eaten-cake commented on PR #18351:
URL: https://github.com/apache/tvm/pull/18351#issuecomment-3343258258
resolve #18338
--
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