[Relax][Frontend][TFLite] Support StableHLO shape ops - #20114
[Relax][Frontend][TFLite] Support StableHLO shape ops#20114Aharrypotter wants to merge 2 commits into
Conversation
Co-authored-by: Mohxen <mohsenrahmati@icloud.com>
|
@tlopex cc |
tlopex
left a comment
There was a problem hiding this comment.
Overall this looks good, but there are a couple of missing edge cases around COMPLEX64. Relax represents complex tensors with an extra trailing size-2 axis, so reshape needs to use _get_relax_tensor_shape, and transpose needs to append that pair axis to the permutation. Using the raw TFLite output shape also breaks rank-0 reshape outputs. Could we handle those cases and add scalar/complex tests?
Done. |
Summary
This PR adds Relax TFLite frontend support for the remaining StableHLO shape
operators tracked by #19519:
STABLEHLO_RESHAPE->R.reshapeSTABLEHLO_SLICE->R.strided_sliceSTABLEHLO_TRANSPOSE->R.permute_dimsIt carries forward the implementation from #19869 by @Mohxen onto the current
mainbranch and addresses the outstanding review feedback by using explicitValueErrorchecks for the input and output arity of all three new converters.Design
StableHLO reshape
STABLEHLO_RESHAPEhas one tensor input and a statically described resultshape. The converter reads that shape from the TFLite output tensor metadata
and emits
relax.op.reshape.StableHLO slice
STABLEHLO_SLICEstoresstart_indices,limit_indices, andstridesinStablehloSliceOptions. The converter parses those vectors, applies them to allinput axes, and emits
relax.op.strided_slice.StableHLO transpose
STABLEHLO_TRANSPOSEstores its permutation inStablehloTransposeOptions. The converter parses the permutation and emitsrelax.op.permute_dims.Operator Support
STABLEHLO_RESHAPER.reshapeSTABLEHLO_SLICER.strided_sliceSTABLEHLO_TRANSPOSER.permute_dimsTests
The tests manually build minimal TFLite flatbuffers for each StableHLO
operator and compare the imported Relax IR with
tvm.ir.assert_structural_equal. The slice fixture exercises non-unit strides,and the transpose fixture uses a nontrivial three-dimensional permutation.
Local validation:
python -m ruff format --check \ 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 py_compile \ 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 "stablehlo_reshape or stablehlo_slice or stablehlo_transpose" -qResult:
References