Repository navigation
[precompile] Address review cleanups on PrecompileSession - #199065
bobrenjc93 wants to merge 7 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/199065
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 64cf555 with merge base be4d660 ( 🟡 GREEN LIGHT - PR requires human review:
reason: BROKEN TRUNK - The following job 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. |
|
@claude review |
|
Claude finished @bobrenjc93's task in 1m 2s —— View job The PR's own changes are correct, but it misses a second copy of the wrong guard-filter claim: the public PR Review: #199065SummaryThe PR fixes the API Design
RecommendationRequest Changes: fix the |
[ghstack-poisoned]
|
@claude review |
Follow-up to the review of #198137, which has landed; this does not amend it. The precompile_capture docstring claimed runtime guards stay intact during capture and that guard_filter_fn only shapes the serialized guard state. That is backwards: CheckFunctionManager applies the filter to sorted_guards before it builds the runtime guard manager, so a dropped guard never triggers a recompile during capture, just as it cannot pick a graph at serve time. The docstring now says so, as does the public DynamoTracer docstring in torch/_precompile.py, which carried the same claim. The summary() comment gains the matching caveat: the varied-value rule only compares variants some kept guard split apart, so a dropped slot that is the sole difference between two calls is never reported. The nn.Module and bound-method PackageError messages ended with "calling cap(model, x)", but nothing in this module is named cap (the session hands back its _call). The clause is dropped. PrecompileSession is now Generic[_P, _R]: __init__ takes Callable[_P, _R], __enter__ returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs, so the callable from the with block keeps fn's signature instead of returning object. precompile_capture returns PrecompileSession[_P, _R], and _DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R]. Test Plan: ``` lintrunner -a torch/_dynamo/precompile_package.py torch/_precompile.py python test/dynamo/test_precompile_package.py python test/test_precompile.py ``` Both suites pass (99 and 297 tests); no test asserts on the dropped message clause. This PR was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: 8bdd4bb Pull-Request: #199065
|
Claude finished @bobrenjc93's task in 51s —— View job I found no issues. The updated PR fixes the PR Review: #199065SummaryThis PR fixes the
RecommendationApprove: nothing blocks landing. |
|
/easycla |
Follow-up to the review of #198137, which has landed; this does not amend it. The precompile_capture docstring claimed runtime guards stay intact during capture and that guard_filter_fn only shapes the serialized guard state. That is backwards: CheckFunctionManager applies the filter to sorted_guards before it builds the runtime guard manager, so a dropped guard never triggers a recompile during capture, just as it cannot pick a graph at serve time. The docstring now says so, as does the public DynamoTracer docstring in torch/_precompile.py, which carried the same claim. The summary() comment gains the matching caveat: the varied-value rule only compares variants some kept guard split apart, so a dropped slot that is the sole difference between two calls is never reported. The nn.Module and bound-method PackageError messages ended with "calling cap(model, x)", but nothing in this module is named cap (the session hands back its _call). The clause is dropped. PrecompileSession is now Generic[_P, _R]: __init__ takes Callable[_P, _R], __enter__ returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs, so the callable from the with block keeps fn's signature instead of returning object. precompile_capture returns PrecompileSession[_P, _R], and _DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R]. Test Plan: ``` lintrunner -a torch/_dynamo/precompile_package.py torch/_precompile.py python test/dynamo/test_precompile_package.py python test/test_precompile.py ``` Both suites pass (99 and 297 tests); no test asserts on the dropped message clause. This PR was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: 34c7875 Pull-Request: #199065
|
Claude finished @bobrenjc93's task in 34s —— View job The code is correct, but the PR Review: #199065SummaryThis PR does five things:
No API Design
RecommendationApprove: the wording fix above is small and doesn't need another review round. |
[ghstack-poisoned]
|
@claude review |
|
Claude finished @bobrenjc93's task in 26s —— View job I found no issues. The PR Review: #199065SummaryThis PR fixes the The RecommendationApprove: nothing blocks landing. |
Follow-up to the review of #198137, which has landed; this does not amend it. The precompile_capture docstring claimed runtime guards stay intact during capture and that guard_filter_fn only shapes the serialized guard state. That is backwards: CheckFunctionManager applies the filter to sorted_guards before it builds the runtime guard manager, so a dropped guard never triggers a recompile during capture, just as it cannot pick a graph at serve time. The docstring now says so, as does the public DynamoTracer docstring in torch/_precompile.py, which carried the same claim. The summary() comment gains the matching caveat: the varied-value rule only compares variants some kept guard split apart, so a dropped slot that is the sole difference between two calls is never reported. The nn.Module and bound-method PackageError messages ended with "calling cap(model, x)", but nothing in this module is named cap (the session hands back its _call). The clause is dropped. PrecompileSession is now Generic[_P, _R]: __init__ takes Callable[_P, _R], __enter__ returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs, so the callable from the with block keeps fn's signature instead of returning object. precompile_capture returns PrecompileSession[_P, _R], and _DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R]. Test Plan: ``` lintrunner -a torch/_dynamo/precompile_package.py torch/_precompile.py python test/dynamo/test_precompile_package.py python test/test_precompile.py ``` Both suites pass (99 and 297 tests); no test asserts on the dropped message clause. This PR was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: a506835 Pull-Request: #199065
Follow-up to the review of #198137, which has landed; this does not amend it. The precompile_capture docstring claimed runtime guards stay intact during capture and that guard_filter_fn only shapes the serialized guard state. That is backwards: CheckFunctionManager applies the filter to sorted_guards before it builds the runtime guard manager, so a dropped guard never triggers a recompile during capture, just as it cannot pick a graph at serve time. The docstring now says so, as does the public DynamoTracer docstring in torch/_precompile.py, which carried the same claim. The summary() comment gains the matching caveat: the varied-value rule only compares variants some kept guard split apart, so a dropped slot that is the sole difference between two calls is never reported. The nn.Module and bound-method PackageError messages ended with "calling cap(model, x)", but nothing in this module is named cap (the session hands back its _call). The clause is dropped. PrecompileSession is now Generic[_P, _R]: __init__ takes Callable[_P, _R], __enter__ returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs, so the callable from the with block keeps fn's signature instead of returning object. precompile_capture returns PrecompileSession[_P, _R], and _DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R]. Test Plan: ``` lintrunner -a torch/_dynamo/precompile_package.py torch/_precompile.py python test/dynamo/test_precompile_package.py python test/test_precompile.py ``` Both suites pass (99 and 297 tests); no test asserts on the dropped message clause. This PR was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: a506835 Pull-Request: #199065
Follow-up to the review of #198137, which has landed; this does not amend it. The precompile_capture docstring claimed runtime guards stay intact during capture and that guard_filter_fn only shapes the serialized guard state. That is backwards: CheckFunctionManager applies the filter to sorted_guards before it builds the runtime guard manager, so a dropped guard never triggers a recompile during capture, just as it cannot pick a graph at serve time. The docstring now says so, as does the public DynamoTracer docstring in torch/_precompile.py, which carried the same claim. The summary() comment gains the matching caveat: the varied-value rule only compares variants some kept guard split apart, so a dropped slot that is the sole difference between two calls is never reported. The nn.Module and bound-method PackageError messages ended with "calling cap(model, x)", but nothing in this module is named cap (the session hands back its _call). The clause is dropped. PrecompileSession is now Generic[_P, _R]: __init__ takes Callable[_P, _R], __enter__ returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs, so the callable from the with block keeps fn's signature instead of returning object. precompile_capture returns PrecompileSession[_P, _R], and _DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R]. Test Plan: ``` lintrunner -a torch/_dynamo/precompile_package.py torch/_precompile.py python test/dynamo/test_precompile_package.py python test/test_precompile.py ``` Both suites pass (99 and 297 tests); no test asserts on the dropped message clause. This PR was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: a506835 Pull-Request: #199065
Follow-up to the review of #198137, which has landed; this does not amend it. The precompile_capture docstring claimed runtime guards stay intact during capture and that guard_filter_fn only shapes the serialized guard state. That is backwards: CheckFunctionManager applies the filter to sorted_guards before it builds the runtime guard manager, so a dropped guard never triggers a recompile during capture, just as it cannot pick a graph at serve time. The docstring now says so, as does the public DynamoTracer docstring in torch/_precompile.py, which carried the same claim. The summary() comment gains the matching caveat: the varied-value rule only compares variants some kept guard split apart, so a dropped slot that is the sole difference between two calls is never reported. The nn.Module and bound-method PackageError messages ended with "calling cap(model, x)", but nothing in this module is named cap (the session hands back its _call). The clause is dropped. PrecompileSession is now Generic[_P, _R]: __init__ takes Callable[_P, _R], __enter__ returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs, so the callable from the with block keeps fn's signature instead of returning object. precompile_capture returns PrecompileSession[_P, _R], and _DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R]. Test Plan: ``` lintrunner -a torch/_dynamo/precompile_package.py torch/_precompile.py python test/dynamo/test_precompile_package.py python test/test_precompile.py ``` Both suites pass (99 and 297 tests); no test asserts on the dropped message clause. This PR was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: a506835 Pull-Request: #199065
Follow-up to the review of #198137, which has landed; this does not amend it. The precompile_capture docstring claimed runtime guards stay intact during capture and that guard_filter_fn only shapes the serialized guard state. That is backwards: CheckFunctionManager applies the filter to sorted_guards before it builds the runtime guard manager, so a dropped guard never triggers a recompile during capture, just as it cannot pick a graph at serve time. The docstring now says so, as does the public DynamoTracer docstring in torch/_precompile.py, which carried the same claim. The summary() comment gains the matching caveat: the varied-value rule only compares variants some kept guard split apart, so a dropped slot that is the sole difference between two calls is never reported. The nn.Module and bound-method PackageError messages ended with "calling cap(model, x)", but nothing in this module is named cap (the session hands back its _call). The clause is dropped. PrecompileSession is now Generic[_P, _R]: __init__ takes Callable[_P, _R], __enter__ returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs, so the callable from the with block keeps fn's signature instead of returning object. precompile_capture returns PrecompileSession[_P, _R], and _DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R]. Test Plan: ``` lintrunner -a torch/_dynamo/precompile_package.py torch/_precompile.py python test/dynamo/test_precompile_package.py python test/test_precompile.py ``` Both suites pass (99 and 297 tests); no test asserts on the dropped message clause. This PR was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: a506835 Pull-Request: #199065
Follow-up to the review of #198137, which has landed; this does not amend it. The precompile_capture docstring claimed runtime guards stay intact during capture and that guard_filter_fn only shapes the serialized guard state. That is backwards: CheckFunctionManager applies the filter to sorted_guards before it builds the runtime guard manager, so a dropped guard never triggers a recompile during capture, just as it cannot pick a graph at serve time. The docstring now says so, as does the public DynamoTracer docstring in torch/_precompile.py, which carried the same claim. The summary() comment gains the matching caveat: the varied-value rule only compares variants some kept guard split apart, so a dropped slot that is the sole difference between two calls is never reported. The nn.Module and bound-method PackageError messages ended with "calling cap(model, x)", but nothing in this module is named cap (the session hands back its _call). The clause is dropped. PrecompileSession is now Generic[_P, _R]: __init__ takes Callable[_P, _R], __enter__ returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs, so the callable from the with block keeps fn's signature instead of returning object. precompile_capture returns PrecompileSession[_P, _R], and _DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R]. Test Plan: ``` lintrunner -a torch/_dynamo/precompile_package.py torch/_precompile.py python test/dynamo/test_precompile_package.py python test/test_precompile.py ``` Both suites pass (99 and 297 tests); no test asserts on the dropped message clause. This PR was authored with the help of an AI assistant (Claude Code). Co-Authored-By: Claude Opus 5.5 <[email protected]> ghstack-source-id: a506835 Pull-Request: #199065
[ghstack-poisoned]
|
/easycla |
|
@claude review |
|
Claude finished @bobrenjc93's task in 25s —— View job I found no issues. The diff is the same as at my 2026-10-10 review, which approved it. PR Review: #199065SummaryThis PR makes these changes:
No RecommendationApprove: nothing blocks landing. |
[ghstack-poisoned]
|
Starting merge as part of PR stack under #198777 |
…roperty (#198777) Part of the set of changes the two-phase precompile workflow needs at pytorch tip, on top of the open precompile stack that ends in #198558. In that workflow, one GPU captures the model against a fake process group of the serving world size, and then every rank replays the saved artifact with recompilation refused. The set was found by running the workflow end to end at tip on a large production FSDP2 recommendation model. Each change here was the first blocker at its step: the run got past that step once the change was applied. Each was then confirmed by removing it alone from the full set, which made the run fail again at the same point. With the full set, the replay completed on all 16 ranks for 100 batches with zero serve-time compilation. Its losses matched an uncompiled run of the same build: the first step was bit-identical, and after 100 steps the differences were within run-to-run noise. **Why precompile needs this.** A precompile artifact is loaded by a different process from the one that captured it. So each compiled frame's code object is recorded as a location, a module plus a qualname, that the loading process can look up and match against the frame Dynamo sees. Plain `torch.compile` never needs this, because it keys its cache on the live code object. A code object that cannot be located cannot be packaged, so the whole capture fails. Getters defined with `@property` are ordinary model code (a `forward` that reads `self.scale`, for example), so precompile has to locate them. In the end-to-end run: The model compiles a frame whose code is defined under a `@property`. At tip, capture failed at package save with exactly the error above. With this change, capture got past package save. **What.** `_get_code_source` records a code object's location by walking its `co_qualname` from the module with `getattr`. On a class, `getattr` returns the `property` or `functools.cached_property` descriptor, not the function inside it. So a code object that is a property getter, or a function nested in one (`C.prop.<locals>.inner`), could not be resolved. Packaging then aborted with: PackageError: Cannot resolve a fully qualified name for <code object ...>. Lookup scope: <property object ...> This change: - stops the qualname walk at a descriptor; - descends through `fget`, `fset`, `fdel` or `func`, emitting a path the loader replays with plain `getattr` (for example `.fget`); - lets the class search in `_find_code_source` look inside descriptors too. Python 3.10 has no `co_qualname`, so there this search is the only path, and before this change it skipped descriptors entirely. **Example.** ```python # owner.py import functools class Owner: @Property def prop(self): def inner(): return 1 return inner @functools.cached_property def cached(self): return 2 ``` ```python from torch._dynamo.package import CompilePackage from owner import Owner getter = vars(Owner)["prop"].fget.__code__ package = CompilePackage(None) with package.code_context(getter): pass # before: PackageError: Cannot resolve a fully qualified name for <code object prop ...>. # Lookup scope: <property object ...> # after: recorded under Owner.prop and found again through .fget; the same holds # for the nested `inner` and for Owner.cached through .func ``` Pull Request resolved: #198777 Approved by: https://github.com/pytorchgreenlight, https://github.com/MengjiaoZhou ghstack dependencies: #198558, #198920, #199065
Stack from ghstack (oldest at bottom):
Follow-up to the review of #198137, which has landed; this does not amend it.
The precompile_capture docstring claimed runtime guards stay intact during
capture and that guard_filter_fn only shapes the serialized guard state. That
is backwards: CheckFunctionManager applies the filter to sorted_guards before
it builds the runtime guard manager, so a dropped guard never triggers a
recompile during capture, just as it cannot pick a graph at serve time. The
docstring now says so, and the summary() comment gains the matching caveat:
the varied-value rule only compares variants some kept guard split apart, so a
dropped slot that is the sole difference between two calls is never reported.
The nn.Module and bound-method PackageError messages ended with "calling
cap(model, x)", but nothing in this module is named cap (the session hands back
its _call). The clause is dropped.
PrecompileSession is now Generic[_P, _R]: init takes Callable[_P, _R],
enter returns Callable[_P, _R], and _call is typed with _P.args/_P.kwargs,
so the callable from the with block keeps fn's signature instead of returning
object. precompile_capture returns PrecompileSession[_P, _R], and
_DynamoCapture, already Capture[_P, _R], now takes a PrecompileSession[_P, _R].
Test Plan:
Both suites pass (99 and 297 tests); no test asserts on the dropped message
clause.
This PR was authored with the help of an AI assistant (Claude Code).
Co-Authored-By: Claude Opus 5.5 [email protected]
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98