From 7cd904e3b73089a4f3ceaadb941c0d1a40122765 Mon Sep 17 00:00:00 2001 From: Aharrypotter Date: Thu, 18 Jun 2026 11:56:47 +0800 Subject: [PATCH] [Relax][Frontend][TFLite] Add explicit operator marker handling --- .../relax/frontend/tflite/tflite_frontend.py | 10 +++++++ tests/python/relax/test_frontend_tflite.py | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/python/tvm/relax/frontend/tflite/tflite_frontend.py b/python/tvm/relax/frontend/tflite/tflite_frontend.py index 0edfc00ce9e1..85555c4f9664 100644 --- a/python/tvm/relax/frontend/tflite/tflite_frontend.py +++ b/python/tvm/relax/frontend/tflite/tflite_frontend.py @@ -219,6 +219,7 @@ def __init__(self, model, subgraph, exp_tab, ctx, conversion_state=None): "DENSIFY": self.convert_densify, "DEPTH_TO_SPACE": self.convert_depth_to_space, "DEPTHWISE_CONV_2D": functools.partial(self.convert_conv, conv_type="depthwise"), + "DELEGATE": functools.partial(self.convert_operator_marker, op_name="DELEGATE"), "DEQUANTIZE": self.convert_dequantize, "DETECTION_POSTPROCESS": self.convert_detection_postprocess, "DILATE": self.convert_dilate, @@ -290,6 +291,9 @@ def __init__(self, model, subgraph, exp_tab, ctx, conversion_state=None): "PACK": self.convert_pack, "PAD": self.convert_pad, "PADV2": self.convert_pad, + "PLACEHOLDER_FOR_GREATER_OP_CODES": functools.partial( + self.convert_operator_marker, op_name="PLACEHOLDER_FOR_GREATER_OP_CODES" + ), "POW": functools.partial(self._convert_elemwise, relax_op=_op.power), "PRELU": self.convert_prelu, "RANGE": self.convert_range, @@ -479,6 +483,12 @@ def check_unsupported_ops(self): if len(raise_msg) > 0: raise tvm.error.OpNotImplemented(raise_msg) + def convert_operator_marker(self, op, op_name): + """Reject TFLite marker builtins with an explicit diagnostic.""" + raise tvm.error.OpNotImplemented( + f"TFLite operator marker {op_name} is not a Relax tensor operator" + ) + def unbind(self, data, axis=1): """ This is a modified version compared to the one in common.py. diff --git a/tests/python/relax/test_frontend_tflite.py b/tests/python/relax/test_frontend_tflite.py index 01beaadd7bdb..540c3fcb7806 100644 --- a/tests/python/relax/test_frontend_tflite.py +++ b/tests/python/relax/test_frontend_tflite.py @@ -4066,6 +4066,32 @@ def _get_builtin_operator(builtin_name): return getattr(_tfl_builtin_operator, builtin_name) +def _build_tflite_operator_marker_model(builtin_name): + """Build a minimal model containing a TFLite marker builtin.""" + builder = flatbuffers.Builder(1024) + builtin_op = _get_builtin_operator(builtin_name) + op_code = _build_operator_code(builder, builtin_op) + tensors = [ + _build_tensor(builder, 0, [1], tensor_type=_tfl_tensor_type.FLOAT32), + _build_tensor(builder, 0, [1], tensor_type=_tfl_tensor_type.FLOAT32), + ] + op = _build_operator(builder, 0, [0], [1]) + subgraph = _build_subgraph(builder, tensors=tensors, operators=[op], inputs=[0], outputs=[1]) + return _finish_tflite_model( + builder, + subgraph=subgraph, + operator_codes=[op_code], + buffers=[_build_buffer(builder)], + ) + + +@pytest.mark.parametrize("builtin_name", ["DELEGATE", "PLACEHOLDER_FOR_GREATER_OP_CODES"]) +def test_operator_marker_unsupported(builtin_name): + """TFLite marker builtins report explicit unsupported diagnostics.""" + with pytest.raises(tvm.error.OpNotImplemented, match=f"TFLite operator marker {builtin_name}"): + _load_model_from_buffer(_build_tflite_operator_marker_model(builtin_name)) + + def _run_module(mod, *inputs): tgt = tvm.target.Target("c") ex = tvm.compile(mod, tgt)