Repository navigation
[dynamo] Serialize a separately built, separately filtered copy of a package's guards - #198086
bobrenjc93 wants to merge 4 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198086
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: ⏳ 54 Pending, 3 Unrelated FailuresAs of commit 533f1fa with merge base 618de55 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
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 39m 51s —— View job Reviewed — the two-build split is the right shape, but the Full reviewPR Review: #198086SummarySplits API Design
Code Quality
Testing
Performance
RecommendationRequest Changes The design is sound and the tests that exist are well-targeted. Blocking items: the unvalidated serialization-only guards (API Design), the over-broad |
[ghstack-poisoned]
[ghstack-poisoned]
|
Thanks; two of these changed the code, two changed the tests, and I am declining two with reasons below. The fixes are in 865e0d8.
Fixed in 865e0d8: the save build's
Fixed in 865e0d8: the runtime builder's keys are snapshotted before
Declined: this is the intended asymmetry.
Fixed in 865e0d8:
Declined here: that path is only reachable from a package, and the two commits above that wire it exercise it end to end (#198088 saves TENSOR_MATCH unfiltered from a bare explicit package, #198089 pins the raise on a guard the artifact cannot carry); the bypass leg is the pre-existing
Acknowledged as the cost of the design rather than fixed: the live guards of an explicit capture are the strict |
|
Claude finished @bobrenjc93's task in 36m 4s —— View job Re-reviewed 865e0d8/6592598: the two accepted fixes landed correctly and both declines are reasonable, but the new serialization same-frame check has an ordering/diagnostics problem and the narrowed Full reviewVerification of the four changes
New findings
RecommendationComment — nothing here blocks the two-build split, which is now in good shape. Finding 1 is a small, mechanical reordering worth doing before landing since it touches an existing error path; findings 2-3 are about the new code's comments matching its actual reach, with 3 carrying a concrete reachability argument I'd want either closed or pinned by a test. I could not run |
[ghstack-poisoned]
|
Thanks; the two mechanical items and the vacuous-filter item are folded, and finding 3 is answered by moving the aotautograd hand-off into a PR of its own with the direct form you suggested. The fixes are in 533f1fa.
Fixed in 533f1fa: the live manager's check runs first, so a guard both hold still fails with the named reason, and the saved copy's check now uses
Fixed in 533f1fa: the comment now says the check covers the leaf and accessor guards of the saved copy only, that the saved copy never ran
Split out: this PR no longer inherits anything from the runtime builder's tree (so a value only the live guards reach is pruned, pinned by
Fixed in 533f1fa: the three custom filters assert the guard they drop is present (
Fixed in 533f1fa: the call and its comment are gone; the memoised snapshot is built by the first Size after the split: this PR is 136 inserted lines (was 185), the new PR 59. |
|
Claude finished @bobrenjc93's task in 37m 42s —— View job Re-reviewed 533f1fa: the two diagnostics fixes from round 2 landed cleanly, but removing the Full reviewPR Review: #198086SummarySplits Verification of round-2 items
Code Quality
Testing
Performance
RecommendationRequest Changes Finding 1 is a behaviour regression against the parent with its only test deleted in the same commit. The rest of the round-2 feedback is resolved and the two-build split itself reads correctly. I could not run |
|
Abandoning this stack for now; it may be reopened later. |
Stack from ghstack (oldest at bottom):
Problem.
CheckFunctionManagerruns one guard build and hands its result to two consumers: the guard manager installed in the frame's live cache, and, undersave_guards, the pickled state a package records for a later process. Those two cannot share a build once a package captures on purpose. A save build is weaker than a live one:GuardBuilderconsultssave_guardsin several places and, when it is set, replaces a guard the artifact cannot carry with a portable but looser one (the pytreeSUPPORTED_NODESguard is demoted from an O(1)DICT_VERSIONcheck to a keys-match expansion, andSHAPE_ENVguards are captured as code parts rather than aShapeEnv), so with a single build the live cache also runs the weaker guards. A package that has to leave a non-portable guard out of its artifact had onlyguard_filter_fn, which also removes the guard from the live cache, so a later capture example that differs only in the dropped guard reuses the wrong graph instead of triggering the variant the package needs to record. And undercaching_precompilethe constructor rewritesguard_filter_fnto dropID_MATCH,CLOSURE_MATCH,WEAKREF_ALIVEandDICT_VERSIONfrom every build, live guards included.Fix.
CheckFunctionManagertakes two keyword-only arguments,serialization_guard_filter_fnandexplicit_capture. When guards are being saved and either is set,separate_save_buildis on:build_guardsruns for the runtime guards withsave_guards=False, so the installed manager is the strict live build, and a secondbuild_guardsruns withsave_guards=Trueover the serialization-filtered guard list;serialize_guardspickles from that second builder and that list. Both filters read the one snapshot of filter entries thatbuild_filter_entriesproduces, and the inspection build is still skipped when no filter exists. Aftercompile_check_fnreturns, the serialization builder'sguard_tree_valuesis seeded with the runtime builder's, so a guard dropped from the saved copy never prunes the value it named. Thecaching_precompilerewrite ofguard_filter_fnis skipped whenexplicit_captureis set. The test helper_test_serializationforwards_explicit_captureand_serialization_guard_filter_fnto the manager it saves from.Summary. The saved state has to come from a builder that ran with saving on over exactly the guards being pickled, because saving changes what the builder emits (the keys-match demotion, the shape code parts,
used_builtin_vars, the extra localsDUPLICATE_INPUTrecords), while the live manager has to come from a builder that ran with saving off; filtering the pickled guard list after one build cannot satisfy both, so a second build is the only shape that works, and it is paid only when the two copies can differ. An explicit capture always splits even without a filter, because the save build is weaker than the live one regardless of filtering; an ambient caching-precompile package (no flag, no filter) keeps the single save build it has today, so nothing changes for it. The tree-values merge exists becausepickle_guards_stateprunes any local the guard tree does not reach into a placeholder, and a dropped guard would otherwise prune a tensor the rest of the state still refers to (it comes back with no dtype and the loaded check misfires); it runs aftercompile_check_fnbecauseDuplicateInputsandStorageOverlapfetch their managers throughget_guard_manager_from_sourcein there, which is what registers those tensors, andtest_duplicate_input_survives_separate_save_buildpins that order. Skipping the ambient rewrite for an explicit capture means such a package says what its artifact omits through its own filter; without one, a non-portable guard reaches the serializer and is refused as aPackageErrorrather than silently dropped. The commit below builds the shared filter entries this relies on; the commits above giveCompilePackagethe two flags and thread them through_compile. Carved out of #195913.The filter applies to the saved copy, not to the live guards
Driven through
CheckFunctionManagerdirectly, the waytest/dynamo/test_guard_serialization.pydoes it:Pinned by
test_serialization_filter_applies_to_the_saved_copy_only.An explicit capture keeps the live guards strict
End to end, which needs the commits above (they carry the flags from
CompilePackageinto_compile); run from a file, since the package records source lines:The saved-side behaviour is pinned by
test_supported_nodes_dict_keys_match; the explicit split is exercised bytest_duplicate_input_survives_separate_save_build. A filter keyed on derived guard types would drop this guard instead: the entries come from the unsaved inspection build, where it still reads asDICT_VERSION.Dropping a guard does not drop the value it named
The merge is load-bearing when a saved guard names a value that only
compile_check_fnregisters. Underuse_lamba_guard_for_object_aliasing,DUPLICATE_INPUTnames its second input throughadditional_used_local_varswithout registering it in the builder's guard tree, and an aotautogradDuplicateInputsregisters its tensors insidecompile_check_fn, on the runtime builder:Pinned by
test_duplicate_input_survives_separate_save_build, which fails with the merge removed and with the merge moved ahead ofcompile_check_fn. Under the default aliasing guardDUPLICATE_INPUTregisters both tensors itself during the build, so the merge is a conservative superset there.The caching_precompile rewrite leaves an explicit capture alone
End to end at the top of the stack:
The ambient behaviour is pinned by the unchanged
test_id_match_with_config. An explicit capture with no filter letsID_MATCHreach the serializer, which refuses it (ID_MATCH guard cannot be serialized); here that is a bypass, and the commit above that makes explicit captures strict turns it into a raise.Test Plan:
The two new tests fail on the parent, which does not accept the new keyword arguments, and pass here; the rest of the file behaves as before.
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