tvm icon indicating copy to clipboard operation
tvm copied to clipboard

[Tracking Issue][TFlite] Expand Missing / Partial Operator Coverage

Open tlopex opened this issue 7 months ago • 22 comments

Background

Excited to see the huge progress the community has made on the Relax TFLite frontend recently — many operators and tests have landed in the last few weeks. To keep pushing this forward, this issue tracks the remaining operator gap so contributors can pick up well-scoped items in parallel.

A. Good-first-issues — drop-in mappings

Workflow: add a handler, wire into convert_map (alphabetical within its region), add one verify(TestClass, Expected) test in tests/python/relax/test_frontend_tflite.py (pattern at L55). All target Relax ops already exist — no new op work needed.

  • [x] CUMSUM → relax.op.cumsum
  • [x] UNIQUE → relax.op.unique
  • [x] SCATTER_ND → relax.op.scatter_nd
  • [x] BROADCAST_TO → relax.op.broadcast_to
  • [x] SIGN → relax.op.sign
  • [x] BITWISE_XOR → relax.op.bitwise_xor
  • [x] RIGHT_SHIFT → relax.op.right_shift
  • [x] BUCKETIZE → relax.op.bucketize
  • [x] EMBEDDING_LOOKUP → relax.op.take
  • [x] SELECT_V2 → relax.op.where
  • [x] RELU_0_TO_1 → relax.op.clip
  • [x] NON_MAX_SUPPRESSION_V4 → port from existing convert_nms_v5

B. Medium — may need new Relax op or non-trivial decomposition

Prefer composing with existing Relax ops over adding a new op. Only register a new relax.op.* when the semantics genuinely cannot be expressed by existing primitives (e.g. random generators, bit-level reinterpret). If a decomposition using existing ops is feasible, go with that — it's a smaller PR and avoids bloating the op set.

  • [x] REDUCE_ANY — commented at tflite_frontend.py:198; can be lowered to relax.op.max on a bool tensor, no new op needed
  • [x] REDUCE_ALL — same, lower to relax.op.min on bool
  • [ ] RANK — emit relax.const(ndim) for static shapes; no op call needed
  • [x] ATAN2 — compose from atan + sign + where, or add relax.op.atan2 for a cleaner impl
  • [x] SEGMENT_SUM — reuse relax.op.scatter_nd with reduction="add" (TFLite requires sorted segment ids)
  • [ ] UNSORTED_SEGMENT_SUM — scatter_nd(reduction="add")
  • [ ] UNSORTED_SEGMENT_MAX — scatter_nd(reduction="max")
  • [x] UNSORTED_SEGMENT_MIN — scatter_nd(reduction="min")
  • [x] UNSORTED_SEGMENT_PROD — scatter_nd(reduction="mul")
  • [ ] DYNAMIC_UPDATE_SLICE — reuse relax.op.slice_scatter
  • [x] DILATE — likely needs a new op (or decompose via pad + strided_slice)
  • [x] MULTINOMIAL — wrap existing relax.op.multinomial_from_uniform; blocked on RANDOM_UNIFORM
  • [x] RANDOM_STANDARD_NORMAL — needs a new random-generator op in Relax
  • [x] RANDOM_UNIFORM — same
  • [x] BITCAST — needs a new reinterpret/view op
  • [x] BROADCAST_ARGS — shape-level computation; consider static-shape-only path first

C. Fix partial implementations

These ops are already in convert_map but their handler raises OpNotImplemented on certain input patterns, making them unusable on real models that hit those patterns.

  • [x] RANGE — handler raises on dynamic scalar inputs (tflite_frontend.py:958); should lower to relax.op.arange.
  • [x] FILL — handler raises when dims is non-constant (L1729); should lower to relax.op.full with a dynamic shape
  • [x] SPLIT_V — handler raises when size_splits is non-constant (L2267); decompose into dynamic strided slices.
  • [x] NON_MAX_SUPPRESSION_V5 — handler raises on soft-NMS (L3546); needs soft_nms_sigma != 0 support
  • [ ] FAKE_QUANT — handler raises on some narrow-range vector configs (L3913)

Contributor workflow

  1. Claim an item by commenting on this issue before starting, so we avoid duplicated work.
  2. Read a recent reference PR for handler + test style.
  3. Add the handler, register in convert_map (alphabetical within its region).
  4. Add a structural-equal test following the verify(TestClass, Expected) pattern (test_frontend_tflite.py:55). Nightly-gated E2E activates automatically via CI_ENV_NIGHTLY.
  5. Tag the PR title [Relax][Frontend][TFLite].

cc @leandron

tlopex avatar Apr 16 '26 23:04 tlopex

Claiming B: REDUCE_ANY and REDUCE_ALL — will lower to relax.op.max / relax.op.min on a bool tensor as suggested, and bundle them into a single PR.

swjng avatar Apr 17 '26 03:04 swjng

Hi @tlopex , I'd like to claim NON_MAX_SUPPRESSION_V5 under "Fix partial implementations" to add support for soft_nms_sigma != 0. I will open a PR with the implementation and tests soon.

Aharrypotter avatar Apr 17 '26 04:04 Aharrypotter

Hi @tlopex, I'd like to claim the following tasks: A. Good-first-issues: BITWISE_XOR → relax.op.bitwise_xor RIGHT_SHIFT → relax.op.right_shift RELU_0_TO_1 → relax.op.clip B. Medium: RANK — will emit relax.const for static shapes UNSORTED_SEGMENT_MAX — will use relax.op.scatter_nd with reduction="max" I'll open PRs for these implementations soon.

Dayuxiaoshui avatar Apr 19 '26 14:04 Dayuxiaoshui

Hi @tlopex , I'd like to claim FILL and SPLIT_V under "Fix partial implementations" . I will open a PR with the implementation and tests soon.

Aharrypotter avatar Apr 19 '26 17:04 Aharrypotter

Hi @tlopex , I'd like to claim CUMSUM under "A. Good-first-issues". I will open a PR with the implementation and test soon.

Peruere1828 avatar Apr 23 '26 16:04 Peruere1828

Hi @tlopex I’d claim FAKE_QUANT and RANGE in one pr and from A UNIQUE , BUCKETIZE and SIGN

0xjah avatar Apr 24 '26 10:04 0xjah

HI @tlopex,, i'd like to work on SCATTER_ND, BROADCAST_TO, EMBEDDING_LOOKUP and SELECT_V2

rknastenka avatar Apr 25 '26 11:04 rknastenka

Hi @tlopex , I’d like to work on UNSORTED_SEGMENT_SUM under the medium category. I’ll submit a PR with implementation and tests soon. Please let me know if it’s already being worked on.

snigenigmatic avatar Apr 25 '26 16:04 snigenigmatic

Hi @tlopex, I'd like to claim NON_MAX_SUPPRESSION_V4 under section A. PR coming shortly.

as4230 avatar Apr 28 '26 12:04 as4230

Hi @tlopex, I'd like to claim BITCAST under section B.

as4230 avatar Apr 28 '26 13:04 as4230

Hi @tlopex , I'd like to claim ATAN2 and DILATE under section B.

as4230 avatar Apr 29 '26 04:04 as4230

Hi @tlopex, I'd like to claim MULTINOMIAL, RANDOM_STANDARD_NORMAL, and RANDOM_UNIFORM under "B. Medium — may need new Relax op or non-trivial decomposition". I will open a PR with the implementation and tests soon.

Aharrypotter avatar Apr 29 '26 15:04 Aharrypotter

Hi @tlopex , I'd like to claim BROADCAST_ARGS under section B

as4230 avatar Apr 30 '26 23:04 as4230

Hi @tlopex, I'd like to claim the remaining unclaimed segment ops under section B: SEGMENT_SUM, UNSORTED_SEGMENT_MIN, and UNSORTED_SEGMENT_PROD. All three lower to relax.op.scatter_nd and will be in one PR.

as4230 avatar May 01 '26 05:05 as4230

Hi @tlopex,

I'd like to claim the following tasks related to scatter and slice updates:

Under B. Medium:

  • SEGMENT_SUM
  • UNSORTED_SEGMENT_MIN
  • UNSORTED_SEGMENT_PROD

I plan to map the segment operators to relax.op.scatter_nd with their respective reduction modes. I will bundle these together and open a PR with the implementation and tests soon!

Aharrypotter avatar May 01 '26 05:05 Aharrypotter

Hi @tlopex, I'd like to claim the following tasks: A. Good-first-issues: BITWISE_XOR → relax.op.bitwise_xor RIGHT_SHIFT → relax.op.right_shift RELU_0_TO_1 → relax.op.clip B. Medium: RANK — will emit relax.const for static shapes UNSORTED_SEGMENT_MAX — will use relax.op.scatter_nd with reduction="max" I'll open PRs for these implementations soon.

Hi @Dayuxiaoshui, since I'm currently working on bundling the other segment and scatter-related ops (SCATTER_ND, SEGMENT_SUM, UNSORTED_SEGMENT_MIN/PROD) into a single PR using relax.op.scatter_nd, would you mind if I include UNSORTED_SEGMENT_MAX in my batch as well to keep the implementation and tests unified?

If you are already halfway through it or prefer to handle it yourself, no worries at all! Just wanted to offer in case it saves you some time for your other claimed tasks.

Aharrypotter avatar May 01 '26 06:05 Aharrypotter

Hi @tlopex, I'd like to claim the remaining unclaimed segment ops under section B: SEGMENT_SUM, UNSORTED_SEGMENT_MIN, and UNSORTED_SEGMENT_PROD. All three lower to relax.op.scatter_nd and will be in one PR.

Hey @as4230, my bad! Looks like we commented pretty close to each other. I had the tab open without refreshing, and I didn't double-check the thread after I posted, so I totally missed your claim.

I actually already finished the code and tests for this batch locally. Would you mind if I just submit the PR since it's ready to go?

If you'd prefer to handle it yourself though, no worries at all! Sorry for the overlap.

Aharrypotter avatar May 01 '26 17:05 Aharrypotter

@Aharrypotter All good, it happens. If everything's ready then go ahead and get the PR in.

as4230 avatar May 01 '26 17:05 as4230

Hi @tlopex, I’d like to help close out the remaining unmerged items in this tracking issue.

I noticed a few of the unchecked items were claimed back in April, but I could not find corresponding merged PRs for them, and the issue has been quiet for several weeks. To avoid leaving the tracking issue stalled, I plan to work on the remaining gaps in one cleanup PR:

  • UNIQUE, SIGN, BITWISE_XOR, RIGHT_SHIFT, BUCKETIZE, RELU_0_TO_1
  • RANK, UNSORTED_SEGMENT_SUM, UNSORTED_SEGMENT_MAX
  • RANGE dynamic scalar inputs and FAKE_QUANT narrow_range/vector coverage
  • DYNAMIC_UPDATE_SLICE status cleanup, depending on the current TFLite schema support

If anyone is already actively working on any of these, happy to coordinate or drop that part.

Aharrypotter avatar Jun 17 '26 09:06 Aharrypotter

Hi @tlopex, I’d like to help close out the remaining unmerged items in this tracking issue.

I noticed a few of the unchecked items were claimed back in April, but I could not find corresponding merged PRs for them, and the issue has been quiet for several weeks. To avoid leaving the tracking issue stalled, I plan to work on the remaining gaps in one cleanup PR:

  • UNIQUE, SIGN, BITWISE_XOR, RIGHT_SHIFT, BUCKETIZE, RELU_0_TO_1
  • RANK, UNSORTED_SEGMENT_SUM, UNSORTED_SEGMENT_MAX
  • RANGE dynamic scalar inputs and FAKE_QUANT narrow_range/vector coverage
  • DYNAMIC_UPDATE_SLICE status cleanup, depending on the current TFLite schema support

If anyone is already actively working on any of these, happy to coordinate or drop that part.

Hi @tlopex — following up on my earlier comment. I went back through the remaining unchecked boxes; with the PRs below, all of them are now addressed. Quick status:

A. Good-first-issues — all landed & tested

  • CUMSUM (#19434), UNIQUE, SIGN, BITWISE_XOR, RIGHT_SHIFT, BUCKETIZE, RELU_0_TO_1 (all in #19813)

B. Medium — all landed & tested

  • RANK, UNSORTED_SEGMENT_SUM, UNSORTED_SEGMENT_MAX (#19813); the other segment ops landed earlier in #19491
  • DYNAMIC_UPDATE_SLICE — runtime (dynamic) start indices now supported in #19881 (builds the scatter_nd index grid in-graph with StableHLO clamping; the static path from #19587 is unchanged)

C. Fix partial implementations

  • FAKE_QUANT — #19813 fixed the handler crashing on a non-existent relax.op.const call (switched to relax.const), which had broken the op on every invocation, and added test_fake_quant_narrow_range_vector as a regression test. The builtin FAKE_QUANT parameter space (scalar min/max, narrow_range, num_bits) is fully supported (the builtin op has no per-channel/vector min/max).
  • RANGE — runtime (dynamic) scalar bounds now supported in #19867, for both integer and float, ascending or descending.

Both dynamic-input items fit cleanly in the frontend: RANGE via tensor_to_shape + match_cast, DYNAMIC_UPDATE_SLICE via scatter_nd with runtime indices. No new Relax op was needed.

Suggest closing this issue once #19881 merges. Please let me know if I've mischaracterized anything.

Aharrypotter avatar Jun 24 '26 09:06 Aharrypotter