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

torch.aten.avg_pool3d to linalg #300

Closed
Tracked by #347
wu-s-john opened this issue Dec 24, 2023 · 3 comments
Closed
Tracked by #347

torch.aten.avg_pool3d to linalg #300

wu-s-john opened this issue Dec 24, 2023 · 3 comments
Assignees

Comments

@wu-s-john
Copy link

wu-s-john commented Dec 24, 2023

Required in model VideoResNet_vaiq_int8

%1473 = torch.aten.avg_pool3d %1471, %1472, %60, %551, %false, %false, %none : !torch.vtensor<[1,512,14,14,14],f32>, !torch.list<int>, !torch.list<int>, !torch.list<int>, !torch.bool, !torch.bool, !torch.none -> !torch.vtensor<[1,512,1,1,1],f32>

Interested in implement the lowering for AvgPool3dOp from Torch to linalg.

Seems that there is no native 3D convolution method for doing a sum or max in linalg. I would be happy to implement.

#215

llvm/torch-mlir#3030

@wu-s-john wu-s-john changed the title torch.aten.avg3dpool [TorchToLinAlg lowering] torch.aten.avg_pool3d [TorchToLinAlg lowering] Dec 24, 2023
@wu-s-john
Copy link
Author

This was actually quite involved to implement. Namely, we cannot apply pooling_ndhwc_sum generically to ConvertAtenAvgPoolOp in Pooling.cpp.

In ConvertAtenAvgPoolOp::matchAndRewrite, it would eventually call the generic createPoolingOp. It would expect that the pooling would happen for a 5 dimensional matrix on it's last 3 dimensions (3, 4, 5). However, it does the pooling on (2, 3, 4) which is not what we want.

That being said, the best approach I thought was just writing out the entire convolution using linalg::Generic.

I thought it would be a bit cumbersome to constantly trying to achieve computational correctness, so I wanted to solve an easier problem. So, I implemented, I implemented the lowering, torch.aten.max_pool3d , instead.

@vivekkhandelwal1
Copy link
Contributor

This was actually quite involved to implement. Namely, we cannot apply pooling_ndhwc_sum generically to ConvertAtenAvgPoolOp in Pooling.cpp.

In ConvertAtenAvgPoolOp::matchAndRewrite, it would eventually call the generic createPoolingOp. It would expect that the pooling would happen for a 5 dimensional matrix on it's last 3 dimensions (3, 4, 5). However, it does the pooling on (2, 3, 4) which is not what we want.

That being said, the best approach I thought was just writing out the entire convolution using linalg::Generic.

I thought it would be a bit cumbersome to constantly trying to achieve computational correctness, so I wanted to solve an easier problem. So, I implemented, I implemented the lowering, torch.aten.max_pool3d , instead.

Hi @wu-s-john, are you still working on this op?

@AmosLewis AmosLewis self-assigned this Apr 19, 2024
@AmosLewis AmosLewis changed the title torch.aten.avg_pool3d [TorchToLinAlg lowering] torch.aten.avg_pool3d to linalg Apr 22, 2024
@AmosLewis
Copy link
Contributor

llvm/torch-mlir#3030

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

No branches or pull requests

3 participants