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

[Inductor] Improve reinplace_scatters pass #112801

Closed
wants to merge 9 commits into from

Conversation

Copy link

pytorch-bot bot commented Nov 2, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/112801

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (5 Unrelated Failures)

As of commit 1acb9af with merge base 7715b47 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
oulgen added a commit that referenced this pull request Nov 3, 2023
ghstack-source-id: 121b8bff9500a18fae553d916fdf46f9aa3c1362
Pull Request resolved: #112801
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
oulgen added a commit that referenced this pull request Nov 5, 2023
ghstack-source-id: f0e1285ca0b39a9aa0d6aab9597a0d90ca062a2c
Pull Request resolved: #112801
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
oulgen added a commit that referenced this pull request Nov 6, 2023
ghstack-source-id: e60acbf4278a063e63bb9be8cd8c8a80b6d9c227
Pull Request resolved: #112801
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
oulgen added a commit that referenced this pull request Nov 6, 2023
ghstack-source-id: e2c9df27eaf2fcdec230c7edf1298df7daed726d
Pull Request resolved: #112801
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
oulgen added a commit that referenced this pull request Nov 6, 2023
ghstack-source-id: 2f429765db08cf79fd3d93a6d7dcd510301a8337
Pull Request resolved: #112801
if len(mutated_arg.users) > 1: # Arg used somewhere else
return False
return True
return not any_use_of_views_after_node(node, shared_view_nodes, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: pass in copy_node by kwarg here.

shares storage with no other nodes.
Reinplaces scatter operations.
If there are no uses of a view of the mutated arg after the current node,
it is possible to inplace the op.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth adding a short description here of why we think this algorithm is correct.


# Check for any uses other than current node and copy_ epilogue
if len(mutated_arg.users) > 2:
if any_use_of_views_after_node(node, shared_view_nodes, copy_node):
return False

graph.erase_node(copy_node)
Copy link
Contributor

Choose a reason for hiding this comment

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

side nit: I think it's a bit weird for the node erasure to be done here. I would think that can_inplace is just a check, but it's also responsible here for doing the graph rewrite.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could move it but then we need to have a ternary return value which is slightly more confusing

def can_inplace(node, mutated_arg):
if get_node_storage(mutated_arg) is None:
return False
shared_view_nodes = storage_to_nodes[get_node_storage(mutated_arg)]
if mutated_arg.op == "placeholder":
if any(view.op == "placeholder" for view in shared_view_nodes):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed? It's ... plausibly correct to me, but did you find a case where it was needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there was a test case that was failing that used some index function which emitted an unsqueeze.

Copy link
Contributor

Choose a reason for hiding this comment

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

What was the exact graph being produced?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The gist is

arg0 <- graph input
buf1 = unsquueze arg0
buf2 = indexput buf1
buf3 = squueze buf2
return buf3

arg0 and buf1 share the memory location but we check whether buf1 is placeholder, so we inplace it, however since arg0 shares the same memory location it would be invalid to inplace unless there was a copy at the epilogue as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, that makes sense. I think at some point when discussing this with you last week I thought of this case, but between then and now I forgot about it :P

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
Copy link
Contributor

@Chillee Chillee left a comment

Choose a reason for hiding this comment

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

We should add a bit more correctness testing as well - the test_perf only tests the properties of the graph, but would be good to see some correctness.

pytorchmergebot pushed a commit that referenced this pull request Nov 7, 2023
@facebook-github-bot facebook-github-bot deleted the gh/oulgen/24/head branch November 10, 2023 15:24
Skylion007 pushed a commit to Skylion007/pytorch that referenced this pull request Nov 14, 2023
Skylion007 pushed a commit to Skylion007/pytorch that referenced this pull request Nov 14, 2023
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.

None yet

4 participants