[Relax][PyTorch] Fix scalar parameter inputs in Dynamo#18725
[Relax][PyTorch] Fix scalar parameter inputs in Dynamo#18725tlopex merged 2 commits intoapache:mainfrom
Conversation
Summary of ChangesHello @mshr-h, 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 addresses a critical bug where scalar parameters were not being properly recognized and passed to the Relax VM through the Dynamo frontend. The changes ensure that zero-dimensional 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. Changelog
Activity
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.
Code Review
This pull request correctly addresses an issue with scalar parameter inputs in the PyTorch Dynamo frontend for Relax. The changes in dynamo.py ensure that scalar tensors are properly handled, and the new test case in test_frontend_dynamo.py effectively validates this fix. The modification in base_fx_graph_translator.py resolves a bug concerning binary operations on two constants. I have provided a suggestion to simplify this part of the code for better readability and conciseness. Overall, this is a solid improvement.
| if isinstance(lhs, relax.Var) or isinstance(rhs, relax.Var): | ||
| return call_binary_op(relax_op, lhs, rhs) | ||
| elif isinstance(lhs, relax.expr.Constant): | ||
| elif isinstance(lhs, relax.expr.Constant) and not isinstance(rhs, relax.expr.Constant): | ||
| return call_binary_op(relax_op, lhs, relax.const(rhs, dtype=lhs.struct_info.dtype)) | ||
| elif isinstance(rhs, relax.expr.Constant): | ||
| elif isinstance(rhs, relax.expr.Constant) and not isinstance(lhs, relax.expr.Constant): | ||
| return call_binary_op(relax_op, relax.const(lhs, dtype=rhs.struct_info.dtype), rhs) | ||
| return intrinsic_op(lhs, rhs) |
There was a problem hiding this comment.
While this change correctly fixes the issue with binary operations on two constants, the logic can be simplified. The call_binary_op function already contains promote_binary_op_args, which handles the promotion of Python scalars to Relax constants when one of the operands is a Relax expression. We can leverage this to make the code more concise and readable.
if isinstance(lhs, relax.Expr) or isinstance(rhs, relax.Expr):
return call_binary_op(relax_op, lhs, rhs)
return intrinsic_op(lhs, rhs)
Ensure scalar parameter placeholders are forwarded to the Relax VM.
Fix a model reported in pytorch/pytorch#169188