Skip to content

[Relax][Frontend][TFLite] Add explicit operator marker handling#19824

Draft
Aharrypotter wants to merge 1 commit into
apache:mainfrom
Aharrypotter:tflite-operator-markers-19519
Draft

[Relax][Frontend][TFLite] Add explicit operator marker handling#19824
Aharrypotter wants to merge 1 commit into
apache:mainfrom
Aharrypotter:tflite-operator-markers-19519

Conversation

@Aharrypotter

Copy link
Copy Markdown
Contributor

Summary

This PR adds explicit Relax TFLite frontend handling for the TFLite builtin
operator markers from #19519 item H:

  • DELEGATE
  • PLACEHOLDER_FOR_GREATER_OP_CODES

These builtins are TFLite marker / pseudo operators rather than ordinary tensor
operators. The frontend now recognizes them and raises a targeted
OpNotImplemented diagnostic instead of falling through to a generic
unsupported-operator path.

Design

DELEGATE marks delegated TFLite subgraphs, and
PLACEHOLDER_FOR_GREATER_OP_CODES is a schema compatibility placeholder. They
do not have Relax tensor semantics to lower. This PR therefore keeps the
importer conservative:

  • both builtin names are added to the TFLite convert_map
  • both route to a shared convert_operator_marker guard
  • the guard reports that the marker is not a Relax tensor operator

This makes the unsupported status intentional and discoverable without mapping
the markers to synthetic Relax ops.

Tests

The tests manually build minimal TFLite flatbuffers containing each marker
builtin and assert that import raises the targeted OpNotImplemented.

Local validation:

python -m ruff format \
  python/tvm/relax/frontend/tflite/tflite_frontend.py \
  tests/python/relax/test_frontend_tflite.py

python -m ruff check \
  python/tvm/relax/frontend/tflite/tflite_frontend.py \
  tests/python/relax/test_frontend_tflite.py

python -m pytest \
  tests/python/relax/test_frontend_tflite.py \
  -k operator_marker_unsupported -q

Result:

ruff format: 2 files left unchanged
ruff check: All checks passed
operator_marker_unsupported tests: 2 passed, 535 deselected

References

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds explicit handling for TFLite marker builtins (DELEGATE and PLACEHOLDER_FOR_GREATER_OP_CODES) in the Relax TFLite frontend, raising a clear OpNotImplemented error instead of failing silently or with a generic error. It also includes corresponding unit tests. The reviewer suggested adding a check to skip these tests if the installed tflite package version is older and does not define these operators, preventing potential test failures in those environments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +4089 to +4092
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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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 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))

@Aharrypotter Aharrypotter marked this pull request as draft June 18, 2026 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant