-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[dynamo] add torch._dynamo.enable and fix compile/enable/disable interaction #132926
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
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/132926
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (3 Unrelated Failures)As of commit 440d1bc with merge base b7a5c7d ( BROKEN TRUNK - The following jobs failed but were 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. |
jansel
left a comment
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.
Failing tests
Follow up to #123771. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
…isable interaction" Follow up to #123771. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
…isable interaction" Follow up to #123771. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
…isable interaction" Fixes the compile/disable interaction part of #123771. Context manager to be followed-up on. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
|
Is this backwards compatible? |
|
No, this will be BC-breaking - see discussion in #123771. i.e. there are users that depend on the old compile/disable interaction. |
| Compilation will only occur if there was a previous `compile` call. | ||
| `enable` is useful for finegrained compiilation control. See the note in `disable` for |
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.
s/compiilation/compilation/
|
Hi, sorry, I'm going to thrash you again. I was reviewing the docs you added and proposing a rewrite of the docs, and while doing so, I realized that I actually think disable as it is used today is different from the "disable" that Horace was proposing in the issue, and we should actually give it a different name. Horace and I came up with "torch.compiler.bypass", but Claude also suggested "force_uncompiled" and "prevent_compilation" which also seemed good. Here are my proposed docs for disable vs these other options. What is the difference between torch.compiler.disable and torch.compiler.force_uncompiled? It's easiest to consider the use cases for these two functions. torch.compiler.disable is for when you want to prevent an outer compilation from continuing compiling into an inner function. You typically want to do this if you have some code that is reachable from a torch.compile that triggers a problem in the compiler (e.g., it causes infinite recompilations) and you just want to disable compilation for it. It comes in two flavors: the default is to disable compilation for that function and all recursive calls (unless you explicitly call torch.compile again internally), and recursive=False, where it will only disable compilation for that particular function call, but will attempt to continue compilation for inner function calls. torch.compiler.force_uncompiled is for when you are in an outer function, and you want to prevent inner compilations from occurring. It's useful if you have some code that has torch.compile directly annotated on functions, but you want to temporarily disable the compiler / any preexisting compiled code so that you can run them under eager semantics, e.g., for benchmarking or if you want to run a TorchDispatchMode (like FlopCounter) which only works in eager semantics. If necessary, you can also undo the effect of this context manager by saying force_uncompiled(False). force_uncompiled is forbidden in graph; you're not allowed to compile code that has a force_uncompiled invocation in it. I don't think you need to change much in your PR. Here's what changes:
WDYT? |
|
We talked about this today in more general at https://docs.google.com/document/d/1qlQyjbENz45L7uGglmiF6CkRgr_VOdxFAcZGCqdtLTY/edit |
|
SGTM from an implementation perspective, although I'm concerned about sufficiently differentiating between A few other clarification questions:
|
It was pretty clear to me when I was writing the docs, so I guess the new docs are not good enough 🤣 Here's a shorter pitch: if you are currently in a torch.compile, but you want to get out, use
I don't mind a decorator but it should be a contextlib.contextmanager style decorator. I don't think
"forbidden in graph" is a preexisting concept which makes the compiler hard error if it traverses it while tracing. It is saying "this code should never be compiled and if you tried to compile it some big accident happened so raise a major error." |
|
Difference between disable and force_eager makes more sense now. What other options are you thinking for |
|
The ones we have right now are: "force_eager", "default", "fail_on_recompile", "eager_on_recompile" |
|
And I will happily bikeshed this forever if needed |
|
To add more color from previous discussion with Ed and others, summary of motivations: https://docs.google.com/document/d/1qlQyjbENz45L7uGglmiF6CkRgr_VOdxFAcZGCqdtLTY/edit#bookmark=id.nl59a72dv4o. Particularly |
|
Moved to a new PR: #137504 |
Attempt #2 at #132926 to implement #123771. Implement a new `torch.compiler.set_phase` function that can force `torch.compile` regions to run eagerly. Other options (such as "fail_on_recompile" and "eager_on_recompile") to be added in a followup PR. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt #2 at #132926 to implement #123771. Implement a new `torch.compiler.set_phase` function that can force `torch.compile` regions to run eagerly. Other options (such as "fail_on_recompile" and "eager_on_recompile") to be added in a followup PR. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt #2 at #132926 to implement #123771. Implement a new `torch.compiler.set_phase` function that can force `torch.compile` regions to run eagerly. Other options (such as "fail_on_recompile" and "eager_on_recompile") to be added in a followup PR. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt #2 at #132926 to implement #123771. Implement a new `torch.compiler.set_phase` function that can force `torch.compile` regions to run eagerly. Other options (such as "fail_on_recompile" and "eager_on_recompile") to be added in a followup PR. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt #2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt #2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames rec [ghstack-poisoned]
Attempt # 2 at #132926 to implement #123771. Implement a new `torch.compiler.set_stance` function that can force `torch.compile` regions to run eagerly. See added tests for usage examples. Pull Request resolved: #137504 Approved by: https://github.com/yf225, https://github.com/jansel
Stack from ghstack (oldest at bottom):
Fixes the compile/disable interaction part of #123771. Context manager to be followed-up on.
cc @ezyang @gchanan @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames