-
Notifications
You must be signed in to change notification settings - Fork 22k
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
[cond] inlining into one of the branches when pred is a python constant #128709
Conversation
[ghstack-poisoned]
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang [ghstack-poisoned]
ghstack-source-id: 6204b597c43c266c4c4bd42dfe232e25c924f8a1 Pull Request resolved: #128709
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang [ghstack-poisoned]
ghstack-source-id: 22661aa10d3efb61ab5b5fe840e3dac4d31fd683 Pull Request resolved: #128709
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang [ghstack-poisoned]
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang [ghstack-poisoned]
ghstack-source-id: 289481af89844ad078f5c2540e1eac53792d1960 Pull Request resolved: #128709
torch/_higher_order_ops/cond.py
Outdated
if isinstance(pred, (bool, int, float)): | ||
log.warning( | ||
"Pred is a Python constant. When used with torch.cond, it executes only one of the branches." | ||
" If you want torch.cond to perserve two branches, please make the predicate a boolean tensor." |
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.
can cond take symbool?
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.
yeah, add a test_export_cond_symbool_pred to reflect this. cond won't specialize on symbool.
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang [ghstack-poisoned]
ghstack-source-id: ee91520c5d4cb73cdd9cb98404313d2616f59cff Pull Request resolved: #128709
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang [ghstack-poisoned]
ghstack-source-id: a4d25d25d63eec7c7a0f1bdfdb6a3a025af510ed Pull Request resolved: #128709
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang [ghstack-poisoned]
@pytorchbot merge |
Merge failedReason: This PR has internal changes and must be landed via Phabricator Details for Dev Infra teamRaised by workflow job |
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames Differential Revision: [D59589709](https://our.internmc.facebook.com/intern/diff/D59589709) [ghstack-poisoned]
@ydwu4 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…thon constant" When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames Differential Revision: [D59589709](https://our.internmc.facebook.com/intern/diff/D59589709) [ghstack-poisoned]
ghstack-source-id: ad68a8daacb741710843b72bec69fd3ce0dc4247 Pull Request resolved: #128709
…thon constant" Reland #128709. When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
replaced by #130493 |
…hen pred is a python constant" Reland #128709. When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
…thon constant" Reland #128709. When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
…hen pred is a python constant" Reland #128709. When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
…thon constant" Reland #128709. When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
…nt (#130493) Reland #128709. When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, Pull Request resolved: #130493 Approved by: https://github.com/BoyuanFeng
…, and prim::Exit (#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: #129416 Approved by: https://github.com/angelayi
…, and prim::Exit (#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: #129416 Approved by: https://github.com/angelayi
…, and prim::Exit (#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: #129416 Approved by: https://github.com/angelayi
…, and prim::Exit (#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: #129416 Approved by: https://github.com/angelayi
…, and prim::Exit (pytorch#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](pytorch#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: pytorch#129416 Approved by: https://github.com/angelayi
…, and prim::Exit (pytorch#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](pytorch#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: pytorch#129416 Approved by: https://github.com/angelayi
…, and prim::Exit (pytorch#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](pytorch#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: pytorch#129416 Approved by: https://github.com/angelayi
…nt (pytorch#128709) When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, Differential Revision: [D59589709](https://our.internmc.facebook.com/intern/diff/D59589709) Pull Request resolved: pytorch#128709 Approved by: https://github.com/zou3519
…n constant (pytorch#128709)" This reverts commit fe3e687. Reverted pytorch#128709 on behalf of https://github.com/ydwu4 due to causing error on truck due to a land racing: https://hud.pytorch.org/pytorch/pytorch/commit/fe3e6878c4bb2a6001045c179fd7fa9838242558 ([comment](pytorch#128709 (comment)))
…nt (pytorch#130493) Reland pytorch#128709. When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants. We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph. Test Plan: The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches, Pull Request resolved: pytorch#130493 Approved by: https://github.com/BoyuanFeng
…, and prim::Exit (pytorch#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](pytorch#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: pytorch#129416 Approved by: https://github.com/angelayi
…, and prim::Exit (pytorch#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](pytorch#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: pytorch#129416 Approved by: https://github.com/angelayi
…, and prim::Exit (pytorch#129416) - Support raise exception. It's behavior matches non-strict export now, thanks to @ydwu4's [PR](pytorch#128709). - Support prim::Unitialized, prim::Enter, and prim::Exit Pull Request resolved: pytorch#129416 Approved by: https://github.com/angelayi
Stack from ghstack (oldest at bottom):
When the input predicate is a python constant, we specialize into one of the branches and warn users that torch.cond is not preserving the dynamism. The previous behavior is that we baked in True/False in the cond operator. This can be confusing. In this PR, we change it to be specializing into one of the branches when the inputs are constants.
We additionally change the naming of cond operator to default one without overriding its name. This allows better testing on de-serialized graph.
Test Plan:
The predicate in some existing tests is the result of a shape comparison. When no dynamic shape is involved, the predicate is a python bool. To fix them, we either change the predicate to be some data-dependent tensor or change the test to check cond is specialized as one of the branches,
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames
Differential Revision: D59589709