Repository navigation
[no-ci] [dynamo] Derive a package's uncovered frames from its entries - #198093
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/198093
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: ❌ 11 New Failures, 1 Unclassified FailureAs of commit 3cb994c with merge base 618de55 ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Sep 22, 2026
Closed
Closed
Closed
Closed
This was referenced Sep 22, 2026
Closed
[ghstack-poisoned]
bobrenjc93
added a commit
that referenced
this pull request
Sep 22, 2026
**Problem.** A frame that entered Dynamo and came out with no guarded code is a hole in the artifact: `install()` skips that code object, so after a load the frame runs eagerly for the life of the process, and nothing on `CompilePackage` says which frames those are. The one report that exists, the summary in torch/_dynamo/precompile_package.py, recomputes the predicate off the cache entry and keys it on the bare `co_name`, so two frames that happen to share a name are two entries a reader cannot tell apart. Recording the gap the way the commit below records a truncated frame would get the common case wrong: a frame's first call may take a graph-less branch and a later call may compile a real variant, so a recorded gap would have to be un-recorded at the second call, and with the variants in the other order it would never be recorded at all. **Fix.** Adds a read-only `uncovered_frames` property to `CompilePackage` that walks the package's entries and reports each one that has a compile id, holds no guarded code and is not bypassed, as a frozenset of `"co_name (filename:firstlineno)"` strings. Nothing is recorded and nothing is serialized; every read recomputes the set from the same entries `install()` consumes. One test compiles a function that returns its input untouched through `torch._dynamo.optimize` with a package and watches the gap appear and then vanish once a variant with guarded code is added under `code_context`; the other registers two entries whose code objects share a name and differ only in filename and checks that both are reported. **Summary.** The predicate is exactly the set `install()` calls `skip_code()` on minus the entries that never entered Dynamo: it skips every entry that is not bypassed and has no guarded code whether or not the frame ran, and the ones without a compile id are resume functions generated at a graph break and never executed (registered by `add_resume_function`; only leaving `code_context` sets the compile id), which are not gaps because no call reached them. A bypassed entry is excluded because it is not skipped but re-traced on the next call and is already reported through its bypass flag and reason, and a frame that hit the recompile limit keeps its working variants installed, so it has guarded code and shows up only in `truncated_frames`. The key matches the one the commit below uses for truncated frames, so the two sets compose and two frames sharing a name stay two, which the summary's bare-name key cannot tell apart; that summary can read this property instead of recomputing the predicate. Deriving rather than recording is the point: the set is a function of the entries, so whichever order a graph-less variant and a compiling variant ran in, the frame is a gap exactly while it has no guarded code, and `add_guarded_code` closes it with no bookkeeping. The property is runtime-only and changes nothing about what is saved or installed. Carved out of #195913. ## A graph-less frame is a gap until a variant compiles ```python import torch from torch._dynamo.package import CompilePackage def fn(x): return x pkg = CompilePackage(fn) pkg.uncovered_frames # parent: AttributeError, CompilePackage has no such property # now: frozenset() torch._dynamo.optimize(backend="eager", package=pkg)(fn)(torch.randn(3)) entry = pkg._codes[fn.__code__] (entry.has_compile_id, len(entry.guarded_codes), entry.bypassed) # parent and now: (True, 0, False); the frame entered Dynamo, produced no # graph, and install() would skip_code() it after a load pkg.uncovered_frames # now: frozenset({'fn (<this file>:4)'}) with pkg.code_context(fn.__code__): pkg.add_guarded_code(b"", fn.__code__) pkg.uncovered_frames # now: frozenset(); the set is derived from the entry, so the variant that # compiled closed the gap whichever order the two variants ran in ``` Pinned by `test_uncovered_frames_follows_the_entries`. ## Two frames sharing a co_name stay two ```python from torch._dynamo.package import _DynamoCodeCacheEntry, SerializedCode def one(x): return x def two(x): return x + 0 code_a = one.__code__.replace(co_name="frame", co_filename="a.py") code_b = two.__code__.replace(co_name="frame", co_filename="b.py") pkg = CompilePackage(fn) for code in (code_a, code_b): pkg._codes[code] = _DynamoCodeCacheEntry( python_code=SerializedCode.from_code_object(code), python_module="m", function_names=[], guarded_codes=[], import_sources={}, backend_ids=[], code_source=None, install_to_global=False, has_compile_id=True, ) sorted(pkg.uncovered_frames) # now: ['frame (a.py:7)', 'frame (b.py:10)'] # keyed on the bare co_name, as the precompile_package.py summary does # today, this reads ('frame', 'frame'): two entries nobody can tell apart pkg._codes[code_a].has_compile_id = False # generated, never-executed resume code sorted(pkg.uncovered_frames) # now: ['frame (b.py:10)']; install() still skip_code()s code_a, but no call # ever reached it, so it is not a gap pkg._codes[code_b].bypassed = True sorted(pkg.uncovered_frames) # now: []; a bypassed entry is re-traced on the next call and is reported # through bypassed / bypass_reason instead ``` The first result and the bypass exclusion are pinned by `test_uncovered_frames_distinguish_frames_that_share_a_name`; the compile-id exclusion follows from the predicate and was checked by running the snippet. Test Plan: ``` python test/dynamo/test_package.py -k uncovered_frames python test/dynamo/test_package.py ``` The new tests fail on the parent, which has no `uncovered_frames` attribute, and pass here. Authored with an AI assistant. Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: 065f207 Pull-Request: #198093
[ghstack-poisoned]
bobrenjc93
added a commit
that referenced
this pull request
Sep 22, 2026
**Problem.** A frame that entered Dynamo and came out with no guarded code is a hole in the artifact: `install()` skips that code object, so after a load the frame runs eagerly for the life of the process, and nothing on `CompilePackage` says which frames those are. The one report that exists, the summary in torch/_dynamo/precompile_package.py, recomputes the predicate off the cache entry and keys it on the bare `co_name`, so two frames that happen to share a name are two entries a reader cannot tell apart. Recording the gap the way the commit below records a truncated frame would get the common case wrong: a frame's first call may take a graph-less branch and a later call may compile a real variant, so a recorded gap would have to be un-recorded at the second call, and with the variants in the other order it would never be recorded at all. **Fix.** Adds a read-only `uncovered_frames` property to `CompilePackage` that walks the package's entries and reports each one that has a compile id, holds no guarded code and is not bypassed, as a frozenset of `"co_name (filename:firstlineno)"` strings. Nothing is recorded and nothing is serialized; every read recomputes the set from the same entries `install()` consumes. One test compiles a function that returns its input untouched through `torch._dynamo.optimize` with a package and watches the gap appear and then vanish once a variant with guarded code is added under `code_context`; the other registers two entries whose code objects share a name and differ only in filename and checks that both are reported. **Summary.** The predicate is exactly the set `install()` calls `skip_code()` on minus the entries that never entered Dynamo: it skips every entry that is not bypassed and has no guarded code whether or not the frame ran, and the ones without a compile id are resume functions generated at a graph break and never executed (registered by `add_resume_function`; only leaving `code_context` sets the compile id), which are not gaps because no call reached them. A bypassed entry is excluded because it is not skipped but re-traced on the next call and is already reported through its bypass flag and reason, and a frame that hit the recompile limit keeps its working variants installed, so it has guarded code and shows up only in `truncated_frames`. The key matches the one the commit below uses for truncated frames, so the two sets compose and two frames sharing a name stay two, which the summary's bare-name key cannot tell apart; that summary can read this property instead of recomputing the predicate. Deriving rather than recording is the point: the set is a function of the entries, so whichever order a graph-less variant and a compiling variant ran in, the frame is a gap exactly while it has no guarded code, and `add_guarded_code` closes it with no bookkeeping. The property is runtime-only and changes nothing about what is saved or installed. Carved out of #195913. ## A graph-less frame is a gap until a variant compiles ```python import torch from torch._dynamo.package import CompilePackage def fn(x): return x pkg = CompilePackage(fn) pkg.uncovered_frames # parent: AttributeError, CompilePackage has no such property # now: frozenset() torch._dynamo.optimize(backend="eager", package=pkg)(fn)(torch.randn(3)) entry = pkg._codes[fn.__code__] (entry.has_compile_id, len(entry.guarded_codes), entry.bypassed) # parent and now: (True, 0, False); the frame entered Dynamo, produced no # graph, and install() would skip_code() it after a load pkg.uncovered_frames # now: frozenset({'fn (<this file>:4)'}) with pkg.code_context(fn.__code__): pkg.add_guarded_code(b"", fn.__code__) pkg.uncovered_frames # now: frozenset(); the set is derived from the entry, so the variant that # compiled closed the gap whichever order the two variants ran in ``` Pinned by `test_uncovered_frames_follows_the_entries`. ## Two frames sharing a co_name stay two ```python from torch._dynamo.package import _DynamoCodeCacheEntry, SerializedCode def one(x): return x def two(x): return x + 0 code_a = one.__code__.replace(co_name="frame", co_filename="a.py") code_b = two.__code__.replace(co_name="frame", co_filename="b.py") pkg = CompilePackage(fn) for code in (code_a, code_b): pkg._codes[code] = _DynamoCodeCacheEntry( python_code=SerializedCode.from_code_object(code), python_module="m", function_names=[], guarded_codes=[], import_sources={}, backend_ids=[], code_source=None, install_to_global=False, has_compile_id=True, ) sorted(pkg.uncovered_frames) # now: ['frame (a.py:7)', 'frame (b.py:10)'] # keyed on the bare co_name, as the precompile_package.py summary does # today, this reads ('frame', 'frame'): two entries nobody can tell apart pkg._codes[code_a].has_compile_id = False # generated, never-executed resume code sorted(pkg.uncovered_frames) # now: ['frame (b.py:10)']; install() still skip_code()s code_a, but no call # ever reached it, so it is not a gap pkg._codes[code_b].bypassed = True sorted(pkg.uncovered_frames) # now: []; a bypassed entry is re-traced on the next call and is reported # through bypassed / bypass_reason instead ``` The first result and the bypass exclusion are pinned by `test_uncovered_frames_distinguish_frames_that_share_a_name`; the compile-id exclusion follows from the predicate and was checked by running the snippet. Test Plan: ``` python test/dynamo/test_package.py -k uncovered_frames python test/dynamo/test_package.py ``` The new tests fail on the parent, which has no `uncovered_frames` attribute, and pass here. Authored with an AI assistant. Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: 5a96458 Pull-Request: #198093
[ghstack-poisoned]
bobrenjc93
added a commit
that referenced
this pull request
Sep 22, 2026
**Problem.** A frame that entered Dynamo and came out with no guarded code is a hole in the artifact: `install()` skips that code object, so after a load the frame runs eagerly for the life of the process, and nothing on `CompilePackage` says which frames those are. The one report that exists, the summary in torch/_dynamo/precompile_package.py, recomputes the predicate off the cache entry and keys it on the bare `co_name`, so two frames that happen to share a name are two entries a reader cannot tell apart. Recording the gap the way the commit below records a truncated frame would get the common case wrong: a frame's first call may take a graph-less branch and a later call may compile a real variant, so a recorded gap would have to be un-recorded at the second call, and with the variants in the other order it would never be recorded at all. **Fix.** Adds a read-only `uncovered_frames` property to `CompilePackage` that walks the package's entries and reports each one that has a compile id, holds no guarded code and is not bypassed, as a frozenset of `"co_name (filename:firstlineno)"` strings. Nothing is recorded and nothing is serialized; every read recomputes the set from the same entries `install()` consumes. One test compiles a function that returns its input untouched through `torch._dynamo.optimize` with a package and watches the gap appear and then vanish once a variant with guarded code is added under `code_context`; the other registers two entries whose code objects share a name and differ only in filename and checks that both are reported. **Summary.** The predicate is exactly the set `install()` calls `skip_code()` on minus the entries that never entered Dynamo: it skips every entry that is not bypassed and has no guarded code whether or not the frame ran, and the ones without a compile id are resume functions generated at a graph break and never executed (registered by `add_resume_function`; only leaving `code_context` sets the compile id), which are not gaps because no call reached them. A bypassed entry is excluded because it is not skipped but re-traced on the next call and is already reported through its bypass flag and reason, and a frame that hit the recompile limit keeps its working variants installed, so it has guarded code and shows up only in `truncated_frames`. The key matches the one the commit below uses for truncated frames, so the two sets compose and two frames sharing a name stay two, which the summary's bare-name key cannot tell apart; that summary can read this property instead of recomputing the predicate. Deriving rather than recording is the point: the set is a function of the entries, so whichever order a graph-less variant and a compiling variant ran in, the frame is a gap exactly while it has no guarded code, and `add_guarded_code` closes it with no bookkeeping. The property is runtime-only and changes nothing about what is saved or installed. Carved out of #195913. ## A graph-less frame is a gap until a variant compiles ```python import torch from torch._dynamo.package import CompilePackage def fn(x): return x pkg = CompilePackage(fn) pkg.uncovered_frames # parent: AttributeError, CompilePackage has no such property # now: frozenset() torch._dynamo.optimize(backend="eager", package=pkg)(fn)(torch.randn(3)) entry = pkg._codes[fn.__code__] (entry.has_compile_id, len(entry.guarded_codes), entry.bypassed) # parent and now: (True, 0, False); the frame entered Dynamo, produced no # graph, and install() would skip_code() it after a load pkg.uncovered_frames # now: frozenset({'fn (<this file>:4)'}) with pkg.code_context(fn.__code__): pkg.add_guarded_code(b"", fn.__code__) pkg.uncovered_frames # now: frozenset(); the set is derived from the entry, so the variant that # compiled closed the gap whichever order the two variants ran in ``` Pinned by `test_uncovered_frames_follows_the_entries`. ## Two frames sharing a co_name stay two ```python from torch._dynamo.package import _DynamoCodeCacheEntry, SerializedCode def one(x): return x def two(x): return x + 0 code_a = one.__code__.replace(co_name="frame", co_filename="a.py") code_b = two.__code__.replace(co_name="frame", co_filename="b.py") pkg = CompilePackage(fn) for code in (code_a, code_b): pkg._codes[code] = _DynamoCodeCacheEntry( python_code=SerializedCode.from_code_object(code), python_module="m", function_names=[], guarded_codes=[], import_sources={}, backend_ids=[], code_source=None, install_to_global=False, has_compile_id=True, ) sorted(pkg.uncovered_frames) # now: ['frame (a.py:7)', 'frame (b.py:10)'] # keyed on the bare co_name, as the precompile_package.py summary does # today, this reads ('frame', 'frame'): two entries nobody can tell apart pkg._codes[code_a].has_compile_id = False # generated, never-executed resume code sorted(pkg.uncovered_frames) # now: ['frame (b.py:10)']; install() still skip_code()s code_a, but no call # ever reached it, so it is not a gap pkg._codes[code_b].bypassed = True sorted(pkg.uncovered_frames) # now: []; a bypassed entry is re-traced on the next call and is reported # through bypassed / bypass_reason instead ``` The first result and the bypass exclusion are pinned by `test_uncovered_frames_distinguish_frames_that_share_a_name`; the compile-id exclusion follows from the predicate and was checked by running the snippet. Test Plan: ``` python test/dynamo/test_package.py -k uncovered_frames python test/dynamo/test_package.py ``` The new tests fail on the parent, which has no `uncovered_frames` attribute, and pass here. Authored with an AI assistant. Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: ae9d0d2 Pull-Request: #198093
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 frame that entered Dynamo and came out with no guarded code is a hole in the artifact:
install()skips that code object, so after a load the frame runs eagerly for the life of the process, and nothing onCompilePackagesays which frames those are. The one report that exists, the summary in torch/_dynamo/precompile_package.py, recomputes the predicate off the cache entry and keys it on the bareco_name, so two frames that happen to share a name are two entries a reader cannot tell apart. Recording the gap the way the commit below records a truncated frame would get the common case wrong: a frame's first call may take a graph-less branch and a later call may compile a real variant, so a recorded gap would have to be un-recorded at the second call, and with the variants in the other order it would never be recorded at all.Fix. Adds a read-only
uncovered_framesproperty toCompilePackagethat walks the package's entries and reports each one that has a compile id, holds no guarded code and is not bypassed, as a frozenset of"co_name (filename:firstlineno)"strings. Nothing is recorded and nothing is serialized; every read recomputes the set from the same entriesinstall()consumes. One test compiles a function that returns its input untouched throughtorch._dynamo.optimizewith a package and watches the gap appear and then vanish once a variant with guarded code is added undercode_context; the other registers two entries whose code objects share a name and differ only in filename and checks that both are reported.Summary. The predicate is exactly the set
install()callsskip_code()on minus the entries that never entered Dynamo: it skips every entry that is not bypassed and has no guarded code whether or not the frame ran, and the ones without a compile id are resume functions generated at a graph break and never executed (registered byadd_resume_function; only leavingcode_contextsets the compile id), which are not gaps because no call reached them. A bypassed entry is excluded because it is not skipped but re-traced on the next call and is already reported through its bypass flag and reason, and a frame that hit the recompile limit keeps its working variants installed, so it has guarded code and shows up only intruncated_frames. The key matches the one the commit below uses for truncated frames, so the two sets compose and two frames sharing a name stay two, which the summary's bare-name key cannot tell apart; that summary can read this property instead of recomputing the predicate. Deriving rather than recording is the point: the set is a function of the entries, so whichever order a graph-less variant and a compiling variant ran in, the frame is a gap exactly while it has no guarded code, andadd_guarded_codecloses it with no bookkeeping. The property is runtime-only and changes nothing about what is saved or installed. Carved out of #195913.A graph-less frame is a gap until a variant compiles
Pinned by
test_uncovered_frames_follows_the_entries.Two frames sharing a co_name stay two
The first result and the bypass exclusion are pinned by
test_uncovered_frames_distinguish_frames_that_share_a_name; the compile-id exclusion follows from the predicate and was checked by running the snippet.Test Plan:
The new tests fail on the parent, which has no
uncovered_framesattribute, 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