Skip to content

[precompile] complete Dynamo artifact capture parity - #194413

Closed
bobrenjc93 wants to merge 12 commits into
gh/bobrenjc93/1032/basefrom
gh/bobrenjc93/1032/head
Closed

bobrenjc93 wants to merge 12 commits into
gh/bobrenjc93/1032/basefrom
gh/bobrenjc93/1032/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Human note:

This is the parity and hardening layer of the folded stack. I reviewed it separately because it makes the safety contract explicit and adds the diagnostics and serving controls needed to audit an incomplete artifact.

AI-assisted review summary:

Finalize every captured code object variant from a single example-execution pass, carry typed capture summaries and input contracts into the artifact, and support standalone and isolated installed serving. Expose recompilation, dynamic-shape, completeness, dropped-guard, and invariant-report controls, with eager and Inductor training support.

Classify guard state by provenance. Unsupported process-local state may be omitted only when it comes from the caller-promised invariant environment; the same state remains an error when reached from an explicit input. Preserve direct guarded objects, replace only unguarded unsupported references with _Missing, and reject artifacts whose required guards cannot be reconstructed.

Reject precompile-time behavior that can mutate caller-promised environment state or depend on an input/environment identity relation that runtime guards cannot reproduce. The bytecode dataflow now follows control flow, descriptors, protocol methods, callbacks, container contents, unpacking, generator yields, and local-function results; unmodeled native wrappers that retain mutable environment objects fail closed when dereferenced.

Pin the artifact to compatible Python and torch versions, avoid importing unrelated module globals into the generated namespace, clean up capture-only globals and cache entries, and document that environment drift is unchecked and can silently miscompute.

Test Plan:

PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k tracer_dynamo -f
PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k rejects_indirect_environment_mutation -f
PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py guard_pickler
UV_OFFLINE=1 PATH=/home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin:/home/bobren/local/e/pytorch-env/bin:/home/bobren/.local/bin:/usr/local/bin:/usr/bin:/bin /home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin/lintrunner -a

This change was authored with assistance from an AI coding tool.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194413

Note: Links to docs will display an error until the docs builds have been completed.

❌ 19 New Failures, 1 Unrelated Failure, 1 Unclassified Failure

As of commit c4aa3bd with merge base ab5fb26 (image):

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:

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.

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Aug 21, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

bobrenjc93 added a commit that referenced this pull request Aug 22, 2026
The earlier Dynamo path could serve captured variants, but it did not yet expose the
package capture's coverage controls, installed-frame behavior, eager training support,
or enough guard diagnostics to make incomplete artifacts auditable. Guard portability
also treated process-local state as a serialization requirement even when that state
was part of the caller-promised invariant environment. A weak reference inside a
WeakValueDictionary could therefore refuse an otherwise valid artifact because its
callback cannot be reconstructed.

Finalize each code object's captured variants from the single example execution pass,
carry typed capture summaries and input contracts into the generated artifact, and
support both standalone and isolated installed serving modes. The public API now
exposes recompilation, dynamic-shape, completeness, dropped-guard, and invariant-report
controls, and training works with both eager and Inductor backends while retaining
readable generated graph and kernel source.

Guard filtering now records source provenance and distinguishes explicit-input state
from the invariant Python environment. Guards that traverse unsupported process-local
objects are omitted as ordinary contract assumptions only when their source is outside
the explicit inputs; the same guards remain risky when reached from an input. This
removes the weakref callback landmine without weakening input-driven dispatch.

Test Plan:

```
TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python test/test_precompile.py
```

```
TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python test/dynamo/test_package.py
```

```
TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python test/dynamo/test_guard_serialization.py
```

```
/home/bobren/local/e/pytorch-env/bin/python -m py_compile test/dynamo/test_aot_autograd_cache.py test/dynamo/test_ctx_manager.py test/dynamo/test_guard_serialization.py test/dynamo/test_repros.py test/test_precompile.py torch/_dynamo/eval_frame.py torch/_dynamo/graph_utils.py torch/_dynamo/guards.py torch/_dynamo/output_graph.py torch/_dynamo/package.py torch/_dynamo/pgo.py torch/_dynamo/types.py torch/_dynamo/variables/builder.py torch/_dynamo/variables/tensor.py torch/_functorch/_aot_autograd/to_standalone_python.py torch/_precompile.py torch/_precompile_driver.py torch/compiler/__init__.py torch/compiler/_precompile_types.py
```

```
PATH=/home/bobren/local/a/pytorch-env/bin:$PATH TMPDIR=$PWD/agent_space/lintrunner_tmp UV_OFFLINE=1 lintrunner -a
```

The full lintrunner invocation applied its fixes and then hit an internal Pyrefly panic.
The changed files pass the RUFF, FLAKE8, DOCSTRING_LINTER, TYPEIGNORE, TYPENOSKIP, and
NOQA linters when run directly through lintrunner.

Authored with an AI assistant.


ghstack-source-id: ac412a9
Pull-Request: #194413
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Aug 28, 2026
Human note:

This is the parity and hardening layer of the folded stack. I reviewed it separately because it makes the safety contract explicit and adds the diagnostics and serving controls needed to audit an incomplete artifact.

AI-assisted review summary:

> Finalize every captured code object variant from a single example-execution pass, carry typed capture summaries and input contracts into the artifact, and support standalone and isolated installed serving. Expose recompilation, dynamic-shape, completeness, dropped-guard, and invariant-report controls, with eager and Inductor training support.
>
> Classify guard state by provenance. Unsupported process-local state may be omitted only when it comes from the caller-promised invariant environment; the same state remains an error when reached from an explicit input. Preserve direct guarded objects, replace only unguarded unsupported references with `_Missing`, and reject artifacts whose required guards cannot be reconstructed.
>
> Reject precompile-time behavior that can mutate caller-promised environment state or depend on an input/environment identity relation that runtime guards cannot reproduce. The bytecode dataflow now follows control flow, descriptors, protocol methods, callbacks, container contents, unpacking, generator yields, and local-function results; unmodeled native wrappers that retain mutable environment objects fail closed when dereferenced.
>
> Pin the artifact to compatible Python and torch versions, avoid importing unrelated module globals into the generated namespace, clean up capture-only globals and cache entries, and document that environment drift is unchecked and can silently miscompute.
>
> Test Plan:
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k tracer_dynamo -f
> ```
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k rejects_indirect_environment_mutation -f
> ```
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py guard_pickler
> ```
>
> ```bash
> UV_OFFLINE=1 PATH=/home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin:/home/bobren/local/e/pytorch-env/bin:/home/bobren/.local/bin:/usr/local/bin:/usr/bin:/bin /home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin/lintrunner -a
> ```
>
> This change was authored with assistance from an AI coding tool.

ghstack-source-id: 96c1e6a
Pull-Request: #194413
bobrenjc93 added a commit that referenced this pull request Aug 28, 2026
Human note:

This is the parity and hardening layer of the folded stack. I reviewed it separately because it makes the safety contract explicit and adds the diagnostics and serving controls needed to audit an incomplete artifact.

AI-assisted review summary:

> Finalize every captured code object variant from a single example-execution pass, carry typed capture summaries and input contracts into the artifact, and support standalone and isolated installed serving. Expose recompilation, dynamic-shape, completeness, dropped-guard, and invariant-report controls, with eager and Inductor training support.
>
> Classify guard state by provenance. Unsupported process-local state may be omitted only when it comes from the caller-promised invariant environment; the same state remains an error when reached from an explicit input. Preserve direct guarded objects, replace only unguarded unsupported references with `_Missing`, and reject artifacts whose required guards cannot be reconstructed.
>
> Reject precompile-time behavior that can mutate caller-promised environment state or depend on an input/environment identity relation that runtime guards cannot reproduce. The bytecode dataflow now follows control flow, descriptors, protocol methods, callbacks, container contents, unpacking, generator yields, and local-function results; unmodeled native wrappers that retain mutable environment objects fail closed when dereferenced.
>
> Pin the artifact to compatible Python and torch versions, avoid importing unrelated module globals into the generated namespace, clean up capture-only globals and cache entries, and document that environment drift is unchecked and can silently miscompute.
>
> Test Plan:
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k tracer_dynamo -f
> ```
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k rejects_indirect_environment_mutation -f
> ```
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py guard_pickler
> ```
>
> ```bash
> UV_OFFLINE=1 PATH=/home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin:/home/bobren/local/e/pytorch-env/bin:/home/bobren/.local/bin:/usr/local/bin:/usr/bin:/bin /home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin/lintrunner -a
> ```
>
> This change was authored with assistance from an AI coding tool.

ghstack-source-id: 96c1e6a
Pull-Request: #194413
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Aug 28, 2026
Human note:

This is the parity and hardening layer of the folded stack. I reviewed it separately because it makes the safety contract explicit and adds the diagnostics and serving controls needed to audit an incomplete artifact.

AI-assisted review summary:

> Finalize every captured code object variant from a single example-execution pass, carry typed capture summaries and input contracts into the artifact, and support standalone and isolated installed serving. Expose recompilation, dynamic-shape, completeness, dropped-guard, and invariant-report controls, with eager and Inductor training support.
>
> Classify guard state by provenance. Unsupported process-local state may be omitted only when it comes from the caller-promised invariant environment; the same state remains an error when reached from an explicit input. Preserve direct guarded objects, replace only unguarded unsupported references with `_Missing`, and reject artifacts whose required guards cannot be reconstructed.
>
> Reject precompile-time behavior that can mutate caller-promised environment state or depend on an input/environment identity relation that runtime guards cannot reproduce. The bytecode dataflow now follows control flow, descriptors, protocol methods, callbacks, container contents, unpacking, generator yields, and local-function results; unmodeled native wrappers that retain mutable environment objects fail closed when dereferenced.
>
> Pin the artifact to compatible Python and torch versions, avoid importing unrelated module globals into the generated namespace, clean up capture-only globals and cache entries, and document that environment drift is unchecked and can silently miscompute.
>
> Test Plan:
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k tracer_dynamo -f
> ```
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k rejects_indirect_environment_mutation -f
> ```
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py guard_pickler
> ```
>
> ```bash
> UV_OFFLINE=1 PATH=/home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin:/home/bobren/local/e/pytorch-env/bin:/home/bobren/.local/bin:/usr/local/bin:/usr/bin:/bin /home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin/lintrunner -a
> ```
>
> This change was authored with assistance from an AI coding tool.

ghstack-source-id: 96c1e6a
Pull-Request: #194413
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Aug 28, 2026
Human note:

This is the parity and hardening layer of the folded stack. I reviewed it separately because it makes the safety contract explicit and adds the diagnostics and serving controls needed to audit an incomplete artifact.

AI-assisted review summary:

> Finalize every captured code object variant from a single example-execution pass, carry typed capture summaries and input contracts into the artifact, and support standalone and isolated installed serving. Expose recompilation, dynamic-shape, completeness, dropped-guard, and invariant-report controls, with eager and Inductor training support.
>
> Classify guard state by provenance. Unsupported process-local state may be omitted only when it comes from the caller-promised invariant environment; the same state remains an error when reached from an explicit input. Preserve direct guarded objects, replace only unguarded unsupported references with `_Missing`, and reject artifacts whose required guards cannot be reconstructed.
>
> Reject precompile-time behavior that can mutate caller-promised environment state or depend on an input/environment identity relation that runtime guards cannot reproduce. The bytecode dataflow now follows control flow, descriptors, protocol methods, callbacks, container contents, unpacking, generator yields, and local-function results; unmodeled native wrappers that retain mutable environment objects fail closed when dereferenced.
>
> Pin the artifact to compatible Python and torch versions, avoid importing unrelated module globals into the generated namespace, clean up capture-only globals and cache entries, and document that environment drift is unchecked and can silently miscompute.
>
> Test Plan:
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k tracer_dynamo -f
> ```
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py test -k rejects_indirect_environment_mutation -f
> ```
>
> ```bash
> PRECOMPILE_OVERLAY_ROOT=$PWD TORCH_USE_RTLD_GLOBAL=1 LD_LIBRARY_PATH=/home/bobren/local/e/pytorch-env/lib:/home/bobren/local/e/pytorch-env/lib/python3.10/site-packages/nvidia/cudnn/lib:/usr/local/cuda-12.8/lib64 /home/bobren/local/e/pytorch-env/bin/python /home/bobren/local/e/pytorch/agent_space/run_precompile_root_overlay.py guard_pickler
> ```
>
> ```bash
> UV_OFFLINE=1 PATH=/home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin:/home/bobren/local/e/pytorch-env/bin:/home/bobren/.local/bin:/usr/local/bin:/usr/bin:/bin /home/bobren/.cache/uv/archive-v0/_EbPanZVazvI1jXYMOQC9/bin/lintrunner -a
> ```
>
> This change was authored with assistance from an AI coding tool.

ghstack-source-id: 7ec47bb
Pull-Request: #194413
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Superseded by the canonical precompile stack #195353-#195362. Not carried over: the cross-scope alias ID_MATCH pin in builder.py (unverified) and the fail-closed error for make_fx + mark_unbacked deferred runtime asserts; re-file as follow-ups if wanted. Closing.

@bobrenjc93 bobrenjc93 closed this Sep 3, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1032/head branch November 11, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant