Repository navigation
[no-ci] [dynamo] Make an explicit capture strict and keep it out of the ambient cache - #198089
Closed
bobrenjc93 wants to merge 4 commits into
Closed
bobrenjc93 wants to merge 4 commits into
bobrenjc93 wants to merge 4 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198089
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: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Sep 22, 2026
Closed
Closed
Closed
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Contributor
Author
|
Abandoning this stack for now; it may be reopened later. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Problem. A
CompilePackagebuilt withexplicit_capture=True(commit 5 of this stack) is a caller asking for exactly this frame, but_compilestill treated it like the ambient cache in two places. Whenserialize_guardsraised aPackageError(a guard the artifact cannot carry, such as a default argument whose__reduce__fails), the catch inCheckFunctionManagerconsulted onlytorch._dynamo.config.strict_precompile, so with that flag off the explicit capture was silently bypassed: the compile ran, a "package bypass" warning was logged, and the entry the caller wanted came back withbypassed=Trueand no guarded code. Separately, undercaching_precompile,ConvertFrameAssert.__call__recorded every package intoPrecompileContextthroughDynamoCache.record_package, so an explicit package whose caller will save it itself was also queued for the ambient cache's serialize/save path, where it would be written under itssource_idas if it were a background cache entry.Fix.
_compilenow passesstrict_error=explicit_captureintoDynamoOutput.build_guards, alongside theexplicit_capturekwarg it already threads through.CheckFunctionManageralready has the branchif strict_precompile or strict_error: raise earoundserialize_guards, so an explicit capture re-raises thePackageErrorout of the compile instead of callingbypass_package, while a plain package keeps the existing bypass-with-warning behaviour. InConvertFrameAssert.__call__, therecord_packagecall is additionally gated onnot self._package.explicit_capture, so the ambientcaching_precompilerecorder skips explicit packages. Two tests intest/dynamo/test_package.pypin each behaviour.Summary. The two changes share one idea: an explicit capture has an owner, and the owner, not the ambient machinery, decides what happens to it. For strictness, the existing
strict_errorparameter was reused rather than adding a new flag, becauseaot_compilealready passesstrict_error=Truefor exactly this reason (a caller that asked for a specific frame should hear about a guard it cannot keep), and the two paths should agree; makingexplicit_captureimplystrict_precompileglobally was rejected because it would also change the behaviour of ambient packages in the same process. For recording, filtering at theConvertFrameAssertcall site rather than insiderecord_packagekeepsDynamoCachefree of package-mode knowledge and leaves the ambient path byte-for-byte unchanged for non-explicit packages. Nothing else about the explicit package changes here: its guards are still built by commit 6's filtered save build and still land onpkg.cache_entry()viaadd_guarded_code, so the caller can save it. Commit 8 above narrows both gates further withrecord = package is not None and not package.serving, so a serving package neither raises nor records; a fresh explicit capture is never serving, so its behaviour is exactly what this commit introduces. Carved out of #195913.An unpicklable guard raises for an explicit capture and bypasses for the ambient cache
Pinned by
test_explicit_capture_raises_where_the_ambient_cache_bypasses. Thebypass_reasonstring visible on the ambient entry comes from commit 2 of this stack.An explicit package is not queued for the caching_precompile cache
Pinned by
test_explicit_capture_is_not_recorded_into_the_ambient_cache. Both snippets were run against the top of the stack, where commit 8 gates the same two lines onrecord; that gate is true for a package that is not serving, so the output is the same as at this commit.Test Plan:
The two new tests fail on the parent (the explicit capture bypasses instead of raising, and the explicit package shows up in
PrecompileContext._dynamo_cache_entries) and pass 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