You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "rknastenka (via GitHub)" <gi...@apache.org> on 2026/04/13 10:54:44 UTC
[PR] [Frontend][TFLite] Add test coverage for SHAPE and RANGE operators [tvm]
rknastenka opened a new pull request, #19401:
URL: https://github.com/apache/tvm/pull/19401
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.**
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Frontend][TFLite] Add test coverage for SHAPE and RANGE operators [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #19401:
URL: https://github.com/apache/tvm/pull/19401
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Frontend][TFLite] Add test coverage for SHAPE and RANGE operators [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19401:
URL: https://github.com/apache/tvm/pull/19401#discussion_r3072499289
##########
python/tvm/relax/frontend/tflite/tflite_frontend.py:
##########
@@ -951,7 +974,12 @@ def convert_shape(self, op):
shape_options = ShapeOptions()
shape_options.Init(op_options.Bytes, op_options.Pos)
- out = relax.op.shape_of(self.get_tensor_expr(input_tensors[0]))
+ # SHAPE must materialize as a tensor output in Relax, not just symbolic shape info.
+ out = relax.op.shape_to_tensor(relax.op.shape_of(self.get_tensor_expr(input_tensors[0])))
+ if shape_options.OutType() == TensorType.INT32:
+ out = relax.op.astype(out, "int32")
+ elif shape_options.OutType() == TensorType.INT64:
+ out = relax.op.astype(out, "int64")
Review Comment:

The `relax.op.shape_to_tensor` operator returns a tensor of dtype `int64` by default. Therefore, the explicit cast to `int64` when `shape_options.OutType()` is `TensorType.INT64` is redundant and can be removed.
```suggestion
if shape_options.OutType() == TensorType.INT32:
out = relax.op.astype(out, "int32")
```
##########
python/tvm/relax/frontend/tflite/tflite_frontend.py:
##########
@@ -925,15 +925,37 @@ def convert_range(self, op):
start, limit, delta = input_tensors[0], input_tensors[1], input_tensors[2]
- expressions = [self.get_tensor_expr(t) for t in [start, limit, delta]]
-
+ def get_scalar_value(tensor):
+ if self.has_expr(tensor.tensor_idx):
+ expr = self.get_expr(tensor.tensor_idx)
+ if isinstance(expr, relax.Constant):
+ value = expr.data.numpy()
+ else:
+ # relax.op.arange currently expects scalar-like values here.
+ # Keep dynamic scalar RANGE explicit until frontend support is added.
+ raise tvm.error.OpNotImplemented(
+ "TFLite RANGE with dynamic scalar inputs is not supported in Relax frontend yet."
+ )
+ else:
+ value = self.get_tensor_value(tensor)
+
+ if isinstance(value, np.ndarray):
+ # TFLite RANGE operands are scalar tensors in the flatbuffer.
+ assert value.size == 1, "RANGE scalar input must have exactly one element"
+ return value.item()
+ return value
Review Comment:

The `isinstance(value, np.ndarray)` check appears to be redundant. Both `expr.data.numpy()` from a `relax.Constant` and `self.get_tensor_value(tensor)` return a `numpy.ndarray`, so `value` will always be a numpy array at this point.
This also means the `return value` statement on line 946 is unreachable.
You can simplify this part by removing the conditional check and the unreachable branch.
```python
# TFLite RANGE operands are scalar tensors in the flatbuffer.
assert value.size == 1, "RANGE scalar input must have exactly one element"
return value.item()
```
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Frontend][TFLite] Add test coverage for SHAPE and RANGE operators [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #19401:
URL: https://github.com/apache/tvm/pull/19401#issuecomment-4238700512
Hi @rknastenka ,could you resolve the conflict so that we can merge it:)
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org