-
Notifications
You must be signed in to change notification settings - Fork 679
Fixes to_edge_transform_and_lower when unsupported ops are asked for preservation #8776
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/8776
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 5 PendingAs of commit 548d770 with merge base 38384a2 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
def _remove_invalid_ops_for_not_decompose( | ||
ops_to_not_decompose: List[torch._ops.OpOverload], | ||
) -> List[torch._ops.OpOverload]: | ||
def keep(op): | ||
schema = op._schema | ||
native_schema = _pybind_schema_to_native_schema(schema) | ||
if native_schema.is_mutable: | ||
return False | ||
if native_schema.aliased_return_names() != [None]: | ||
return False | ||
return True | ||
|
||
return list(filter(keep, ops_to_not_decompose)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this is a bit too sneaky in my mind. If the user wants to debug why an op is decomposed vs not decomposed, it might take them a while to find this filter.
Do you think it's reasonable to raise error at the partitioner level when they try to keep the aliasing op instead of silently filtering them out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's reasonable to raise error at the partitioner level
The user does not specify ops that should be decomposed or not. The partitioner automatically returns the list based on what the backend supports. If we did this filtering in the partitioner, each partitioner would just need to repeat this same filtering logic because it's actually a limitation with ExecuTorch. In fact, I originally did add this logic to the CoreML partitioner, but then I thought it applies to all partitioners, so why not add it to _program.py instead.
We could add logging for this filter though?
I think the ideal solution for to_edge_transform_and_lower is:
- First functionalize the graph and remove aliased ops
- Ask partitioners for ops to preserve
- Run decompositions
Today, step 1 happens after step 2 and that is the issue. Note that doing the functionalization and removing aliased ops before asking partitioners what ops to preserve has the same effect as the filter above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@metascroy i remember vaguely that there was a way to functionalize the graph and remove aliased ops without calling run_decompositions
. @tugsbayasgalan @angelayi is this possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the ideal solution for to_edge_transform_and_lower is:
- First functionalize the graph and remove aliased ops
- Ask partitioners for ops to preserve
- Run decompositions
Today, step 1 happens after step 2 and that is the issue. Note that doing the functionalization and removing aliased ops before asking partitioners what ops to preserve has the same effect as the filter above.
100% agree and this should be the long term fix. Can we create an issue to track that? We can go with the current approach to unblock ourselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created tracking issue here: #8781
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larryliu0820 are there any more concerns on this short term fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No thanks for creating the issue
@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…preservation (#8776) Summary: If a partitioner requests to_edge_transform_and_lower keep mutable / aliasing ops (e.g., transpose, view, permute, etc), lowering with ExecuTorch fails because those ops cannot be functionalized when wrapped in the EDGE_DO_NOT_DECOMP namespace as custom ops. This PR filters out unsupported ops that backends request for preservation. Differential Revision: D70333876 Pulled By: metascroy
49d11b1
to
397a940
Compare
This pull request was exported from Phabricator. Differential Revision: D70333876 |
397a940
to
49d11b1
Compare
@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
if op in [ | ||
# Hits infinte recursion error when op is in | ||
# EDGE_DO_NOT_DECOMP namespace | ||
torch.ops.aten._to_copy.default, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps I didn't understand the full context, but why can't a partitioner just not specify these ops for preservation? I don't think they'll be decomposed anyways?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if a partitioner requests these for preservation, they are no longer aten ops (they become custom ops in EDGE_DO_NOT_DECOMP namespace), and that runs into issues in during export because PyTorch has more restrictions on custom ops than aten ops.
b508634
to
7026ec6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems ok for now, gonna accept, but do you mind linking the issue # to the _remove_invalid_ops_for_not_decompose function?
6e202ee
to
7026ec6
Compare
@metascroy has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Added |
If a partitioner requests to_edge_transform_and_lower keep mutable / aliasing ops (e.g., transpose, view, permute, etc), lowering with ExecuTorch fails because those ops cannot be functionalized when wrapped in the EDGE_DO_NOT_DECOMP namespace as custom ops.
This PR filters out unsupported ops that backends request for preservation.