From b3eec91ee6254b40920c40e922cb3c37ac1c06a4 Mon Sep 17 00:00:00 2001 From: Luke Hutton Date: Fri, 15 Dec 2023 10:54:14 +0000 Subject: [PATCH] [TFLite] Add support for quantized mirror pad (#16243) Removes the restriction on converting quantized mirror pad in the front-end and adds tests to support this change. Change-Id: Id513709b38e6bfdcff2bb35554b6799ef5c5cd52 --- python/tvm/relay/frontend/tflite.py | 6 ----- tests/python/frontend/tflite/test_forward.py | 24 +++++++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/python/tvm/relay/frontend/tflite.py b/python/tvm/relay/frontend/tflite.py index 1880887b7e65..364886423928 100644 --- a/python/tvm/relay/frontend/tflite.py +++ b/python/tvm/relay/frontend/tflite.py @@ -2677,12 +2677,6 @@ def convert_mirror_pad(self, op): except ImportError: raise ImportError("The tflite package must be installed") - # the quantized form MirrorPad is not yet implemented in TFLite. - if self.is_quantized(op): - raise tvm.error.OpNotImplemented( - "TFlite quantized MIRROR_PAD operator is not supported yet." - ) - input_tensors = self.get_input_tensors(op) assert len(input_tensors) == 2, "input tensors length should be 2" diff --git a/tests/python/frontend/tflite/test_forward.py b/tests/python/frontend/tflite/test_forward.py index e85d370be521..6d1e656221f9 100644 --- a/tests/python/frontend/tflite/test_forward.py +++ b/tests/python/frontend/tflite/test_forward.py @@ -3436,7 +3436,13 @@ def _test_pad(data, mode="CONSTANT", quantized=False): inq_data[0], ops.convert_to_tensor(data[1], dtype=data[1].dtype), mode=mode ) compare_tflite_with_tvm( - [data[0]], ["inq_0:0"], inq_data, [out], quantized=True, input_range=input_range + [data[0]], + ["inq_0:0"], + inq_data, + [out], + quantized=True, + input_range=input_range, + experimental_new_converter=True, ) else: out = array_ops.pad( @@ -3506,6 +3512,22 @@ def test_forward_pad(): ], quantized=True, ) + _test_pad( + [ + np.arange(0, 256, dtype=np.uint8).reshape((1, 256)), + np.array([[1, 1], [2, 2]], dtype=np.int32), + ], + quantized=True, + mode="SYMMETRIC", + ) + _test_pad( + [ + np.arange(0, 256, dtype=np.uint8).reshape((1, 256)), + np.array([[0, 0], [2, 2]], dtype=np.int32), + ], + quantized=True, + mode="REFLECT", + ) #######################################################################