Throw for scalar input to Shape. #18504
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Shape returns an empty tensor with shape {0} for a scalar, which is incorrect as there is a single data element. Throwing will at least make the cause of the failure clear.
Expected might be for it to return a shape of
{}
, but ONNX shape inferencing doesn't support scalar either as it calls add_dim on the output_shape at the start so result will always be rank 1 or higher.https://github.com/onnx/onnx/blob/b60f69412abb5393ab819b936b473f83867f6c87/onnx/defs/tensor/defs.cc#L496
The ONNX spec doesn't say scalars aren't supported. @gramalingam should scalar input to Shape return an empty shape?
Motivation and Context
Model failed downstream due to nullptr in output from Shape when called with a scalar.