gemini-code-assist[bot] commented on code in PR #18725:
URL: https://github.com/apache/tvm/pull/18725#discussion_r2777693591


##########
python/tvm/relax/frontend/torch/base_fx_graph_translator.py:
##########
@@ -505,9 +505,9 @@ def call_binary_op(op, lhs, rhs):
             lhs, rhs = self.retrieve_args(node)
             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)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   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.
   
   ```python
               if isinstance(lhs, relax.Expr) or isinstance(rhs, relax.Expr):
                   return call_binary_op(relax_op, lhs, rhs)
               return intrinsic_op(lhs, rhs)
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to