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

Add unsqueeze and transpose patterns #178

Merged
merged 11 commits into from
Dec 18, 2024
Merged

Conversation

kurapov-peter
Copy link
Collaborator

Both rely on the second input to be a constant.

Depends on #177

@slyalin slyalin marked this pull request as ready for review December 17, 2024 15:41
Comment on lines +40 to +55
SmallVector<ReassociationIndices> expand_groups;
ReassociationIndices group = ReassociationIndices();
SmallVector<int64_t> shape(coords.size() + ov_input_shape.rank().get_length());
for (size_t input_idx = 0, coord_idx = 0, i = 0; i < shape.size(); ++i) {
group.push_back(i);
if (coord_idx < coords.size() && i == coords[coord_idx]) {
shape[i] = 1;
coord_idx++;
} else {
const auto& dim = ov_input_shape[input_idx];
shape[i] = dim.is_dynamic() ? ShapedType::kDynamic : dim.get_length();
input_idx++;
expand_groups.push_back(group);
group = ReassociationIndices();
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Why cannot we just take it as node->get_output_partial_shape(0)? I believe the shape in MLIR should match the shape from OV.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would it be always available? (dynamic shapes?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd still need to generate the reassociation groups anyway though

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd still need to generate the reassociation groups anyway though

Copy link
Owner

Choose a reason for hiding this comment

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

get_output_partial_shape always returns shape, including dynamic shapes, which means a part of the dimensions can be dynamic and you already know how to detect them -- dim.is_dynamic(). But I agree that you still need to build reassociation groups.

@slyalin slyalin merged commit 76324ad into mlir Dec 18, 2024
2 of 3 checks passed
@kurapov-peter kurapov-peter deleted the pakurapo/unsqueeze-transpose branch December 18, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants