Skip to content

[Relax][Frontend][TFLite] Add REDUCE_ANY and REDUCE_ALL#19413

Merged
tlopex merged 1 commit intoapache:mainfrom
swjng:feature/tflite-reduce-any-all
Apr 17, 2026
Merged

[Relax][Frontend][TFLite] Add REDUCE_ANY and REDUCE_ALL#19413
tlopex merged 1 commit intoapache:mainfrom
swjng:feature/tflite-reduce-any-all

Conversation

@swjng
Copy link
Copy Markdown
Contributor

@swjng swjng commented Apr 17, 2026

Summary

Adds TFLite frontend support for REDUCE_ANY and REDUCE_ALL (B-group item in #19412).

Lowering

REDUCE_ANY / REDUCE_ALL take 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_ANYrelax.op.max
  • REDUCE_ALLrelax.op.min

Both reuse the existing _convert_reduce handler (shared with REDUCE_MAX, REDUCE_MIN, REDUCE_PROD, MEAN, SUM), with entries added alphabetically to convert_map.

Testing

Added test_reduction_bool_ops in tests/python/relax/test_frontend_tflite.py, parametrized over the same shape / axes / keepdims matrix as the existing test_reduction_ops (24 combinations total). Verified locally by running the test function directly across all parametrizations.

Refs #19412.

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.
Copy link
Copy Markdown
Contributor

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

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 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.

Copy link
Copy Markdown
Member

@tlopex tlopex left a comment

Choose a reason for hiding this comment

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

LGTM Thanks!

@tlopex tlopex merged commit f0af322 into apache:main Apr 17, 2026
10 checks passed
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.
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