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


##########
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:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Directly accessing `lhs.struct_info.dtype` can raise an `AttributeError` if 
`struct_info` is `None` or not an instance of `relax.TensorStructInfo`. To 
ensure robustness and consistency with other logical operators like 
`_logical_not`, we should first verify that `struct_info` is indeed a 
`TensorStructInfo` before accessing its `dtype`.
   
   ```suggestion
           if not isinstance(lhs.struct_info, relax.TensorStructInfo) or 
lhs.struct_info.dtype != "bool":
               lhs = self.block_builder.emit(relax.op.astype(lhs, "bool"))
           if not isinstance(rhs.struct_info, relax.TensorStructInfo) or 
rhs.struct_info.dtype != "bool":
               rhs = self.block_builder.emit(relax.op.astype(rhs, "bool"))
   ```



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