gemini-code-assist[bot] commented on code in PR #19824:
URL: https://github.com/apache/tvm/pull/19824#discussion_r3432893852
##########
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)],
+ )
+
+
[email protected]("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))
Review Comment:

To prevent test failures in environments with older versions of the `tflite`
package (where `DELEGATE` or `PLACEHOLDER_FOR_GREATER_OP_CODES` might not be
defined in `_tfl_builtin_operator`), we should check for their existence and
skip the test if they are missing.
```suggestion
def test_operator_marker_unsupported(builtin_name):
"""TFLite marker builtins report explicit unsupported diagnostics."""
if not hasattr(_tfl_builtin_operator, builtin_name):
pytest.skip(f"{builtin_name} is not supported by the installed
tflite package version.")
with pytest.raises(tvm.error.OpNotImplemented, match=f"TFLite operator
marker {builtin_name}"):
_load_model_from_buffer(_build_tflite_operator_marker_model(builtin_name))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]