Skip to content

Conversation

ydwu4
Copy link
Contributor

@ydwu4 ydwu4 commented Jun 27, 2024

Stack from ghstack (oldest at bottom):

Before the PR, custom ops that don't return outputs will get eliminated after calling .module() because the effect_token that keeps the operator alive is removed in remove_effect_token pass. The reason why we want to remove_effect_token is because we don't want the token to be part of input. However, this causes DCE calls in remove_effect_token itself and the dce calls in unlift to remove the custom op in the graph causing an error in the exported graph.

This PR calls has_side_effect in with_effect to make sure graph.eliminate_dead_code doesn't remove the calls by accident.

Test Plan:
Add a new test pytest test/export/test_torchbind.py -k test_export_inplace_custom_op

Differential Revision: D59498728

Copy link

pytorch-bot bot commented Jun 27, 2024

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 498df79 with merge base 5ceba6a (image):
💚 Looks good so far! There are no failures yet. 💚

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

ydwu4 added a commit that referenced this pull request Jun 27, 2024
@ydwu4 ydwu4 requested a review from angelayi June 27, 2024 17:52
@ydwu4 ydwu4 added the topic: not user facing topic category label Jun 27, 2024
…ct_token"


Before the PR, custom ops that doesn't return outputs will gets eliminated after calling `.module()` because the effect_token that keeps the operator not DCEed is removed in remove_effect_token. The reason why we want to remove_effect_token is because we don't want the token to be part of input. However, the causes DCE calls in remove_effect_token itself and the dce calls in unlift to remove the custom op in the graph causing an error in the exported graph.

This PR removes the DCE calls in unlift and remove_effect_token to avoid this, which may not be a good idea. The idea behind is that the passes in export should never call eliminate dead code so that we could put remote_effect_token anywhere we want.

The alternative is that we should carefully put remove_effect_token as the last transformation to avoid any transformations to eliminate them. But in the case of unlift, we have to remove_effect_token before running unlift in order to keep the signature match.  


Test Plan:
Add a new test pytest test/export/test_torchbind.py -k test_export_inplace_custom_op



[ghstack-poisoned]
…ct_token"


Before the PR, custom ops that doesn't return outputs will gets eliminated after calling `.module()` because the effect_token that keeps the operator not DCEed is removed in remove_effect_token. The reason why we want to remove_effect_token is because we don't want the token to be part of input. However, the causes DCE calls in remove_effect_token itself and the dce calls in unlift to remove the custom op in the graph causing an error in the exported graph.

This PR removes the DCE calls in unlift and remove_effect_token to avoid this, which may not be a good idea. The idea behind is that the passes in export should never call eliminate dead code so that we could put remote_effect_token anywhere we want.

The alternative is that we should carefully put remove_effect_token as the last transformation to avoid any transformations to eliminate them. But in the case of unlift, we have to remove_effect_token before running unlift in order to keep the signature match.  


Test Plan:
Add a new test pytest test/export/test_torchbind.py -k test_export_inplace_custom_op



[ghstack-poisoned]
@ydwu4 ydwu4 changed the title [export] cannot call eliminate_dead_code after remove effect_token [export] make with_effect add has_side_effect to the op target to avoid being DCEed. Jun 27, 2024
@ydwu4 ydwu4 changed the title [export] make with_effect add has_side_effect to the op target to avoid being DCEed. [export] make with_effect add mark the op has_effect to prevent them from DCEed. Jun 27, 2024
…event them from DCEed."


Before the PR, custom ops that doesn't return outputs will gets eliminated after calling `.module()` because the effect_token that keeps the operator not DCEed is removed in remove_effect_token. The reason why we want to remove_effect_token is because we don't want the token to be part of input. However, the causes DCE calls in remove_effect_token itself and the dce calls in unlift to remove the custom op in the graph causing an error in the exported graph.

This PR calls has_side_effect in with_effect to make sure graph.eliminate_dead_code doesn't remove the calls by accident.

Test Plan:
Add a new test pytest test/export/test_torchbind.py -k test_export_inplace_custom_op



[ghstack-poisoned]
ydwu4 added a commit that referenced this pull request Jun 27, 2024
@ydwu4
Copy link
Contributor Author

ydwu4 commented Jun 27, 2024

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 27, 2024
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@ydwu4 ydwu4 changed the title [export] make with_effect add mark the op has_effect to prevent them from DCEed. [export] make with_effect mark op has_effect to prevent them from DCEed. Jun 27, 2024
@kit1980
Copy link
Contributor

kit1980 commented Jul 3, 2024

@pytorchbot revert -m "breaking internal builds, see D59181183" -c ghfirst

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot
Copy link
Collaborator

@ydwu4 your PR has been successfully reverted.

pytorchmergebot added a commit that referenced this pull request Jul 3, 2024
…from DCEed. (#129680)"

This reverts commit 4b8a5e0.

Reverted #129680 on behalf of https://github.com/kit1980 due to breaking internal builds, see D59181183 ([comment](#129680 (comment)))
@ydwu4
Copy link
Contributor Author

ydwu4 commented Jul 8, 2024

@ydwu4 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

…em from DCEed."


Before the PR, custom ops that don't return outputs will get eliminated after calling `.module()` because the effect_token that keeps the operator alive is removed in remove_effect_token pass. The reason why we want to remove_effect_token is because we don't want the token to be part of input. However, this causes DCE calls in remove_effect_token itself and the dce calls in unlift to remove the custom op in the graph causing an error in the exported graph.

This PR calls has_side_effect in with_effect to make sure graph.eliminate_dead_code doesn't remove the calls by accident.

Test Plan:
Add a new test pytest test/export/test_torchbind.py -k test_export_inplace_custom_op

Differential Revision: [D59498728](https://our.internmc.facebook.com/intern/diff/D59498728)

[ghstack-poisoned]
ydwu4 added a commit that referenced this pull request Jul 10, 2024
@ydwu4
Copy link
Contributor Author

ydwu4 commented Jul 10, 2024

@ydwu4 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

…em from DCEed."


Before the PR, custom ops that don't return outputs will get eliminated after calling `.module()` because the effect_token that keeps the operator alive is removed in remove_effect_token pass. The reason why we want to remove_effect_token is because we don't want the token to be part of input. However, this causes DCE calls in remove_effect_token itself and the dce calls in unlift to remove the custom op in the graph causing an error in the exported graph.

This PR calls has_side_effect in with_effect to make sure graph.eliminate_dead_code doesn't remove the calls by accident.

Test Plan:
Add a new test pytest test/export/test_torchbind.py -k test_export_inplace_custom_op

Differential Revision: [D59498728](https://our.internmc.facebook.com/intern/diff/D59498728)

[ghstack-poisoned]
@ydwu4
Copy link
Contributor Author

ydwu4 commented Jul 10, 2024

@ydwu4 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

…em from DCEed."


Before the PR, custom ops that don't return outputs will get eliminated after calling `.module()` because the effect_token that keeps the operator alive is removed in remove_effect_token pass. The reason why we want to remove_effect_token is because we don't want the token to be part of input. However, this causes DCE calls in remove_effect_token itself and the dce calls in unlift to remove the custom op in the graph causing an error in the exported graph.

This PR calls has_side_effect in with_effect to make sure graph.eliminate_dead_code doesn't remove the calls by accident.

Test Plan:
Add a new test pytest test/export/test_torchbind.py -k test_export_inplace_custom_op

Differential Revision: [D59498728](https://our.internmc.facebook.com/intern/diff/D59498728)

[ghstack-poisoned]
ydwu4 added a commit that referenced this pull request Jul 10, 2024
@ydwu4
Copy link
Contributor Author

ydwu4 commented Jul 10, 2024

@ydwu4 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@ydwu4
Copy link
Contributor Author

ydwu4 commented Jul 10, 2024

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: This PR has internal changes and must be landed via Phabricator

Details for Dev Infra team Raised by workflow job

@ydwu4
Copy link
Contributor Author

ydwu4 commented Jul 11, 2024

@pytorchbot merge -f "landed internally"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Jul 25, 2024
…ed. (pytorch#129680)

Before the PR, custom ops that don't return outputs will get eliminated after calling `.module()` because the effect_token that keeps the operator alive is removed in remove_effect_token pass. The reason why we want to remove_effect_token is because we don't want the token to be part of input. However, this causes DCE calls in remove_effect_token itself and the dce calls in unlift to remove the custom op in the graph causing an error in the exported graph.

This PR calls has_side_effect in with_effect to make sure graph.eliminate_dead_code doesn't remove the calls by accident.

Test Plan:
Add a new test pytest test/export/test_torchbind.py -k test_export_inplace_custom_op

Differential Revision: [D59498728](https://our.internmc.facebook.com/intern/diff/D59498728)
Pull Request resolved: pytorch#129680
Approved by: https://github.com/angelayi
@github-actions github-actions bot deleted the gh/ydwu4/129/head branch August 12, 2024 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged Reverted topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants