Repository navigation
[precompile] Render a multi-graph capture as standalone Python source - #195918
Closed
bobrenjc93 wants to merge 7 commits into
Closed
bobrenjc93 wants to merge 7 commits into
bobrenjc93 wants to merge 7 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195918
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 1 Unrelated FailureAs of commit 085aa48 with merge base 1ad121e ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Sep 3, 2026
Closed
Closed
Closed
This was referenced Sep 3, 2026
bobrenjc93
marked this pull request as draft
September 3, 2026 20:24
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93
added a commit
that referenced
this pull request
Sep 4, 2026
The emission half of the dynamo tracer: given a package's cache entry, its compiled backends and a summary, ``_build_multigraph_artifact`` renders the same ``(python_code, cache)`` pair the make_fx tracer returns. The file is labelled by what has a source form. What was captured -- the frames, their variant counts, the guards that could not be serialized, the values pinned to what capture saw -- is emitted as readable literals; the compiled subgraphs are rendered as source through the same aot_autograd.compile_to_python the make_fx tracer uses (they are Inductor output, not Dynamo state), and only the guard trees and the transformed bytecode, which genuinely have no source form, sit under an OPAQUE banner. Rendered blocks share one namespace and resolve their siblings as late-bound globals, so every top-level name a block defines is suffixed per subgraph, driven by AST positions rather than a text match so an attribute, a nested binding and a dotted import path stay out of the rewrite. The standalone driver (``_build_multigraph_forward``) rebuilds each frame's guard trees, binds continuations under the resume names the entry's bytecode loads, restores the entry's defaults aligned to the LAST parameters the way ``__defaults__`` is, and RAISES for a call no captured variant covers rather than compiling one. The driver keeps one globals dict per module the frames were compiled in -- a copy of that module's dict overlaid with the artifact's own bindings -- so a rendered subgraph's unsuffixed imports cannot shadow a user global the guards were written against. A capture whose entry frame Dynamo never compiled is refused at capture time, and a capture with frames the entry cannot reach is warned about here -- they run eager when served, correct but uncompiled -- with serving those by installing the next commit. ``_parse_artifact_metadata`` reads the dynamo literal set when TRACER says so (its SERVING_MODE reader is ahead of the installed mode that commit adds), the make_fx cache envelope gains a ``tracer`` tag, both make_fx drivers turn ambient autocast off on the devices the captured graph dispatches on, and ``_graph_has_dynamic_shapes`` reads ``example_value`` so a dynamic Dynamo graph is not rendered static. ``PrecompiledModule`` now derives from ``PrecompiledRunnable``, the base every loaded artifact will share. Test Plan: ``` python test/test_precompile.py python test/dynamo/test_precompile_package.py python test/functorch/test_compile_to_python.py -k dynamic_shapes ``` Authored with an AI assistant. ghstack-source-id: fd0f6d6 Pull-Request: #195918
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93
added a commit
that referenced
this pull request
Sep 5, 2026
The emission half of the dynamo tracer: given a package's cache entry, its compiled backends and a summary, ``_build_multigraph_artifact`` renders the same ``(python_code, cache)`` pair the make_fx tracer returns. The file is labelled by what has a source form. What was captured -- the frames, their variant counts, the guards that could not be serialized, the values pinned to what capture saw -- is emitted as readable literals; the compiled subgraphs are rendered as source through the same aot_autograd.compile_to_python the make_fx tracer uses (they are Inductor output, not Dynamo state), and only the guard trees and the transformed bytecode, which genuinely have no source form, sit under an OPAQUE banner. Rendered blocks share one namespace and resolve their siblings as late-bound globals, so every top-level name a block defines is suffixed per subgraph, driven by AST positions rather than a text match so an attribute, a nested binding and a dotted import path stay out of the rewrite. The standalone driver (``_build_multigraph_forward``) rebuilds each frame's guard trees, binds continuations under the resume names the entry's bytecode loads, restores the entry's defaults aligned to the LAST parameters the way ``__defaults__`` is, and RAISES for a call no captured variant covers rather than compiling one. The driver keeps one globals dict per module the frames were compiled in -- a copy of that module's dict overlaid with the artifact's own bindings -- so a rendered subgraph's unsuffixed imports cannot shadow a user global the guards were written against. A capture whose entry frame Dynamo never compiled is refused at capture time, and a capture with frames the entry cannot reach is warned about here -- they run eager when served, correct but uncompiled -- with serving those by installing the next commit. ``_parse_artifact_metadata`` reads the dynamo literal set when TRACER says so (its SERVING_MODE reader is ahead of the installed mode that commit adds), the make_fx cache envelope gains a ``tracer`` tag, both make_fx drivers turn ambient autocast off on the devices the captured graph dispatches on, and ``_graph_has_dynamic_shapes`` reads ``example_value`` so a dynamic Dynamo graph is not rendered static. ``PrecompiledModule`` now derives from ``PrecompiledRunnable``, the base every loaded artifact will share. Test Plan: ``` python test/test_precompile.py python test/dynamo/test_precompile_package.py python test/functorch/test_compile_to_python.py -k dynamic_shapes ``` Authored with an AI assistant. ghstack-source-id: 72621b9 Pull-Request: #195918
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):
The emission half of the dynamo tracer: given a package's cache entry, its
compiled backends and a summary,
_build_multigraph_artifactrenders thesame
(python_code, cache)pair the make_fx tracer returns. The file islabelled by what has a source form. What was captured -- the frames, their
variant counts, the guards that could not be serialized, the values pinned to
what capture saw -- is emitted as readable literals; the compiled subgraphs are
rendered as source through the same aot_autograd.compile_to_python the make_fx
tracer uses (they are Inductor output, not Dynamo state), and only the guard
trees and the transformed bytecode, which genuinely have no source form, sit
under an OPAQUE banner. Rendered blocks share one namespace and resolve their
siblings as late-bound globals, so every top-level name a block defines is
suffixed per subgraph, driven by AST positions rather than a text match so an
attribute, a nested binding and a dotted import path stay out of the rewrite.
The standalone driver (
_build_multigraph_forward) rebuilds each frame'sguard trees, binds continuations under the resume names the entry's bytecode
loads, restores the entry's defaults aligned to the LAST parameters the way
__defaults__is, and RAISES for a call no captured variant covers ratherthan compiling one. The driver keeps one globals dict per module the frames
were compiled in -- a copy of that module's dict overlaid with the artifact's
own bindings -- so a rendered subgraph's unsuffixed imports cannot shadow a
user global the guards were written against. A capture whose entry frame
Dynamo never compiled is refused at capture time, and a capture with frames
the entry cannot reach is warned about here -- they run eager when served,
correct but uncompiled -- with serving those by installing the next commit.
_parse_artifact_metadatareads the dynamo literal set when TRACER says so(its SERVING_MODE reader is ahead of the installed mode that commit adds),
the make_fx cache envelope gains a
tracertag, both make_fx drivers turnambient autocast off on the devices the captured graph dispatches on, and
_graph_has_dynamic_shapesreadsexample_valueso a dynamic Dynamograph is not rendered static.
PrecompiledModulenow derives fromPrecompiledRunnable, the base every loaded artifact will share.Test Plan:
Authored with an AI assistant.