onnx
onnx copied to clipboard
Spec: Clarify Transpose
Ask a Question
Question
It is unclear what types of tensors Transpose accepts from the spec. For example, does it accept 1d or 0d tensors as inputs? If so can perm be an empty list? Is perm optional since it has words like "by default"? Does len(perm) need to be rank(input)?
Further information
-
Relevant Area: operators
-
Is this issue related to a specific model?
No
Notes
Hi @justinchuby, I think these corner cases might just be undefined behavior.
does it accept 1d or 0d tensors as inputs?
IIUC, at least from onnx shape inference perspective, they should be both fine case if not giving specified perm.
So can perm be an empty list?
Shape inference will stop if the given perm is an empty list according to this line.
Note that since current ONNX spec does not explicitly disallow these, probably the downstream runtime tools' behavior for these cases might also be undefined (either can work or cannot work).
Is perm optional since it has words like "by default"? Does len(perm) need to be rank(input)?
perm is optional. Definitely for this case I agree we can add as perm (optional): list of ints , although the following description has explicitly mentioned "by default".
Does len(perm) need to be rank(input)?
Currently shape inference does not forbid it, but I think we can add a check for it.
Feel free to submit a PR to resolve these ambiguity if you have bandwidth. Thanks!
If the input is 0d, I would expect perm to be an empty list. Would that be reasonable?
If the input is 0d, I would expect perm to be an empty list. Would that be reasonable?
Makes sense to me if we want to explicitly add the restriction: len(perm) needs to be rank(input).
If the input is 0d, I would expect perm to be an empty list. Would that be reasonable?
Yes. I would say that the current behavior is a bug/limitation of the shape-inference code.
I also tried out the ONNX reference implementation. It fails for a scalar (0D) input ... I assume this is a fixable limitation.