[Relax][PyTorch] Support bare operator.add and operator.sub in PyTorch ExportedProgram frontend#18919
[Relax][PyTorch] Support bare operator.add and operator.sub in PyTorch ExportedProgram frontend#18919mshr-h wants to merge 1 commit into
Conversation
…h ExportedProgram frontend Added `"add"` and `"sub"` entries to the ExportedProgram frontend `convert_map`. When `operator.add` or `operator.sub` appears in an FX graph, its `__name__` is `"add"` or `"sub"` (without suffix), which wasn't matched by existing entries like `"add.Tensor"`.
Summary of ChangesHello, 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 PyTorch ExportedProgram frontend within TVM Relax by introducing explicit support for bare Highlights
🧠 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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly adds support for bare operator.add and operator.sub in the PyTorch ExportedProgram frontend by updating the convert_map. This is a necessary change for handling dynamic shapes, as torch.export can emit these operators in such scenarios. The new test case effectively validates this functionality. I've identified a minor fragility issue in the test where hardcoded symbolic variable names are used, and I've provided suggestions to make the test more robust.
| R.Tensor(("s0", 4), dtype="float32") | ||
| ): | ||
| s0 = T.int64(is_size_var=True) | ||
| R.func_attr({"tir_var_lower_bound": {"s77": 2}}) |
There was a problem hiding this comment.
The hardcoded symbolic variable name "s77" in func_attr makes this test fragile, as the name generated by PyTorch's export is not guaranteed to be consistent. While map_free_vars=True can map symbolic variables in shapes, it doesn't apply to string keys in the attributes dictionary. Since the main purpose of this test is to verify the translation of bare add and sub operators, and not the range constraints, I suggest removing this line to make the test more robust.
| R.Tensor(("s0", 4), dtype="float32") | ||
| ): | ||
| s0 = T.int64(is_size_var=True) | ||
| R.func_attr({"tir_var_lower_bound": {"s77": 2}}) |
Added
"add"and"sub"entries to the ExportedProgram frontendconvert_map.When
operator.addoroperator.subappears in an FX graph, its__name__is"add"or"sub"(without suffix), which wasn't matched by existing entries like"add.Tensor".