javierdejesusda opened a new pull request, #19679:
URL: https://github.com/apache/tvm/pull/19679

   ### Motivation
   
   `torch.logical_and` accepts input tensors of any dtype (treating any nonzero
   element as `True`) and always returns a `bool` tensor.
   
   The PyTorch frontend did not produce that `bool` result. The ExportedProgram
   frontend lowered `logical_and.default` with
   `self._binary_op(relax.op.logical_and, operator.and_)`, which kept the 
operand
   dtype and emitted `relax.op.logical_and` on non-bool inputs (for example
   `float32`). `relax.op.logical_and` requires boolean inputs and otherwise 
fails
   `LegalizeOps` in the TOPI `logical_and`. The FX frontend did not register
   `logical_and` at all, so the op was unsupported there.
   
   ### Changes
   
   - Add a shared `_logical_and` converter in `BaseFXGraphImporter` that casts
     non-bool operands to `bool` before applying `relax.op.logical_and`. Bool
     operands are passed through unchanged (no redundant cast).
   - Point the `logical_and.default` (ExportedProgram) registration at the new
     converter, and add a `logical_and` (FX) registration that was previously
     missing, matching the existing `logical_not` converter.
   - Add a standalone `test_logical_and` to both the FX and ExportedProgram test
     suites asserting the corrected IR (`astype` to bool on each operand, then
     `logical_and`, producing a `bool` output).
   
   ### Notes
   
   The cast to `bool` lowers to an elementwise nonzero test, so it matches
   PyTorch's "nonzero is True" semantics for float, integer, and NaN inputs.
   


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