Skip to content

[Frontend][TFLite] Add test coverage for SHAPE and RANGE operators#19401

Open
rknastenka wants to merge 4 commits intoapache:mainfrom
rknastenka:rshape
Open

[Frontend][TFLite] Add test coverage for SHAPE and RANGE operators#19401
rknastenka wants to merge 4 commits intoapache:mainfrom
rknastenka:rshape

Conversation

@rknastenka
Copy link
Copy Markdown
Contributor

Initial goal was to add SHAPE and RANGE tests, solving part of #18971

This PR achieves that and includes the minimum necessary frontend fixes discovered during implementation so those tests reflect real supported behavior instead of xfail/workarounds.

so this PR includes both:
1. New SHAPE/RANGE tests
2. Targeted frontend fixes required to make those tests pass correctly

Why These Changes Were Needed

  • SHAPE conversion previously produced symbolic shape info instead of a tensor output aligned with TFLite SHAPE semantics.
  • RANGE conversion passed tensor expressions into arange instead of scalar values for constant scalar bounds.
  • Zero-input TFLite subgraphs (valid for constant-only models such as RANGE without inputs) were blocked by a strict assertion.
  • Model output collection was brittle for constant/prefetched outputs and could fail when output expressions were not already in the expr table.
  • As a result, i could not add meaningful SHAPE/RANGE coverage without fixing frontend behavior.

Modifications

Frontend Changes (In tflite_frontend.py):

  • Updated convert_shape: SHAPE now materializes shape output as a tensor using shape_to_tensor(shape_of(...))
  • Applies output dtype casting based on ShapeOptions OutType (int32/int64)
  • Updated convert_range: Extracts scalar values for start/limit/delta from scalar constants
  • Calls arange with scalar-like values
  • Keeps dynamic scalar RANGE explicit as unsupported (raises OpNotImplemented with clear message)
  • Updated _input_type: Removed assumption that every subgraph must have at least one input
  • Supports valid zero-input subgraphs
  • Updated from_tflite output assembly: Resolves outputs via tensor wrappers and get_tensor_expr instead of direct expr-table lookup by name

Main functional changes are localized to SHAPE/RANGE conversion and model output/input handling.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the TFLite frontend for Relax by implementing support for the SHAPE and RANGE operators. It also updates subgraph processing to allow zero inputs and improves output resolution to correctly handle constant or prefetched tensors. The review feedback identifies opportunities to simplify the code by removing redundant type checks in the RANGE operator implementation and omitting an unnecessary cast to int64 for SHAPE outputs, given the default behavior of the underlying operator.

rknastenka and others added 3 commits April 13, 2026 14:02
@tlopex
Copy link
Copy Markdown
Member

tlopex commented Apr 13, 2026

Hi @rknastenka ,could you resolve the conflict so that we can merge it:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants