tvm icon indicating copy to clipboard operation
tvm copied to clipboard

[Tracking Issue][TFLite] Expand unit test coverage for supported non-quantized operators

Open tlopex opened this issue 8 months ago • 18 comments

We just rebuilt the TFLite frontend.

Today, tests/python/relax/test_frontend_tflite.py already covers a subset of operators, including some via parametrized tests (for example RELU, RELU6, TANH, SOFTMAX, LOGISTIC, ARG_MIN, and ARG_MAX). However, its test coverage is still not enough.

This issue tracks adding operator-focused unit tests for supported non-quantized operators that are still under-tested or currently have no explicit coverage in the Relax TFLite frontend.

Candidate operators to cover

The list below is based on the current Relax frontend implementation and the current contents of tests/python/relax/test_frontend_tflite.py.

Shape / indexing / layout

  • [x] SQUEEZE
  • [x] STRIDED_SLICE
  • [x] SLICE
  • [x] SHAPE
  • [x] SELECT / WHERE
  • [x] GATHER
  • [x] GATHER_ND
  • [x] REVERSE_V2
  • [x] REVERSE_SEQUENCE
  • [x] TILE
  • [x] UNPACK
  • [x] ZEROS_LIKE
  • [x] RANGE
  • [x] SPLIT_V
  • [x] SPACE_TO_BATCH_ND
  • [x] BATCH_TO_SPACE_ND
  • [x] DEPTH_TO_SPACE
  • [x] SPACE_TO_DEPTH

Elementwise / activation / comparison / normalization

  • [x] HARD_SWISH
  • [x] LEAKY_RELU
  • [x] RELU_N1_TO_1
  • [x] PRELU
  • [x] LOG
  • [x] LOG_SOFTMAX
  • [x] SQUARED_DIFFERENCE
  • [x] GREATER
  • [x] GREATER_EQUAL
  • [x] L2_NORMALIZATION
  • [x] LOCAL_RESPONSE_NORMALIZATION

Reductions

  • [x] MEAN
  • [x] REDUCE_MAX
  • [x] REDUCE_MIN
  • [x] REDUCE_PROD
  • [x] SUM

Resize

  • [x] RESIZE_BILINEAR
  • [x] RESIZE_NEAREST_NEIGHBOR

Convolution / linear / pooling

  • [x] FULLY_CONNECTED
  • [x] DEPTHWISE_CONV_2D
  • [x] TRANSPOSE_CONV
  • [x] L2_POOL_2D

Padding / sparse / other

  • [x] PAD
  • [x] PADV2
  • [x] MIRROR_PAD
  • [x] ONE_HOT
  • [x] MATRIX_DIAG
  • [x] MATRIX_SET_DIAG
  • [x] TOPK_V2
  • [x] SPARSE_TO_DENSE
  • [x] DENSIFY (sparse-to-dense tensor; may need a network-level test rather than a simple unit test)

Suggested contribution style

  • Small PRs are welcome. A PR can add coverage for one operator or a small related group of operators.
  • Please reuse the existing test style in tests/python/relax/test_frontend_tflite.py.
  • For simple conversions, checking the generated Relax IR with tvm.ir.assert_structural_equal is preferred. We really appreciate you provide Expected IRModule to test those ops
  • For larger operators, using the existing verify(...) helper pattern is also fine, following current tests in the file.
  • Numerical E2E checks should continue to follow the current nightly-only behavior guarded by CI_ENV_NIGHTLY.

Useful reference

The old Relay test file is a good source of test shapes, edge cases, and operator-specific scenarios:

  • tests/python/frontend/tflite/test_forward.py at commit 292ecfd210

Notes for contributors

This is a good-first-issue / parallelizable tracking issue:

  • each operator test is mostly independent
  • multiple PRs can land in parallel
  • contributors can reference this issue and check off the operator(s) covered by their PR

If you pick this up, please mention which operator(s) your PR adds coverage for. And if you find some issues with existed ops when adding tests, you're welcome to fix them as well!

cc @leandron

tlopex avatar Apr 03 '26 04:04 tlopex

Hi @tlopex — I’d like to pick up Relax TFLite frontend test coverage for these five non-quantized ops: GREATER, GREATER_EQUAL, LOG, SQUEEZE, and ZEROS_LIKE. I’ll follow the existing style in tests/python/relax/test_frontend_tflite.py (structural verify / Expected IR where reasonable). Please let me know if any of these already have an open PR. Thanks!

Dayuxiaoshui avatar Apr 03 '26 07:04 Dayuxiaoshui

Hi @tlopex, I would like to work on the activation/elementwise group. I will add test coverage for HARD_SWISH, LEAKY_RELU, RELU_N1_TO_1, PRELU, LOG, and LOG_SOFTMAX in a single PR. Following the existing assert_structural_equal style with explicit Expected IRModules.

fnhirwa avatar Apr 04 '26 00:04 fnhirwa

Hi @tlopex , i'd like to work on the "Reductions" Group: SUM, MEAN, REDUCE_MAX, REDUCE_MIN, REDUCE_PROD

i'll cover them in one PR

rknastenka avatar Apr 06 '26 08:04 rknastenka

Hi @tlopex, I want to claim RESIZE_BILINEAR and RESIZE_NEAREST_NEIGHBOR

OmarAzizi avatar Apr 06 '26 12:04 OmarAzizi

hey @tlopex I'd claim L2_NORMALIZATION SLICE, REVERSE_V2

0xjah avatar Apr 06 '26 14:04 0xjah

Hi @tlopex, I'd like to claim SHAPE, TILE, and RANGE. I'll submit them together in a single PR.

rknastenka avatar Apr 08 '26 08:04 rknastenka

hey @tlopex I'd claim L2_NORMALIZATION SLICE, REVERSE_V2 and Convolution / linear / pooling I’ll submit the pr soon

0xjah avatar Apr 08 '26 11:04 0xjah

Hi @tlopex, I want to clain SQUARED_DIFFERENCE and LOCAL_RESPONSE_NORMALIZATION

OmarAzizi avatar Apr 08 '26 21:04 OmarAzizi

Hi, I'd like to contribute coverage for the following operators from the Padding / Sparse / Other category:

  • PAD
  • PADV2
  • MIRROR_PAD (REFLECT mode)
  • TOPK_V2
  • ONE_HOT

I also found and fixed two bugs in the existing converter implementations while writing the tests:

  1. convert_mirror_pad: called relax.op.nn.mirror_pad which does not exist in the Relax op namespace. Fixed to use relax.op.nn.pad with pad_mode="reflect" for REFLECT mode.
  2. convert_one_hot: passed on_value/off_value as Expr (constant tensors) where the op signature requires PrimValue, and passed an extra dtype argument that the function does not accept. Fixed to extract the scalar value and wrap in relax.PrimValue.

I'll open a PR shortly.

swjng avatar Apr 09 '26 01:04 swjng

Hi @tlopex, I'd like to claim the following three operators:

  • SELECT / WHERE
  • DEPTH_TO_SPACE
  • SPACE_TO_DEPTH

I'll submit them together in a single PR.

zhengkezhou1 avatar Apr 10 '26 06:04 zhengkezhou1

Hi @tlopex , I would like to claim and work on the following operators:

  • MATRIX_DIAG
  • MATRIX_SET_DIAG
  • SPARSE_TO_DENSE
  • DENSIFY (I noted the requirement that this might need a network-level test rather than a simple unit test, and I will look into it.)

I will add test coverage by PR one by one, following the existing assert_structural_equal style with explicit Expected IRModules.

Aharrypotter avatar Apr 14 '26 01:04 Aharrypotter

hi @tlopex I would like to work on GATHER and GATHER_ND

fnhirwa avatar Apr 14 '26 07:04 fnhirwa

hi @tlopex I'd claim PRELU LOCAL_RESPONSE_NORMALIZATION SQUARED_DIFFERENCE

0xjah avatar Apr 14 '26 23:04 0xjah

hey @tlopex I'd claim and work on STRIDED_SLICE and SPLIT_V

Aharrypotter avatar Apr 19 '26 17:04 Aharrypotter

Hi @tlopex, I'd like to claim the remaining shape/layout ops: REVERSE_SEQUENCE, UNPACK, SPACE_TO_BATCH_ND, and BATCH_TO_SPACE_ND.

rknastenka avatar May 01 '26 14:05 rknastenka

Hi @tlopex, I’d like to pick up TFLite GATHER and GATHER_ND coverage in tests/python/relax/test_frontend_tflite.py (tracking issue #18971). I’ll follow the existing style in the file (explicit expected IRModules + tvm.ir.assert_structural_equal, using verify() if needed) and send a single PR.

weicheng-hsu avatar May 06 '26 18:05 weicheng-hsu

Hi @tlopex, I’d like to pick up the remaining unchecked TFLite non-quantized operator coverage items in this tracking issue:

  • SQUEEZE
  • REVERSE_SEQUENCE
  • UNPACK
  • ZEROS_LIKE

I’ll add them together in one PR, following the existing tests/python/relax/test_frontend_tflite.py style with explicit Expected IRModules / structural equality where practical.

Aharrypotter avatar Jun 17 '26 10:06 Aharrypotter

Thanks everyone for the contributions and discussions! The issue is now resolved.

tlopex avatar Jun 23 '26 19:06 tlopex