Skip to content

[Relax][Frontend][TFLite] Support StableHLO shape ops#19869

Open
Mohxen wants to merge 2 commits into
apache:mainfrom
Mohxen:stablehlo-reshape
Open

[Relax][Frontend][TFLite] Support StableHLO shape ops#19869
Mohxen wants to merge 2 commits into
apache:mainfrom
Mohxen:stablehlo-reshape

Conversation

@Mohxen

@Mohxen Mohxen commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Adds Relax TFLite frontend support for the remaining StableHLO shape operators:

  • STABLEHLO_RESHAPE -> R.reshape
  • STABLEHLO_SLICE -> R.strided_slice
  • STABLEHLO_TRANSPOSE -> R.permute_dims

Related to #19519.

Testing

  • python -m ruff check python/tvm/relax/frontend/tflite/tflite_frontend.py tests/python/relax/test_frontend_tflite.py
  • python -m py_compile python/tvm/relax/frontend/tflite/tflite_frontend.py tests/python/relax/test_frontend_tflite.py
  • git diff --check

Related to #19519.

@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 support for converting the STABLEHLO_RESHAPE operator to Relax in the TFLite frontend, including corresponding unit tests. The feedback suggests replacing the assert statements in the new conversion function with explicit ValueError checks to ensure validation is not bypassed when Python is run with optimization flags.

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 +3020 to +3023
input_tensors = self.get_input_tensors(op)
assert len(input_tensors) == 1
output_tensors = self.get_output_tensors(op)
assert len(output_tensors) == 1

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

Using assert statements for input validation is discouraged because they can be optimized away when Python is run with the -O (optimize) flag. This would bypass the validation checks entirely and could lead to cryptic errors (like IndexError) later in the execution. It is safer and more robust to explicitly check the conditions and raise a ValueError with a descriptive error message.

Suggested change
input_tensors = self.get_input_tensors(op)
assert len(input_tensors) == 1
output_tensors = self.get_output_tensors(op)
assert len(output_tensors) == 1
input_tensors = self.get_input_tensors(op)
if len(input_tensors) != 1:
raise ValueError(f"STABLEHLO_RESHAPE expects exactly 1 input tensor, but got {len(input_tensors)}")
output_tensors = self.get_output_tensors(op)
if len(output_tensors) != 1:
raise ValueError(f"STABLEHLO_RESHAPE expects exactly 1 output tensor, but got {len(output_tensors)}")

@Mohxen Mohxen changed the title [Relax][Frontend][TFLite] Support STABLEHLO_RESHAPE [Relax][Frontend][TFLite] Support StableHLO shape ops Jun 27, 2026
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