-
Notifications
You must be signed in to change notification settings - Fork 24.9k
[precompile] Ensure @disable()-ed function won't trigger recompile from precompile bytecode. #155363
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
…om precompile bytecode. In a precompiled bytecode, it looks like the following: ``` pre-graph bytecode ... compiled graph code ... post-graph bytecode ``` In pre-graph bytecode we have calls into helper functions like torch._dynamo.utils.call_size which will invoke @disable inside the bytecode. Normally torch.compile() will handle these frames fine, but for precompile we will load bytecode from a clean state of dynamo and we want a way to assert recompile never happen, so the current way to ensure this is by doing set_stance("fail_on_recompile") (open to any other idea to test this, but IMO this is the closest thing we have today). This approach doesn't work when util functions like call_size() is involved and this PR fixes a bunch of places to make sure "fail_on_recompile" can skip through the functions meant to be skipped during compilation. Differential Revision: [D76156867](https://our.internmc.facebook.com/intern/diff/D76156867/) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/155363
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (2 Unrelated Failures)As of commit 2228142 with merge base be2ad70 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This pull request was exported from Phabricator. Differential Revision: D76156867 |
@pytorchbot rebase -b main |
@pytorchbot started a rebase job onto refs/remotes/origin/main. Check the current status here |
…m precompile bytecode. In a precompiled bytecode, it looks like the following: ``` pre-graph bytecode ... compiled graph code ... post-graph bytecode ``` In pre-graph bytecode we have calls into helper functions like torch._dynamo.utils.call_size which will invoke disable inside the bytecode. Normally torch.compile() will handle these frames fine, but for precompile we will load bytecode from a clean state of dynamo and we want a way to assert recompile never happen, so the current way to ensure this is by doing set_stance("fail_on_recompile") (open to any other idea to test this, but IMO this is the closest thing we have today). This approach doesn't work when util functions like call_size() is involved and this PR fixes a bunch of places to make sure "fail_on_recompile" can skip through the functions meant to be skipped during compilation. Differential Revision: [D76156867](https://our.internmc.facebook.com/intern/diff/D76156867/) ghstack-source-id: cb4a327 Pull Request resolved: #155363
Successfully rebased |
Also based on #155259 |
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.
It took me a while to understand why you're removing @functools.wraps(fn)
(so maybe a better comment could help), but my understanding is:
- in precompile, we sometimes attempt to top-level compile a @disable'd function, but the
functools.wraps
frame ends up getting traced with the old callback still active, leading to failures under thefail_on_recompile
stance. - We need the
functools.wraps
normally so that convert_frame.py has some knowledge of the original underlying frame (e.g. I believe not including this decorator will impact how trace_rules handles this function).
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.
Test failures?
@williamwen42 yes your understand is correct to me. I can add more comments to explain this. |
…ecompile from precompile bytecode." In a precompiled bytecode, it looks like the following: ``` pre-graph bytecode ... compiled graph code ... post-graph bytecode ``` In pre-graph bytecode we have calls into helper functions like torch._dynamo.utils.call_size which will invoke disable inside the bytecode. Normally torch.compile() will handle these frames fine, but for precompile we will load bytecode from a clean state of dynamo and we want a way to assert recompile never happen, so the current way to ensure this is by doing set_stance("fail_on_recompile") (open to any other idea to test this, but IMO this is the closest thing we have today). This approach doesn't work when util functions like call_size() is involved and this PR fixes a bunch of places to make sure "fail_on_recompile" can skip through the functions meant to be skipped during compilation. Differential Revision: [D76156867](https://our.internmc.facebook.com/intern/diff/D76156867/) cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx chenyang78 kadeng chauhang amjames [ghstack-poisoned]
…om precompile bytecode. Pull Request resolved: #155363 In a precompiled bytecode, it looks like the following: ``` pre-graph bytecode ... compiled graph code ... post-graph bytecode ``` In pre-graph bytecode we have calls into helper functions like torch._dynamo.utils.call_size which will invoke @disable inside the bytecode. Normally torch.compile() will handle these frames fine, but for precompile we will load bytecode from a clean state of dynamo and we want a way to assert recompile never happen, so the current way to ensure this is by doing set_stance("fail_on_recompile") (open to any other idea to test this, but IMO this is the closest thing we have today). This approach doesn't work when util functions like call_size() is involved and this PR fixes a bunch of places to make sure "fail_on_recompile" can skip through the functions meant to be skipped during compilation. Differential Revision: [D76156867](https://our.internmc.facebook.com/intern/diff/D76156867/) ghstack-source-id: 289152993
This pull request was exported from Phabricator. Differential Revision: D76156867 |
@pytorchbot merge |
Merge startedYour 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 |
This pull request was exported from Phabricator. Differential Revision: D76156867 |
Stack from ghstack (oldest at bottom):
In a precompiled bytecode, it looks like the following:
In pre-graph bytecode we have calls into helper functions like torch._dynamo.utils.call_size which will invoke @disable inside the bytecode.
Normally torch.compile() will handle these frames fine, but for precompile we will load bytecode from a clean state of dynamo and we want a way to assert recompile never happen, so the current way to ensure this is by doing set_stance("fail_on_recompile") (open to any other idea to test this, but IMO this is the closest thing we have today).
This approach doesn't work when util functions like call_size() is involved and this PR fixes a bunch of places to make sure "fail_on_recompile" can skip through the functions meant to be skipped during compilation.
Differential Revision: D76156867
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames