The GitHub Actions job "Lint" on tvm.git/main has failed.
Run started by GitHub user tlopex (triggered by tlopex).

Head commit for run:
0eaf1cb019f8bd2bcb225b92aaa36d2878b19a16 / Arpit Jain 
<[email protected]>
[Relax][ONNX] Import Min/Max/Sum/Mean when an input has no static shape (#20288)

Fixes #20280.

`MultiInputBase._impl_v1` reads `inp.ty.shape` for every input and folds
them with `compute_broadcast_shape`, which starts with `len(shape_a)`.
Relax spells an unknown static shape `R.Tensor(dtype=..., ndim=k)`,
whose struct info carries `shape=None`, so `len(None)` raises
`TypeError: object of type 'NoneType' has no len()`. That state is not
exotic: `R.dynamic_strided_slice` produces it, so a plain ONNX `Slice`
with runtime `starts`/`ends` feeding a `Max` is enough, on a model
`onnx.checker.check_model(..., full_check=True)` accepts and onnxruntime
executes.

ONNX defines Min, Max, Sum and Mean as elementwise with multidirectional
broadcasting, so when a static target shape cannot be computed the ops
are folded pairwise instead and the binary op broadcasts. `Mean` divides
by the input count afterwards. The known-shape path is untouched, and
single-input nodes now come back as the input itself rather than
tripping the `Found null pointer node` assertion that the
stack-and-reduce path hits with an unknown shape.

Verification. I do not have a source build handy, so I ran the release
wheel (`apache-tvm` 0.26.0, arm64) with this file's `main` version of
`_normalize_shape_dim`, `_broadcast_shape_dims`,
`compute_broadcast_shape` and `MultiInputBase` transplanted in, once
without the change and once with it. That runs `main`'s exact Python
logic for this path against a real runtime.

Across `{Min, Max, Sum, Mean}` x `{1, 2, 3}` inputs, all twelve fail
before and all twelve import after:

Max n=1: FAILED InternalError: Check failed: (n.defined()) is false:
Found null pointer node
    Max   n=2: FAILED TypeError: object of type 'NoneType' has no len()

The new `test_multi_input_unknown_static_shape` covers the same matrix
and shows 12 failed / 12 passed the same way. The existing `-k
multi_input` tests are 37 passed with the change in place, so the static
and symbolic paths are unaffected.

One thing worth being explicit about: this fixes the import, not
end-to-end lowering. The imported IR is `R.maximum(lv8, y)` where `lv8`
is `R.Tensor(dtype="float32", ndim=2)`, and `tvm.compile` on it still
fails with `CodeGenVM cannot handle this intrinsic now: relax.maximum`.
That is not new or specific to these ops: the same graph with `Add` in
place of `Max` imports today and fails at codegen identically with
`relax.add`. Lowering elementwise ops over an unknown-shape operand is a
separate gap; this change gets Min/Max/Sum/Mean to the same place `Add`
already is, which is what the issue asks for.

Signed-off-by: Arpit Jain <[email protected]>

Report URL: https://github.com/apache/tvm/actions/runs/34187745845

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to