Skip to content

[Relax][Frontend][TFLite] Fix bool REDUCE_ANY/REDUCE_ALL compile failure#19415

Merged
tlopex merged 1 commit into
apache:mainfrom
swjng:fix/tflite-reduce-bool-cast
Apr 18, 2026
Merged

[Relax][Frontend][TFLite] Fix bool REDUCE_ANY/REDUCE_ALL compile failure#19415
tlopex merged 1 commit into
apache:mainfrom
swjng:fix/tflite-reduce-bool-cast

Conversation

@swjng

@swjng swjng commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Problem

#19413 registered REDUCE_ANY / REDUCE_ALL as _convert_reduce with relax.op.max / relax.op.min. These TFLite ops are bool-only (per TFL op schema: TFL_ReduceAnyOp / TFL_ReduceAllOp take and return TFL_BoolTensor), and relax.op.max / relax.op.min are not defined on bool, so any real model using these ops fails at compile time with:

Cannot decide min_value for type bool
Cannot decide max_value for type bool

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_bool handler 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 without CI_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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread python/tvm/relax/frontend/tflite/tflite_frontend.py
… 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.
@swjng swjng force-pushed the fix/tflite-reduce-bool-cast branch from 6665dfb to 9978949 Compare April 17, 2026 07:48
verify(ReduceBoolModule, expected)

# Regression guard: compile to catch a bool max/min lowering path.
tvm.compile(expected, tvm.target.Target("llvm"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tvm.compile(expected, tvm.target.Target("llvm")) I don't think we need it here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@tlopex tlopex merged commit 545c332 into apache:main Apr 18, 2026
13 checks passed
@tlopex

tlopex commented Apr 18, 2026

Copy link
Copy Markdown
Member

Merged though, we may find some ways to completely fix it, not only at the frontend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants