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

Allow partial TorchToTcp conversions using a whitelist #16

Merged

Conversation

sjain-stanford
Copy link
Collaborator

@sjain-stanford sjain-stanford commented Nov 2, 2023

Add pass option to TorchToTcp accepting a set of op name strings as whitelist (for selective conversion). This allows flexibility with phase ordering of conversion passes in downstream pipelines.

add private method

move addPatternIfOpInConvertTorchOpsSet to utility function

add back typeConverter

add inline function in Utils.h

update Misc patterns as well

update

elementwise
@sjain-stanford sjain-stanford changed the title Add pass option to TorchToTcp accepting a set of op name strings as whitelist (for selective conversion) Allow partial TorchToTcp conversions using a whitelist Nov 2, 2023
update
@sjain-stanford sjain-stanford marked this pull request as ready for review November 2, 2023 22:36
@sjain-stanford sjain-stanford requested review from sanjoy, navahgar and a team November 2, 2023 22:37
Copy link
Contributor

@zezhang zezhang left a comment

Choose a reason for hiding this comment

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

Thanks for enabling this feature, LGTM!

patterns.add<ConvertAtenAtan2Op>(typeConverter, context);
ConversionTarget &target, const llvm::StringSet<> &convertTorchOpsSet) {

#define INSERT_ATEN_ELEMENTWISE_OP_PATTERN(ConvertAtenOpPattern, AtenOp) \
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can reduce some duplication through token pasting:

#define INSERT_ATEN_ELEMENTWISE_OP_PATTERN(AtenOp) \
  torch_to_tcp::addPatternIfOpInConvertTorchOpsSet<Convert ## AtenOp ## Pattern,       \
                                                    AtenOp>(                    \
       typeConverter, patterns, target, convertTorchOpsSet)

...

INSERT_ATEN_ELEMENTWISE_OP_PATTERN(AtenAtan2Op);

Same for the other macros.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good suggestion, done. I think this was applicable to just INSERT_ATEN_ELEMENTWISE_OP_PATTERN macro in Elementwise.cpp and INSERT_ATEN_MISC_OP_PATTERN macro in Misc.cpp. PLMK if I missed any other occurrence and I'll address in a follow-on.

lib/Conversion/TorchToTcp/TorchToTcp.cpp Outdated Show resolved Hide resolved
lib/Pipeline/Pipeline.cpp Outdated Show resolved Hide resolved
@sjain-stanford sjain-stanford merged commit 690574e into cruise-automation:main Nov 3, 2023
1 check passed
@sjain-stanford sjain-stanford deleted the sambhav/torchtotcp branch November 3, 2023 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants