Repository navigation
[precompile] Rebuild a trivial frame as plain Python only when a resume name reaches it - #198908
bobrenjc93 wants to merge 6 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198908
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit f523f14 with merge base 2cb7870 ( 🟢 GREEN LIGHT - PR approved to be merged without human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Claude finished @bobrenjc93's task in 1m 39s —— View job I found no correctness problems in the gate change. There are two small follow-ups below, and neither blocks the PR. Review detailsSummaryBefore this PR, the driver rebuilt every trivial non-entry record as a plain function. Now it only does that for a trivial record that has a resume name. Unnamed trivial records, such as a I also checked these cases:
Code Quality
Testing
RecommendationApprove. The fix is small and consistent across both call sites, and it has a regression test. The notes above are follow-ups. |
[ghstack-poisoned]
|
@claude review |
[ghstack-poisoned]
|
@claude review |
|
Claude finished @bobrenjc93's task in 1m 9s —— View job The previous review findings are fixed at HEAD Review detailsSummaryThe PR rebuilds a trivial record as plain Python only when the record has a resume name, and it uses the same gate in Testing
RecommendationRequest Changes. The driver change is correct. The new capture should move ahead of the reset and scrub so the test still checks that the driver binds its own globals. |
[ghstack-poisoned]
Superseded by a newer greenlight verdict.
|
@claude review |
|
Claude finished @bobrenjc93's task in 57s —— View job The driver change at HEAD Review detailsSummaryThe PR gates the plain-function rebuild of a trivial record on the record having a resume name, and uses the same predicate in Testing
RecommendationRequest Changes. The fix is a small reordering in the test, and it has been open since the last review. |
[ghstack-poisoned]
…me name reaches it Addresses aorenste's review of #198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now captures `_callback_step` (the shape above, with an identity `cb`), checks that Dynamo recorded the callback as trivial with no resume names, adds that record, named `__main__`, to the artifact, and still serves it. That capture runs before the reset and `_scrub_minted`, so the scrub also removes the globals it mints and the test still checks that the driver binds its own. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: f8e7c51 Pull-Request: #198908
|
@claude review |
|
Claude finished @bobrenjc93's task in 40s —— View job I found no remaining issues at HEAD Review detailsSummaryBefore this PR, the standalone driver rebuilt every trivial non-entry record as plain Python. It now does that only for a trivial record that has a resume name. The earlier findings are all resolved:
I found no new problems in the RecommendationApprove. |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 0 checks: Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…me name reaches it Addresses aorenste's review of #198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now captures `_callback_step` (the shape above, with an identity `cb`), checks that Dynamo recorded the callback as trivial with no resume names, adds that record, named `__main__`, to the artifact, and still serves it. That capture runs before the reset and `_scrub_minted`, so the scrub also removes the globals it mints and the test still checks that the driver binds its own. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: f8e7c51 Pull-Request: #198908
…me name reaches it Addresses aorenste's review of #198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now captures `_callback_step` (the shape above, with an identity `cb`), checks that Dynamo recorded the callback as trivial with no resume names, adds that record, named `__main__`, to the artifact, and still serves it. That capture runs before the reset and `_scrub_minted`, so the scrub also removes the globals it mints and the test still checks that the driver binds its own. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: f8e7c51 Pull-Request: #198908
…me name reaches it Addresses aorenste's review of #198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now captures `_callback_step` (the shape above, with an identity `cb`), checks that Dynamo recorded the callback as trivial with no resume names, adds that record, named `__main__`, to the artifact, and still serves it. That capture runs before the reset and `_scrub_minted`, so the scrub also removes the globals it mints and the test still checks that the driver binds its own. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: f8e7c51 Pull-Request: #198908
…me name reaches it Addresses aorenste's review of #198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now captures `_callback_step` (the shape above, with an identity `cb`), checks that Dynamo recorded the callback as trivial with no resume names, adds that record, named `__main__`, to the artifact, and still serves it. That capture runs before the reset and `_scrub_minted`, so the scrub also removes the globals it mints and the test still checks that the driver binds its own. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: f8e7c51 Pull-Request: #198908
…me name reaches it Addresses aorenste's review of #198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now captures `_callback_step` (the shape above, with an identity `cb`), checks that Dynamo recorded the callback as trivial with no resume names, adds that record, named `__main__`, to the artifact, and still serves it. That capture runs before the reset and `_scrub_minted`, so the scrub also removes the globals it mints and the test still checks that the driver binds its own. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: f8e7c51 Pull-Request: #198908
…me name reaches it Addresses aorenste's review of #198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now captures `_callback_step` (the shape above, with an identity `cb`), checks that Dynamo recorded the callback as trivial with no resume names, adds that record, named `__main__`, to the artifact, and still serves it. That capture runs before the reset and `_scrub_minted`, so the scrub also removes the globals it mints and the test still checks that the driver binds its own. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: f8e7c51 Pull-Request: #198908
…me name reaches it Addresses aorenste's review of #198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now captures `_callback_step` (the shape above, with an identity `cb`), checks that Dynamo recorded the callback as trivial with no resume names, adds that record, named `__main__`, to the artifact, and still serves it. That capture runs before the reset and `_scrub_minted`, so the scrub also removes the globals it mints and the test still checks that the driver binds its own. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: f8e7c51 Pull-Request: #198908
…me name reaches it (pytorch#198908) Addresses aorenste's review of pytorch#198214, which is approved and so is left untouched. The standalone driver rebuilt every trivial non-entry record as a plain function, opening its module for the globals. Dynamo records every function it intercepts while a continuation runs eager, so a callback the entry calls after `.backward()` gets a trivial record too, with no resume names. When that callback is defined in the capturing script its record names `__main__`, and `_import` refuses `__main__`, so loading the artifact failed with an error blaming the entry even when the entry's module is importable: ```python # mylib.py def step(model, x, cb): loss = (model(x) * 2).sum() loss.backward() return cb(loss) ``` Nothing in the artifact can call such a record: the continuation calls whatever `cb` the serving caller passes. The plain-function branch is now gated on the record having a resume name, not on it not being the entry. A record with none falls through to the no-variant path, which defers its refusal to a call that never comes and binds nothing. The entry has no resume names, so it still reaches the entry refusal as before. The resume-name pre-check uses the same gate, so it opens exactly the modules `_make_dispatcher` does. The test also folds the reset / scrub-minted-names / alias sys.modules / exec-the-driver sequence, copied across four tests, into two helpers, `_scrub_minted` and `_multigraph_driver`. Test Plan: `test_trivial_continuation_is_served_as_plain_python` now adds a trivial `__main__` record with no resume names to the artifact and still serves it. With the old gate restored, all three variants fail with "captured from a function defined in the capturing script's __main__ module". ``` python test/test_precompile.py -k test_multigraph_driver_dispatches -k test_trivial_continuation -k round_trips_a_hand_built python test/test_precompile.py lintrunner test/test_precompile.py torch/_precompile_driver.py ``` This PR was authored with the help of an AI assistant (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]> Pull Request resolved: pytorch#198908 Approved by: https://github.com/pytorchgreenlight
Stack from ghstack (oldest at bottom):
Addresses aorenste's review of #198214, which is approved and so is left
untouched.
The standalone driver rebuilt every trivial non-entry record as a plain function,
opening its module for the globals. Dynamo records every function it intercepts
while a continuation runs eager, so a callback the entry calls after
.backward()gets a trivial record too, with no resume names. When that callbackis defined in the capturing script its record names
__main__, and_importrefuses
__main__, so loading the artifact failed with an error blaming theentry even when the entry's module is importable:
Nothing in the artifact can call such a record: the continuation calls whatever
cbthe serving caller passes. The plain-function branch is now gated on therecord having a resume name, not on it not being the entry. A record with none
falls through to the no-variant path, which defers its refusal to a call that
never comes and binds nothing. The entry has no resume names, so it still
reaches the entry refusal as before. The resume-name pre-check uses the same
gate, so it opens exactly the modules
_make_dispatcherdoes.The test also folds the reset / scrub-minted-names / alias sys.modules /
exec-the-driver sequence, copied across four tests, into two helpers,
_scrub_mintedand_multigraph_driver.Test Plan:
test_trivial_continuation_is_served_as_plain_pythonnow adds a trivial__main__record with no resume names to the artifact and still serves it.With the old gate restored, all three variants fail with "captured from a
function defined in the capturing script's main module".
This PR was authored with the help of an AI assistant (Claude).
Co-Authored-By: Claude Opus 5.5 [email protected]