Repository navigation
[dynamo] Give CompilePackage an explicit capture mode, a serving mode and a serialization guard filter - #198087
bobrenjc93 wants to merge 4 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198087
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, 2 Unrelated FailuresAs of commit b8294b6 with merge base 618de55 ( 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 9m 34s —— View job PR Review: #198087Pure-data plumbing that adds three construction-time modes to Full reviewPR Review: #198087SummaryAdds three keyword-only constructor arguments to API Design
Code Quality
Testing
RecommendationApprove The comment at Note: I reviewed statically and did not run |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
|
Abandoning this stack for now; it may be reopened later. |
Stack from ghstack (oldest at bottom):
Problem. A
CompilePackagetoday has exactly one job: it is the ambient cache thatcaching_precompilefills behind the user's back, so the constructor takes a function, an optional cache entry and an inlined-sources switch and nothing else. Commit 4 below taughtCheckFunctionManagerto build a separately filtered copy of the guards for serialization and to build the live guards strictly for an explicit capture, but a package has no way to say which of those it wants, soconvert_framecannot ask it. Two further situations have no representation either: a package produced bytorch.compiler.precompilethat the caller saves itself, which must not be strict-or-lenient by accident and must not also leak into the ambient cache, and a package that serves a loaded artifact, which nothing will ever save again and whose uncovered frames should compile without being recorded.Fix.
CompilePackage.__init__gains three keyword-only arguments,serialization_guard_filter_fn,explicit_captureandserving, stored on the instance and exposed through read-only properties of the same names, with the filter typed as a callable from a sequence ofGuardFilterEntryto a sequence of booleans so it matches theguard_filter_fnhook. The commit is pure data: nothing intorch/reads the properties yet. Commit 6 threads the filter and the capture flag intoDynamoOutput.build_guards, commit 7 uses the capture flag to make the compile strict and to keep the package out ofDynamoCache, and commit 8 uses the serving flag to stop recording. The new test pins that the three settings are independent and all off by default.Summary. The design point is that a package now has three modes, and they are separate flags rather than one enum or one inferred bit. The ambient
caching_precompilecache is the default with everything off; an explicit capture is a package the caller owns and saves, whose live guards stay strict and whose serialized copy may be filtered; a serving package holds a loaded artifact and only ever reads. The filter is deliberately not the capture flag: the code this was carved from originally inferred the capture mode from the filter being set, which made the filter double as a mode switch, so an ambient-cache user who only wanted to drop a guard from the saved state would silently also get strict errors and lose automatic persistence, while an explicit capture that wanted every guard saved had to pass a keep-all filter to be recognised. Keeping them independent lets commit 4'sseparate_save_buildfire for a filter alone (a second build is needed whenever the saved guards differ from the live ones) without touching the strictness or persistence decisions that only the capture flag should make. The properties are read-only because the mode is fixed at construction and consulted on every frame; a package that could switch modes between frames would leave earlier entries recorded under one policy and later ones under another. Carved out of #195913.The three settings are independent and off by default
Pinned by
test_explicit_capture_is_not_inferred_from_the_serialization_filterintest/dynamo/test_package.py. The snippet depends on nothing above this commit.The flags are keyword-only and read-only
The positional arguments of the parent constructor keep their positions, so existing callers are unaffected.
Test Plan:
The new test fails on the parent with a TypeError from the constructor 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