Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shape inference for Reshape if the data is unranked tensor #2539

Merged
merged 9 commits into from
Oct 3, 2023

Conversation

chentong319
Copy link
Collaborator

@chentong319 chentong319 commented Sep 29, 2023

We can get the rank of the output tensor if the shape() has static shape. This could be useful in the middle of iteration.
I didn't change the symbolic computation of dims in computeShape() because unranked tensor is not allowed when the expression is used in lowering.
The error is mentioned by #2524 .

Signed-off-by: chentong319 <[email protected]>
Signed-off-by: chentong319 <[email protected]>
// TODO: Infer shape without data rank if shape is a constant
// without -1 and without 0 and allowzero.
if (!hasShapeAndRank(getData()) || !hasStaticShape(getShape().getType()))
if (!hasShapeAndRank(getData()) && !hasStaticShape(getShape().getType()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the comment at L125 said, even though shape of Reshape is a constant, it may contain symbolic value, e.g. 0, meaning taking the dimension from the input dimension. Not sure the code afterward can handle such a case: input is unranked and shape contains 0. Otherwise, we need to check shape values in details.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the code to handle 0 or -1 for shape. Since we just need to handle them for shape inference, those dimensions are conservatively given unknown (QuestionmarkIndexExpr). When coming to lowering, the data can not be unranked.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test cases are added to lit test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Collaborator

@tungld tungld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@chentong319 chentong319 merged commit 4ecfb4c into onnx:main Oct 3, 2023
8 checks passed
@chentong319 chentong319 deleted the reshape-infer branch October 3, 2023 19:22
@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #11905 [push] Shape inference for Resh... started at 15:30

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #12912 [push] Shape inference for Resh... started at 15:23

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #12888 [push] Shape inference for Resh... started at 14:23

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #12888 [push] Shape inference for Resh... failed after 1 hr 19 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #12912 [push] Shape inference for Resh... passed after 1 hr 39 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #11905 [push] Shape inference for Resh... passed after 1 hr 50 min

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants