-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Relax] Fix the squeeze operator to behave consistently with torch #18478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Modify dimension check to skip non-1 dimensions.
Added a new Squeeze3 module and its expected output for testing.
Update squeeze function to skip non-unit dimensions.
Summary of ChangesHello @ConvolutedDog, 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 updates the Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 correctly updates the behavior of the squeeze operator in both TOPI and Relax to align with PyTorch, where attempting to squeeze a dimension not of size 1 is a no-op. The changes in include/tvm/topi/transform.h and src/relax/op/tensor/manipulate.cc correctly implement this logic, and the new test case in tests/python/relax/test_frontend_from_exported_program.py validates it. However, the docstrings for the squeeze function in python/tvm/relax/op/manipulate.py, python/tvm/topi/transform.py, and for SqueezeAttrs in include/tvm/relax/attrs/manipulate.h have not been updated to reflect this new behavior, which could cause confusion. I've added comments to address these documentation inconsistencies.
|
@tvm-bot rerun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Please include testcase for that in the relax op test.
https://github.com/apache/tvm/blob/main/tests/python/relax/test_op_manipulate.py#L840
Updated condition to check for valid dimensions in shape.
tlopex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you
mshr-h
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
This commit fixes the squeeze operator to behave consistently with PyTorch
by implementing no-op behavior when squeezing dimensions that are not of size 1.
Previously:
squeeze(x, [1]) on tensor with shape [32, 10, 5] would fail
Now:
squeeze(x, [1]) on tensor with shape [32, 10, 5] returns the original tensor
without modification, matching PyTorch's behavior
This fixes compatibility issues when converting PyTorch models that use
squeeze with dimensions that may not always be 1 during inference."
This work was done in collaboration with guan404ming's commit d87841d.