Files
apache--tvm/python
Javier De Jesus f5e8a3acb3 [Relax][PyTorch] Add logical_or and logical_xor converters (#19756)
### Motivation

`torch.logical_or` and `torch.logical_xor` accept input tensors of any
dtype
(treating any nonzero element as `True`) and always return a `bool`
tensor.

Neither op was handled by the PyTorch frontend. The ExportedProgram
frontend did
not register `logical_or.default` / `logical_xor.default`, and the FX
frontend
did not register `logical_or` / `logical_xor`, so importing a model that
uses
either op failed early with `Unsupported function types`.

This follows up on #19679 (`logical_and`) and addresses the explicit
question
raised in #19743: whether `logical_or` and `logical_xor` need the same
handling.

### Changes

- Add shared `_logical_or` and `_logical_xor` converters in
`BaseFXGraphImporter`
that cast non-bool operands to `bool` before applying
`relax.op.logical_or` /
  `relax.op.logical_xor`. Bool operands are passed through unchanged (no
  redundant cast).
- Register `logical_or.default` / `logical_xor.default`
(ExportedProgram) and
  `logical_or` / `logical_xor` (FX), matching the existing `logical_and`
  converter.
- Add standalone `test_logical_or` and `test_logical_xor` to both the FX
and
ExportedProgram test suites, asserting the corrected IR (`astype` to
bool on
  each operand, then the logical op, 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.
2026-06-13 14:42:24 -04:00
..