adityasingh2400 commented on PR #20092:
URL: https://github.com/apache/tvm/pull/20092#issuecomment-5196452587
You are right, and thanks for catching it. Fixed in dd1477d.
I confirmed the collapse you describe. `get_info` starts from `shape = []`
and only appends per dim, so it never returns `None`, and `_parse_graph_input`
feeds that straight into `_new_var`. Both an absent shape field and a
present-but-empty one therefore became `R.Tensor(())`, which means my `is None`
check was unreachable for an unknown-rank input and such an input would have
folded to `R.shape([])`.
`get_info` now returns `None` for the shape when
`tensor_type.HasField("shape")` is false. That matches what `TensorType`
already documents, `shape: Optional[Expr]` with `ndim` defaulting to -1 for the
unknown-rank form, so `_new_var(shape=None)` produces a tensor with no static
shape and the `is None` branch in `Shape` becomes reachable and correct. The
call site now also warns on unknown rank, matching the existing warning for
unknown dimensions.
I checked the premise against real protos rather than assuming:
| input | `HasField("shape")` | dims |
|---|---|---|
| `make_tensor_value_info(..., [])` rank-0 | True | 0 |
| `make_tensor_value_info(..., None)` unknown rank | False | 0 |
| `make_tensor_value_info(..., [2, 3])` | True | 2 |
Added `test_shape_unknown_rank_input`, which asserts the input keeps `shape
is None` and `ndim == -1` rather than becoming rank-0, and that `Shape` still
emits `relax.shape_of`. It also asserts the absent shape field up front so the
test cannot silently stop covering the case.
One caveat on verification: I could not run the ONNX frontend tests locally,
since that needs a built TVM. The proto behaviour above is measured, the rest
is reasoned from `get_info`'s single call site and the `TensorType` contract,
so CI is the real check here. Happy to iterate if it comes back unhappy.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]