Aharrypotter opened a new pull request, #20114:
URL: https://github.com/apache/tvm/pull/20114
## Summary
This PR adds Relax TFLite frontend support for the remaining StableHLO shape
operators tracked by #19519:
- `STABLEHLO_RESHAPE` -> `R.reshape`
- `STABLEHLO_SLICE` -> `R.strided_slice`
- `STABLEHLO_TRANSPOSE` -> `R.permute_dims`
It carries forward the implementation from #19869 by @Mohxen onto the current
`main` branch and addresses the outstanding review feedback by using explicit
`ValueError` checks for the input and output arity of all three new
converters.
## Design
### StableHLO reshape
`STABLEHLO_RESHAPE` has one tensor input and a statically described result
shape. The converter reads that shape from the TFLite output tensor metadata
and emits `relax.op.reshape`.
### StableHLO slice
`STABLEHLO_SLICE` stores `start_indices`, `limit_indices`, and `strides` in
`StablehloSliceOptions`. The converter parses those vectors, applies them to
all
input axes, and emits `relax.op.strided_slice`.
### StableHLO transpose
`STABLEHLO_TRANSPOSE` stores its permutation in
`StablehloTransposeOptions`. The converter parses the permutation and emits
`relax.op.permute_dims`.
## Operator Support
| Operator | TFLite metadata | Relax lowering | Supported subset |
|---|---|---|---|
| `STABLEHLO_RESHAPE` | output tensor shape | `R.reshape` | static result
shape |
| `STABLEHLO_SLICE` | start, limit, and stride vectors | `R.strided_slice` |
static slice attributes |
| `STABLEHLO_TRANSPOSE` | permutation vector | `R.permute_dims` | static
permutation |
## Tests
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:
```bash
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" -q
```
Result:
```text
ruff format --check: 2 files already formatted
ruff check: All checks passed
py_compile: passed
targeted StableHLO shape tests: 3 passed, 551 deselected
```
## References
- Completes the remaining StableHLO shape-operator items in #19519.
- Continues and supersedes #19869 by @Mohxen.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]