onnx icon indicating copy to clipboard operation
onnx copied to clipboard

Spec: Clarify Transpose

Open justinchuby opened this issue 3 years ago • 5 comments
trafficstars

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

justinchuby avatar Oct 20 '22 22:10 justinchuby

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!

jcwchen avatar Oct 25 '22 16:10 jcwchen

If the input is 0d, I would expect perm to be an empty list. Would that be reasonable?

justinchuby avatar Oct 25 '22 23:10 justinchuby

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).

jcwchen avatar Oct 25 '22 23:10 jcwchen

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.

gramalingam avatar Apr 15 '24 21:04 gramalingam

I also tried out the ONNX reference implementation. It fails for a scalar (0D) input ... I assume this is a fixable limitation.

gramalingam avatar Apr 16 '24 20:04 gramalingam