Repository navigation
[dynamo] Bypass a code whose backend is missing on a copy of the cache entry - #198083
bobrenjc93 wants to merge 2 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198083
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ⏳ 6 Pending, 2 Unrelated FailuresAs of commit d49d488 with merge base 618de55 ( 🟡 GREEN LIGHT - PR requires human review:
reason: UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Claude finished @bobrenjc93's task in 13m 48s —— View job The change is correct and no existing test or production caller depended on the old in-place mutation, but the new test pins the in-process object invariant rather than the repeated-save consequence the PR description leads with. Full reviewPR Review: #198083SummaryMakes Testing
The scenario is reachable, not hypothetical. The pass-through branch is unverified. The description claims Code QualityThe stated invariant is only partly achieved, and the gap is worth a sentence in the comment. The new comment at torch/_dynamo/package.py:954-955 asserts the function is "non-mutating," and the description generalizes that to "the save path is a reader of the package's state." The copy is shallow by design, so the returned entry's This is not a live bug: the only caller of Verified, no action needed
RecommendationRequest Changes — only for the missing repeated-save regression test. The production change is correct and I would approve it as-is otherwise; the new test just does not assert the property that the description says broke, and that property is reachable from a public API. I was not able to run |
[ghstack-poisoned]
|
Thanks; both test asks are folded, and the comment now says what the copy does and does not detach. Replies per finding (the fix is in d49d488):
Fixed in d49d488:
Fixed in d49d488: the same second save asserts
Fixed in d49d488: the comment in Also since your review: the pure refactor of |
|
Claude finished @bobrenjc93's task in 5m 5s —— View job All three review findings are addressed in d49d488 and I have no further blocking comments; the second-save assertion is the one that would fail on the parent, which is exactly the gap I flagged. Follow-up review of d49d488Verification of the three findings1. Repeated-save regression test — fixed, and it does fail on the parent.
The premise the test rests on holds: the live 2. Pass-through branch — fixed. 3. Shallow-copy caveat in the comment — fixed. torch/_dynamo/package.py:954-959 now says the copy is shallow, names the shared containers, says why that suits the single caller (pickles at once), and points at One optional nitThe comment enumerates the shared containers as Also checked, no action needed
RecommendationApprove. I could not execute |
|
Abandoning this stack for now; it may be reopened later. |
Stack from ghstack (oldest at bottom):
Problem. When
PrecompileContext.create_cache_entriesstitches a saved entry together,PrecompileCacheEntry.from_cache_entrymarks every code whose backend artifact it cannot find as bypassed, so that a later load skips that code instead of installing a graph it does not have. It did this by writingbypassed = Truestraight onto the code entry it was handed. That entry is not a snapshot:PrecompileContext._dynamo_cache_entriesholds the_DynamoCacheEntrythatCompilePackage.cache_entrybuilt with the package's own_DynamoCodeCacheEntryobjects, the ones still serving this process. So a save that came up short on one backend flipped the live package to bypassed as a side effect, and since nothing in the save path ever writesbypassed = False, the flag stuck until the next recorded compile of that frame cleared it; every save in between wrote a bypassed entry even if the artifact had come back. Separately,fn_first_linenowas annotated asstr | Nonealthough it is always assignedco_firstlineno, an int.Fix.
from_cache_entryno longer mutates its input. It walks the codes, and for a code whose backend is missing it appendsdataclasses.replace(code, bypassed=True)instead of the original; codes with all their backends present are appended as they are. It then returns aPrecompileCacheEntrybuilt arounddataclasses.replace(cache_entry, codes=codes), so neither the entry nor itscodeslist is the live object. Thefn_first_linenoannotation becomesint | None. A new test intest_package.pycompiles undercaching_precompile, clears the recorded backend artifacts, saves, and checks that the saved copy is bypassed while the live entry is not.Summary. The save path is a reader of the package's state and should not be able to change what the package does next; bypassing on a copy is the smallest change that gives it that property. A shallow
dataclasses.replaceis enough because the function only ever rewrites thebypassedflag and thecodeslist; the guarded codes and import sources inside each code entry are shared with the live entry but are not written here, matching what the load path already does when it copies a bypassed code before re-tracing. The alternative of having the caller deep-copy the whole_DynamoCacheEntrybefore handing it in was rejected as much more expensive (the guards state is large) and as leaving the trap in place for any other caller. The observable output of a save is unchanged: the same codes are bypassed, the samedynamo_cache_bypassartifact is emitted, andbackend_contentholds the same artifacts. This is the bottom of the stack and later commits build on the live entry staying trustworthy: commit 2 records a bypass reason on the entry only while it is bypassed, and commit 11 derives a package's uncovered frames from which entries are not bypassed, both of which would misreport a package that a save had silently flipped. Carved out of #195913.A save whose backend is gone no longer flips the live package
Pinned by
test_saving_does_not_bypass_the_live_entryintest/dynamo/test_package.py.The copy stops at the flag; a code with its backend passes through unchanged
The pass-through and the shared-object claims follow from
cache_entrybuildingcodes=list(self._codes.values())and from the loop only replacing a code on the missing-backend branch; the bypass side is pinned by the same test as above.Test Plan:
The new test fails on the parent, where the live entry comes back bypassed, and passes here.
Authored with an AI assistant.
Co-Authored-By: Claude Fable 5.1 [email protected]
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98