[Relax][Frontend][TFLite] Add SCATTER_ND operator for Relax TFLite#19490
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds support for the SCATTER_ND operator to the TFLite frontend in Relax and includes a new test case to verify its functionality. The review feedback highlights two necessary corrections: the indices tensor needs to be permuted to align with Relax's expected layout (where the index depth is the first dimension), and the shape tensor must be explicitly cast to int64 when handled dynamically to satisfy the requirements of the tensor_to_shape operator.
tlopex
approved these changes
May 1, 2026
tlopex
pushed a commit
that referenced
this pull request
May 3, 2026
## Summary This PR adds Relax TFLite frontend support for the following segment operators from #19412: - `SEGMENT_SUM` - `UNSORTED_SEGMENT_MIN` - `UNSORTED_SEGMENT_PROD` These operators are lowered through `relax.op.scatter_nd` with the corresponding reduction modes. ## Changes ### TFLite Frontend 1. Add TFLite converter mappings for segment operators: - `SEGMENT_SUM` -> `scatter_nd(..., reduction="add")` - `UNSORTED_SEGMENT_MIN` -> `scatter_nd(..., reduction="min")` - `UNSORTED_SEGMENT_PROD` -> `scatter_nd(..., reduction="mul")` 2. Add shared segment lowering logic: - Convert `segment_ids` into scatter indices via `expand_dims`. - Build the output shape from `num_segments` or constant `segment_ids`. - Initialize the scatter base tensor with the correct reduction identity. ### Tests Add TFLite frontend tests for: - `test_segment_sum` - `test_unsorted_segment_min` - `test_unsorted_segment_prod` Each test verifies the imported Relax IR lowers to `R.scatter_nd` with the expected reduction mode and base tensor initialization. ## Testing All targeted tests pass: ```bash python -m pytest \ tests/python/relax/test_frontend_tflite.py::test_scatter_nd \ tests/python/relax/test_frontend_tflite.py::test_segment_sum \ tests/python/relax/test_frontend_tflite.py::test_unsorted_segment_min \ tests/python/relax/test_frontend_tflite.py::test_unsorted_segment_prod \ -q ``` ## References - Issue #19412: TFLite Relax frontend operator support tracking - Related PR #19490: Adds SCATTER_ND support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for the
SCATTER_NDoperator in the Relax TFLite frontend.Key Changes:
convert_scatter_ndto parseindicesandupdates.to_int_listandrelax.op.tensor_to_shape.relax.op.zerosto initialize the base array based on theupdatesprecision dtype.SCATTER_NDto the correspondingrelax.op.scatter_nd()target.convert_mapand provided the matching unit test in test_frontend_tflite.py.Testing:
Passed unit tests
Related to #19412