javierdejesusda commented on code in PR #19679:
URL: https://github.com/apache/tvm/pull/19679#discussion_r3368198037


##########
python/tvm/relax/frontend/torch/base_fx_graph_translator.py:
##########
@@ -391,6 +391,17 @@ def _log_softmax(self, node: fx.Node) -> relax.Var:
         dim = node.args[1] if len(node.args) > 1 else node.kwargs.get("dim", 
-1)
         return self.block_builder.emit(relax.op.nn.log_softmax(x, dim))
 
+    def _logical_and(self, node: fx.Node) -> relax.Var:
+        lhs = self.env[node.args[0]]
+        rhs = self.env[node.args[1]]
+        # torch.logical_and accepts any dtype (treating nonzero as True) and 
returns bool, but
+        # relax.op.logical_and requires boolean inputs, so cast non-bool 
inputs to bool first.
+        if lhs.struct_info.dtype != "bool":
+            lhs = self.block_builder.emit(relax.op.astype(lhs, "bool"))
+        if rhs.struct_info.dtype != "bool":
+            rhs = self.block_builder.emit(relax.op.astype(rhs, "bool"))

Review Comment:
   I kept the direct `struct_info.dtype` check to stay
   consistent with the existing `_logical_not` converter just below, which 
accesses
   `struct_info.dtype` the same way without an `isinstance` check. Both 
operands come
   from `torch.logical_and`, which only accepts tensor inputs, so their 
`struct_info`
   is always a `TensorStructInfo` and the access is safe. Adding the guard here 
would
   make this converter diverge from `_logical_not`, so I left it consistent 
with the
   surrounding code.



-- 
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