This is an automated email from the ASF dual-hosted git repository.

tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new f0af322c19 [Relax][Frontend][TFLite] Add `REDUCE_ANY` and `REDUCE_ALL` 
(#19413)
f0af322c19 is described below

commit f0af322c197615457a1df49f6409bf8ffcf2ee14
Author: Soowon Jeong <[email protected]>
AuthorDate: Fri Apr 17 15:19:10 2026 +0900

    [Relax][Frontend][TFLite] Add `REDUCE_ANY` and `REDUCE_ALL` (#19413)
    
    ## 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_ANY` → `relax.op.max`
    - `REDUCE_ALL` → `relax.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.
---
 .../tvm/relax/frontend/tflite/tflite_frontend.py   |  3 ++-
 tests/python/relax/test_frontend_tflite.py         | 29 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/python/tvm/relax/frontend/tflite/tflite_frontend.py 
b/python/tvm/relax/frontend/tflite/tflite_frontend.py
index 22f45e8a5a..6d57dd5653 100644
--- a/python/tvm/relax/frontend/tflite/tflite_frontend.py
+++ b/python/tvm/relax/frontend/tflite/tflite_frontend.py
@@ -195,7 +195,8 @@ class OperatorConverter:
             "PRELU": self.convert_prelu,
             "RANGE": self.convert_range,
             "QUANTIZE": self.convert_quantize,
-            # "REDUCE_ANY": functools.partial(self._convert_reduce, 
relax_op=_op.any),
+            "REDUCE_ALL": functools.partial(self._convert_reduce, 
relax_op=_op.min),
+            "REDUCE_ANY": functools.partial(self._convert_reduce, 
relax_op=_op.max),
             "REDUCE_MAX": functools.partial(self._convert_reduce, 
relax_op=_op.max),
             "REDUCE_MIN": functools.partial(self._convert_reduce, 
relax_op=_op.min),
             "REDUCE_PROD": functools.partial(self._convert_reduce, 
relax_op=_op.prod),
diff --git a/tests/python/relax/test_frontend_tflite.py 
b/tests/python/relax/test_frontend_tflite.py
index de26bae25e..4fff2340de 100644
--- a/tests/python/relax/test_frontend_tflite.py
+++ b/tests/python/relax/test_frontend_tflite.py
@@ -1977,6 +1977,35 @@ def test_reduction_ops(tf_op, relax_op, input_shape, 
axes, keepdims, dtype):
     verify(ReduceModule, expected)
 
 
[email protected](
+    "tf_op, relax_op",
+    [
+        (tf.reduce_any, relax.op.max),
+        (tf.reduce_all, relax.op.min),
+    ],
+)
[email protected](
+    "input_shape, axes",
+    [
+        ((1, 8, 8, 3), 1),
+        ((1, 8, 8, 3), [1, 2]),
+        ((1, 8, 8, 3), -1),
+        ((1, 8, 8, 3), None),
+        ((30,), 0),
+        ((2, 5, 2), [0, 2]),
+    ],
+)
[email protected]("keepdims", [True, False])
+def test_reduction_bool_ops(tf_op, relax_op, input_shape, axes, keepdims):
+    class ReduceBoolModule(tf.Module):
+        @tf.function(input_signature=[tf.TensorSpec(shape=input_shape, 
dtype=tf.bool)])
+        def func(self, x):
+            return tf_op(x, axis=axes, keepdims=keepdims)
+
+    expected = _make_reduce_expected(relax_op, input_shape, axes, keepdims, 
"bool")
+    verify(ReduceBoolModule, expected)
+
+
 def test_pad():
     class Pad(tf.Module):
         @tf.function(input_signature=[tf.TensorSpec(shape=(2, 3), 
dtype=tf.float32)])

Reply via email to