Commit dcbebe7
[Relax][Frontend][TFLite] Add UNIDIRECTIONAL_SEQUENCE_RNN converter (#19601)
## Summary
This PR adds Relax TFLite frontend support for
`UNIDIRECTIONAL_SEQUENCE_RNN` (BuiltinOperator 35), claimed in
[#19519](#19519) Group A.
The op executes a simple RNN cell over a time sequence. The converter
unrolls the time steps at graph-construction time using Relax
primitives.
Cell equation:
```
h_t = fused_activation(x_t @ W.T + h_{t-1} @ Wr.T + b)
```
## Changes
- **Handler**: `convert_unidirectional_sequence_rnn` registered in
`convert_map` (alphabetical, U-region after `UNPACK`)
- **Inputs** (5): `input [batch, time, input_size]`, `input_weights
[num_units, input_size]`, `recurrent_weights [num_units, num_units]`,
`bias [num_units]`, `hidden_state [batch, num_units]` (variable,
zero-initialised)
- **Output**: `[batch, time, num_units]` (always batch-major)
- **time_major=True**: input is transposed to batch-major before
unrolling
- **Activations**: NONE, RELU, RELU6, TANH, SIGMOID (via
`convert_fused_activation_function`)
- **Quantized**: raises `OpNotImplemented` (not yet supported)
## Testing
Modern TF/Keras (2.x, Keras 3) no longer emits
`UNIDIRECTIONAL_SEQUENCE_RNN`; `SimpleRNN` with `unroll=False` lowers to
`WHILE`+TensorList ops, and `unroll=True` expands to elementwise ops.
Tests therefore follow the same flatbuffer-construction pattern used by
the StableHLO op PRs (#19536, #19587).
Three tests added to `tests/python/relax/test_frontend_tflite.py`:
- `test_unidirectional_sequence_rnn_none_activation` —
`tvm.ir.assert_structural_equal` with identity weights / zero bias, NONE
activation, time=1
- `test_unidirectional_sequence_rnn_relu_activation` — shape check,
random weights, RELU activation, time=3
- `test_unidirectional_sequence_rnn_time_major` — shape check,
`time_major=True` input layout
```bash
python -m pytest tests/python/relax/test_frontend_tflite.py -k unidirectional_sequence_rnn -v
```
All 3 tests pass. pre-commit (ASF header, ruff check, ruff format) all
pass.
## References
- Issue [#19519](#19519) Group A:
Sequence / recurrent model operators
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent fa66213 commit dcbebe7
2 files changed
Lines changed: 308 additions & 0 deletions
File tree
- python/tvm/relax/frontend/tflite
- tests/python/relax
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| 384 | + | |
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
| |||
4877 | 4878 | | |
4878 | 4879 | | |
4879 | 4880 | | |
| 4881 | + | |
| 4882 | + | |
| 4883 | + | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
| 4909 | + | |
| 4910 | + | |
| 4911 | + | |
| 4912 | + | |
| 4913 | + | |
| 4914 | + | |
| 4915 | + | |
| 4916 | + | |
| 4917 | + | |
| 4918 | + | |
| 4919 | + | |
| 4920 | + | |
| 4921 | + | |
| 4922 | + | |
| 4923 | + | |
| 4924 | + | |
| 4925 | + | |
| 4926 | + | |
| 4927 | + | |
| 4928 | + | |
| 4929 | + | |
| 4930 | + | |
| 4931 | + | |
| 4932 | + | |
| 4933 | + | |
| 4934 | + | |
| 4935 | + | |
| 4936 | + | |
| 4937 | + | |
| 4938 | + | |
| 4939 | + | |
| 4940 | + | |
| 4941 | + | |
| 4942 | + | |
| 4943 | + | |
| 4944 | + | |
| 4945 | + | |
| 4946 | + | |
| 4947 | + | |
| 4948 | + | |
| 4949 | + | |
| 4950 | + | |
| 4951 | + | |
| 4952 | + | |
| 4953 | + | |
| 4954 | + | |
| 4955 | + | |
| 4956 | + | |
| 4957 | + | |
| 4958 | + | |
| 4959 | + | |
| 4960 | + | |
| 4961 | + | |
| 4962 | + | |
| 4963 | + | |
| 4964 | + | |
| 4965 | + | |
| 4966 | + | |
| 4967 | + | |
| 4968 | + | |
| 4969 | + | |
| 4970 | + | |
| 4971 | + | |
| 4972 | + | |
| 4973 | + | |
| 4974 | + | |
| 4975 | + | |
| 4976 | + | |
| 4977 | + | |
| 4978 | + | |
| 4979 | + | |
| 4980 | + | |
4880 | 4981 | | |
4881 | 4982 | | |
4882 | 4983 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3720 | 3720 | | |
3721 | 3721 | | |
3722 | 3722 | | |
| 3723 | + | |
| 3724 | + | |
3723 | 3725 | | |
3724 | 3726 | | |
3725 | 3727 | | |
| |||
9719 | 9721 | | |
9720 | 9722 | | |
9721 | 9723 | | |
| 9724 | + | |
| 9725 | + | |
| 9726 | + | |
| 9727 | + | |
| 9728 | + | |
| 9729 | + | |
| 9730 | + | |
| 9731 | + | |
| 9732 | + | |
| 9733 | + | |
| 9734 | + | |
| 9735 | + | |
| 9736 | + | |
| 9737 | + | |
| 9738 | + | |
| 9739 | + | |
| 9740 | + | |
| 9741 | + | |
| 9742 | + | |
| 9743 | + | |
| 9744 | + | |
| 9745 | + | |
| 9746 | + | |
| 9747 | + | |
| 9748 | + | |
| 9749 | + | |
| 9750 | + | |
| 9751 | + | |
| 9752 | + | |
| 9753 | + | |
| 9754 | + | |
| 9755 | + | |
| 9756 | + | |
| 9757 | + | |
| 9758 | + | |
| 9759 | + | |
| 9760 | + | |
| 9761 | + | |
| 9762 | + | |
| 9763 | + | |
| 9764 | + | |
| 9765 | + | |
| 9766 | + | |
| 9767 | + | |
| 9768 | + | |
| 9769 | + | |
| 9770 | + | |
| 9771 | + | |
| 9772 | + | |
| 9773 | + | |
| 9774 | + | |
| 9775 | + | |
| 9776 | + | |
| 9777 | + | |
| 9778 | + | |
| 9779 | + | |
| 9780 | + | |
| 9781 | + | |
| 9782 | + | |
| 9783 | + | |
| 9784 | + | |
| 9785 | + | |
| 9786 | + | |
| 9787 | + | |
| 9788 | + | |
| 9789 | + | |
| 9790 | + | |
| 9791 | + | |
| 9792 | + | |
| 9793 | + | |
| 9794 | + | |
| 9795 | + | |
| 9796 | + | |
| 9797 | + | |
| 9798 | + | |
| 9799 | + | |
| 9800 | + | |
| 9801 | + | |
| 9802 | + | |
| 9803 | + | |
| 9804 | + | |
| 9805 | + | |
| 9806 | + | |
| 9807 | + | |
| 9808 | + | |
| 9809 | + | |
| 9810 | + | |
| 9811 | + | |
| 9812 | + | |
| 9813 | + | |
| 9814 | + | |
| 9815 | + | |
| 9816 | + | |
| 9817 | + | |
| 9818 | + | |
| 9819 | + | |
| 9820 | + | |
| 9821 | + | |
| 9822 | + | |
| 9823 | + | |
| 9824 | + | |
| 9825 | + | |
| 9826 | + | |
| 9827 | + | |
| 9828 | + | |
| 9829 | + | |
| 9830 | + | |
| 9831 | + | |
| 9832 | + | |
| 9833 | + | |
| 9834 | + | |
| 9835 | + | |
| 9836 | + | |
| 9837 | + | |
| 9838 | + | |
| 9839 | + | |
| 9840 | + | |
| 9841 | + | |
| 9842 | + | |
| 9843 | + | |
| 9844 | + | |
| 9845 | + | |
| 9846 | + | |
| 9847 | + | |
| 9848 | + | |
| 9849 | + | |
| 9850 | + | |
| 9851 | + | |
| 9852 | + | |
| 9853 | + | |
| 9854 | + | |
| 9855 | + | |
| 9856 | + | |
| 9857 | + | |
| 9858 | + | |
| 9859 | + | |
| 9860 | + | |
| 9861 | + | |
| 9862 | + | |
| 9863 | + | |
| 9864 | + | |
| 9865 | + | |
| 9866 | + | |
| 9867 | + | |
| 9868 | + | |
| 9869 | + | |
| 9870 | + | |
| 9871 | + | |
| 9872 | + | |
| 9873 | + | |
| 9874 | + | |
| 9875 | + | |
| 9876 | + | |
| 9877 | + | |
| 9878 | + | |
| 9879 | + | |
| 9880 | + | |
| 9881 | + | |
| 9882 | + | |
| 9883 | + | |
| 9884 | + | |
| 9885 | + | |
| 9886 | + | |
| 9887 | + | |
| 9888 | + | |
| 9889 | + | |
| 9890 | + | |
| 9891 | + | |
| 9892 | + | |
| 9893 | + | |
| 9894 | + | |
| 9895 | + | |
| 9896 | + | |
| 9897 | + | |
| 9898 | + | |
| 9899 | + | |
| 9900 | + | |
| 9901 | + | |
| 9902 | + | |
| 9903 | + | |
| 9904 | + | |
| 9905 | + | |
| 9906 | + | |
| 9907 | + | |
| 9908 | + | |
| 9909 | + | |
| 9910 | + | |
| 9911 | + | |
| 9912 | + | |
| 9913 | + | |
| 9914 | + | |
| 9915 | + | |
| 9916 | + | |
| 9917 | + | |
| 9918 | + | |
| 9919 | + | |
| 9920 | + | |
| 9921 | + | |
| 9922 | + | |
| 9923 | + | |
| 9924 | + | |
| 9925 | + | |
| 9926 | + | |
| 9927 | + | |
| 9928 | + | |
9722 | 9929 | | |
9723 | 9930 | | |
0 commit comments