You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "Aharrypotter (via GitHub)" <gi...@apache.org> on 2026/06/18 03:57:15 UTC

[PR] [Relax][Frontend][TFLite] Add explicit operator marker handling [tvm]

Aharrypotter opened a new pull request, #19824:
URL: https://github.com/apache/tvm/pull/19824

   ## 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:
   
   ```bash
   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:
   
   ```text
   ruff format: 2 files left unchanged
   ruff check: All checks passed
   operator_marker_unsupported tests: 2 passed, 535 deselected
   ```
   
   ## References
   
   - Issue #19519 item H: TFLite operator markers
   


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][TFLite] Add explicit operator marker handling [tvm]

Posted by "Aharrypotter (via GitHub)" <gi...@apache.org>.
Aharrypotter commented on code in PR #19824:
URL: https://github.com/apache/tvm/pull/19824#discussion_r3447875486


##########
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))

Review Comment:
   The older-schema case is already covered by the shared `_get_builtin_operator` helper in `tests/python/relax/test_frontend_tflite.py`: it checks `hasattr(_tfl_builtin_operator, builtin_name)` and calls `pytest.skip(...)` if the installed `tflite` package does not define the marker builtin enum.
   
   I also re-ran the focused marker test locally and it passes: `test_operator_marker_unsupported`: 2 passed.



-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][TFLite] Add explicit operator marker handling [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #19824:
URL: https://github.com/apache/tvm/pull/19824


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][TFLite] Add explicit operator marker handling [tvm]

Posted by "Aharrypotter (via GitHub)" <gi...@apache.org>.
Aharrypotter commented on PR #19824:
URL: https://github.com/apache/tvm/pull/19824#issuecomment-4760841414

   Thanks for the review. The older-schema case is already covered by the shared _get_builtin_operator helper in 	ests/python/relax/test_frontend_tflite.py: it checks hasattr(_tfl_builtin_operator, builtin_name) and calls pytest.skip(...) if the installed 	flite package does not define the marker builtin enum. I also re-ran the focused marker test locally and it passes (	est_operator_marker_unsupported: 2 passed).


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][TFLite] Add explicit operator marker handling [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
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)],
+    )
+
+
+@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))

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org