mshr-h commented on code in PR #17875:
URL: https://github.com/apache/tvm/pull/17875#discussion_r2055198180
##########
python/tvm/relax/frontend/torch/fx_translator.py:
##########
@@ -132,6 +132,54 @@ def convert(node: fx.Node) -> relax.Var:
return convert
+ ########## Binary Ops ##############
+
+ def _binary_op_inplace(self, relax_op: Callable, intrinsic_op: Callable)
-> Callable:
+ from torch import fx
+
+ def convert(node: fx.Node) -> relax.Var:
+ def promote_binary_op_args(lhs, rhs):
+ if isinstance(lhs, relax.Expr) and isinstance(rhs, relax.Expr):
+ return lhs, rhs
+ elif isinstance(lhs, relax.Expr):
+ assert isinstance(lhs.struct_info, relax.TensorStructInfo)
+ return lhs, relax.const(rhs, lhs.struct_info.dtype)
+ elif isinstance(rhs, relax.Expr):
+ assert isinstance(rhs.struct_info, relax.TensorStructInfo)
+ return relax.const(lhs, rhs.struct_info.dtype), rhs
+ else:
+ assert False
+
+ def call_binary_op(op, lhs, rhs):
+ lhs, rhs = promote_binary_op_args(lhs, rhs)
+ return self.block_builder.emit(op(lhs, rhs))
+
+ lhs, rhs = self.retrieve_args(node)
+ if isinstance(lhs, relax.Var) or isinstance(rhs, relax.Var):
Review Comment:
Ah, right. I misunderstood.
--
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]