Skip to content

Commit

Permalink
[TFLite] Add support for quantized mirror pad (#16243)
Browse files Browse the repository at this point in the history
Removes the restriction on converting quantized mirror pad in the
front-end and adds tests to support this change.

Change-Id: Id513709b38e6bfdcff2bb35554b6799ef5c5cd52
  • Loading branch information
lhutton1 committed Dec 15, 2023
1 parent 37c38ac commit b3eec91
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
6 changes: 0 additions & 6 deletions python/tvm/relay/frontend/tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
24 changes: 23 additions & 1 deletion tests/python/frontend/tflite/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
)


#######################################################################
Expand Down

0 comments on commit b3eec91

Please sign in to comment.