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

Converts all Adaptive Pooling Ops to Linalg #2808

Merged
merged 19 commits into from
Mar 22, 2024
Merged

Conversation

zjgarvey
Copy link
Collaborator

The previous conversions for AtenAdaptiveAvgPool1dOp and AtenAdaptiveMaxPool2dOp are refactored into a general templated conversion that works for all of the AtenAdaptive...PoolNdOp's.

New support is added for the following ops:

  1. AtenAdaptiveMaxPool1d
  2. AtenAdaptiveMaxPool3d
  3. AtenAdaptiveAvgPool3d

Support is also provided for passing inputs without batch dimensions. For example, applying adaptive_avg_pool2d to an input tensor of rank 3.

After pytorch #118162 gets down to torch-mlir, I'll add a test for AdaptiveMaxPool1d with return_indices (which will pass with that upstream fix).

Also adds support for:
- aten.adaptive_max_pool1d
- aten.adaptive_max_pool3d
- using inputs of rank n+1 instead of n+2 (i.e., no batches)
All adaptive pooling ops will now use the same templated conversion pattern.
@zjgarvey
Copy link
Collaborator Author

The AdaptiveAvgPool2d tests are failing on dynamo with the expected error message:

Exception: Unsupported: missing default value for argument 0 in schema for aten.div.Tensor_mode

So I know to add those to the appropriate place in the xfail sets.

However, the dynamo failures for AdaptiveAvgPool3d are more cryptic and say:

error: unknown: failed to legalize operation 'torch.constant.int'

I'll do some digging to figure out what is going on there. I would like to assume it is secretly encountering the same issue as the other tests, but I'd like to figure out why it isn't giving the same error message.

@zjgarvey zjgarvey force-pushed the adaptpoolgen branch 3 times, most recently from 8a4afeb to 60e9346 Compare January 29, 2024 19:04
Copy link
Collaborator

@newling newling left a comment

Choose a reason for hiding this comment

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

Looks like a nice improvement! Just a few minor suggestions.

lib/Conversion/TorchToLinalg/Pooling.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchToLinalg/Pooling.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchToLinalg/Pooling.cpp Outdated Show resolved Hide resolved
lib/Conversion/TorchToLinalg/Pooling.cpp Outdated Show resolved Hide resolved
also stores isMaxPool as part of the same struct as Dim
Seeing if it's possible to use polymorphism to clean up conversion
Copy link
Collaborator

@newling newling left a comment

Choose a reason for hiding this comment

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

This looks good to me. Thanks for making the suggested changes (the template to determine dim and isMax is very nice). @zjgarvey feel free to get the opinion of a more experienced torch-mlir-er if you like.

This one off-loads compile-time cf to polymorphic helper functions
@zjgarvey
Copy link
Collaborator Author

zjgarvey commented Feb 5, 2024

The helper functions require quite a few arguments, but overall I think this polymorphism approach is probably better. Let me know what you think, @newling.

@newling
Copy link
Collaborator

newling commented Feb 5, 2024

The helper functions require quite a few arguments, but overall I think this polymorphism approach is probably better. Let me know what you think, @newling.

Nice! I think it makes the main function easier to follow. I have made a PR zjgarvey#1 against this which may/mayn't be a better design.

@zjgarvey
Copy link
Collaborator Author

zjgarvey commented Feb 6, 2024

Nice! I think it makes the main function easier to follow. I have made a PR zjgarvey#1 against this which may/mayn't be a better design.

Yeah, I can see the advantage there especially if I can move all of the helper functions to the external structure and not need to define derived classes for the conversion. I'll check this out, thanks for the prototyping @newling .

@zjgarvey
Copy link
Collaborator Author

zjgarvey commented Feb 6, 2024

I'm going to make a few more changes right now to move the rest of the methods to the external helper.

@zjgarvey zjgarvey force-pushed the adaptpoolgen branch 2 times, most recently from 4e5753f to 8660363 Compare March 14, 2024 22:49
@zjgarvey
Copy link
Collaborator Author

@rsuderman I just updated this PR so that it should be fine to merge without problems.

Would you mind taking a look?

Copy link
Collaborator

@renxida renxida left a comment

Choose a reason for hiding this comment

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

I'm by no means familiar with this codebase and most of my comments are "i wonder" type comments. I would so love it if @zjgarvey could explain the thought processes behind some of the decisions. Maybe we should @ somebody more experienced to comment on it afterwards.

lib/Conversion/TorchToLinalg/Pooling.cpp Show resolved Hide resolved
lib/Conversion/TorchToLinalg/Pooling.cpp Show resolved Hide resolved
lib/Conversion/TorchToLinalg/Pooling.cpp Show resolved Hide resolved
lib/Conversion/TorchToLinalg/Pooling.cpp Show resolved Hide resolved
lib/Conversion/TorchToLinalg/Pooling.cpp Show resolved Hide resolved
Copy link
Collaborator

@newling newling left a comment

Choose a reason for hiding this comment

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

Apologies for the delay in reviewing. This looks good to me!

@zjgarvey
Copy link
Collaborator Author

@renxida do you think the comments I added in the last commit are sufficient to clear up the readability concerns you had earlier?

@renxida renxida merged commit 99b3a5f into llvm:main Mar 22, 2024
3 checks passed
josel-amd pushed a commit to Xilinx/torch-mlir that referenced this pull request Jun 7, 2024
The previous conversions for AtenAdaptiveAvgPool1dOp and
AtenAdaptiveMaxPool2dOp are refactored into a general templated
conversion that works for all of the AtenAdaptive...PoolNdOp's.

New support is added for the following ops:

1. AtenAdaptiveMaxPool1d
2. AtenAdaptiveMaxPool3d
3. AtenAdaptiveAvgPool3d

Support is also provided for passing inputs without batch dimensions.
For example, applying adaptive_avg_pool2d to an input tensor of rank 3.

After [pytorch #118162](pytorch/pytorch#118162)
gets down to torch-mlir, I'll add a test for AdaptiveMaxPool1d with
return_indices (which will pass with that upstream fix).

---------

Co-authored-by: James Newling <[email protected]>
josel-amd pushed a commit to Xilinx/torch-mlir that referenced this pull request Jun 10, 2024
The previous conversions for AtenAdaptiveAvgPool1dOp and
AtenAdaptiveMaxPool2dOp are refactored into a general templated
conversion that works for all of the AtenAdaptive...PoolNdOp's.

New support is added for the following ops:

1. AtenAdaptiveMaxPool1d
2. AtenAdaptiveMaxPool3d
3. AtenAdaptiveAvgPool3d

Support is also provided for passing inputs without batch dimensions.
For example, applying adaptive_avg_pool2d to an input tensor of rank 3.

After [pytorch #118162](pytorch/pytorch#118162)
gets down to torch-mlir, I'll add a test for AdaptiveMaxPool1d with
return_indices (which will pass with that upstream fix).

---------

Co-authored-by: James Newling <[email protected]>
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