[Relax][Frontend][TFLite] Fix bool REDUCE_ANY/REDUCE_ALL compile failure#19415
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements a specialized conversion for TFLite's REDUCE_ALL and REDUCE_ANY operations by casting boolean inputs to int8 before reduction and back to bool afterwards, addressing the lack of support for boolean min/max operations in Relax. A review comment identifies a bug in the handling of empty axes, which currently results in no reduction instead of reducing over all dimensions as required by TFLite, and suggests a more efficient way to handle single-element tuples.
… int8 TFLite `REDUCE_ANY` / `REDUCE_ALL` take bool tensors (per TFL op schema), but `relax.op.max` / `relax.op.min` are not defined on bool, so compile fails with "Cannot decide min_value/max_value for type bool". Cast the input to int8, reduce, then cast back to bool. Also compile the expected module in the test so this regression is caught without `CI_ENV_NIGHTLY`. Follow-up to apache#19413.
6665dfb to
9978949
Compare
| verify(ReduceBoolModule, expected) | ||
|
|
||
| # Regression guard: compile to catch a bool max/min lowering path. | ||
| tvm.compile(expected, tvm.target.Target("llvm")) |
There was a problem hiding this comment.
tvm.compile(expected, tvm.target.Target("llvm")) I don't think we need it here?
There was a problem hiding this comment.
I'd like to keep this if possible. The guard caught exactly the regression that #19413 shipped that structural equality matched because expected and converted IR both used relax.op.max on bool, and the failure surfaces only at compile time. If there's a different path in CI that actually exercises compile for the TFLite frontend tests, then it can be removed. Do you have any idea of that?
|
Merged though, we may find some ways to completely fix it, not only at the frontend |
Problem
#19413 registered
REDUCE_ANY/REDUCE_ALLas_convert_reducewithrelax.op.max/relax.op.min. These TFLite ops are bool-only (per TFL op schema:TFL_ReduceAnyOp/TFL_ReduceAllOptake and returnTFL_BoolTensor), andrelax.op.max/relax.op.minare not defined on bool, so any real model using these ops fails at compile time with:The existing structural-equality test passed because it never attempted to compile the converted module (E2E is gated on
CI_ENV_NIGHTLY).Fix
Introduce a dedicated
_convert_reduce_boolhandler that casts the input to int8, reduces with max/min, and casts back to bool. Update the test to compile the expected module so this lowering is exercised withoutCI_ENV_NIGHTLY.Testing
Verified compile + VM-run (TF converter → Relax → LLVM) across the full shape / axes / keepdims matrix from
test_reduction_bool_ops: 12 cases, all PASS.Follow-up to #19413.