javierdejesusda opened a new pull request, #19645:
URL: https://github.com/apache/tvm/pull/19645
### Motivation
`torch.logical_not` accepts an input tensor of any dtype (treating any
nonzero
element as `True`) and always returns a `bool` tensor.
The PyTorch frontend previously lowered it with
`self._unary_op(relax.op.logical_not)`.
`relax.op.logical_not` is a unary arithmetic op that passes its input dtype
through,
so a non-bool input (for example `float32`) produced a `float32` result
instead of
the `bool` result PyTorch returns. This is a dtype mismatch against the
reference
PyTorch semantics for both the FX and ExportedProgram frontends.
### Changes
- Add a shared `_logical_not` converter in `BaseFXGraphImporter` that casts
non-bool
inputs to `bool` before applying `relax.op.logical_not`. Bool inputs are
passed
through unchanged (no redundant cast).
- Point the `logical_not` (FX) and `logical_not.default` (ExportedProgram)
registrations at the new converter.
- Update the FX test and add a standalone ExportedProgram `test_logical_not`
to assert
the corrected IR (`astype` to bool, then `logical_not`, 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]