[Relax][Frontend][TFLite] Add REDUCE_ANY and REDUCE_ALL#19413
Merged
tlopex merged 1 commit intoapache:mainfrom Apr 17, 2026
Merged
[Relax][Frontend][TFLite] Add REDUCE_ANY and REDUCE_ALL#19413tlopex merged 1 commit intoapache:mainfrom
REDUCE_ANY and REDUCE_ALL#19413tlopex merged 1 commit intoapache:mainfrom
Conversation
Lower `REDUCE_ANY` to `relax.op.max` and `REDUCE_ALL` to `relax.op.min` on bool tensors. Max/min on bool preserves logical-or/and semantics, so no new Relax op is needed. Adds a structural-equality test covering the same shape/axes/keepdims matrix as `test_reduction_ops`. Tracked in apache#19412.
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds support for REDUCE_ALL and REDUCE_ANY operators in the TFLite frontend for TVM Relax, mapping them to relax.op.min and relax.op.max respectively. It also introduces a new test suite, test_reduction_bool_ops, which validates these boolean reduction operations across multiple input shapes, axes, and keepdims configurations. I have no feedback to provide.
swjng
added a commit
to swjng/tvm
that referenced
this pull request
Apr 17, 2026
… 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
added a commit
to swjng/tvm
that referenced
this pull request
Apr 17, 2026
… 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.
tlopex
pushed a commit
that referenced
this pull request
Apr 18, 2026
…failure (#19415) ## 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds TFLite frontend support for
REDUCE_ANYandREDUCE_ALL(B-group item in #19412).Lowering
REDUCE_ANY/REDUCE_ALLtake bool tensors and compute logical OR / AND along the given axes. Max / min on a bool tensor produces the same result, so no new Relax op is required:REDUCE_ANY→relax.op.maxREDUCE_ALL→relax.op.minBoth reuse the existing
_convert_reducehandler (shared withREDUCE_MAX,REDUCE_MIN,REDUCE_PROD,MEAN,SUM), with entries added alphabetically toconvert_map.Testing
Added
test_reduction_bool_opsintests/python/relax/test_frontend_tflite.py, parametrized over the same shape / axes / keepdims matrix as the existingtest_reduction_ops(24 combinations total). Verified locally by running the test function directly across all parametrizations.Refs #19412.