Skip to content

[precompile] support Dynamo graph breaks - #194148

Closed
bobrenjc93 wants to merge 11 commits into
gh/bobrenjc93/998/basefrom
gh/bobrenjc93/998/head
Closed

bobrenjc93 wants to merge 11 commits into
gh/bobrenjc93/998/basefrom
gh/bobrenjc93/998/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Human note:

This is the graph-break layer of the folded stack. I reviewed it separately because it adds the native cache-entry and resume-frame machinery needed to serve captured graph breaks without running Dynamo at runtime.

AI-assisted review summary:

Capture and serialize every Dynamo entry and resume frame, rebuild their dispatchers at load, and embed closure-free disabled functions with portable globals. This supports explicit graph breaks, torch._dynamo.disable, modules, keyword examples, and nested resume frames while keeping the artifact standalone.

Preserve each complete guard manager outcome vector across the examples instead of minimizing dependent guards independently. Reject identity-dependent input/environment guards rather than dropping them, so aliasing and dictionary-order relationships cannot route an input to the wrong variant.

Replaying graph breaks through a runtime Dynamo compiler was rejected because it would violate the no-runtime-recompilation contract. The generated artifact reconstructs only the captured frames and dispatchers.

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
/home/bobren/local/e/pytorch-env/bin/python -m py_compile torch/_dynamo/eval_frame.py torch/_dynamo/guards.py torch/_dynamo/package.py torch/_precompile.py torch/_precompile_driver.py
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 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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

As of commit 508db9d 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 commented Aug 20, 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 Dynamo precompile path previously required full-graph capture, so an explicit
graph break or torch._dynamo.disable call could not be packaged. Guard minimization
also treated dependent guard records independently, which could route aliasing or
dictionary-order cases to the wrong variant.

Capture and serialize every Dynamo entry and resume frame, rebuild their dispatchers
at load, and embed closure-free disabled functions with portable globals. Guard
reduction now preserves each complete manager's outcome vector across the examples;
identity-dependent example guards are rejected instead of being discarded during
capture. Compiled graphs and Inductor kernels remain readable Python, while only guard
state and required bytecode stay opaque.

I considered replaying graph breaks through a runtime Dynamo compiler, but that would
violate the artifact's no-runtime-recompilation contract. Reconstructing the captured
resume frames keeps the artifact standalone and deterministic.

Test Plan:

```
/home/bobren/local/b/pytorch-env/bin/python agent_space/run_precompile_overlay.py test -v -k dynamo
```

```
/home/bobren/local/b/pytorch-env/bin/python agent_space/run_precompile_overlay.py test -v TestPrecompile.test_tracer_default_and_explicit_make_fx TestPrecompile.test_cache_envelope_is_weights_only_safe TestPrecompile.test_example_inputs_is_keyword_only TestPrecompile.test_make_fx_requires_one_example_input_num_examples_0 TestPrecompile.test_make_fx_requires_one_example_input_num_examples_2
```

```
PATH=/home/bobren/.conda/envs/xlformers_finetune_conda-newest/bin:$PATH TMPDIR=/home/bobren/local/e/pytorch/agent_space/precompile-example-inputs/agent_space/lintrunner_tmp UV_OFFLINE=1 lintrunner -a
```

```
/home/bobren/local/b/pytorch-env/bin/python agent_space/run_precompile_overlay.py example
```

Authored with an AI assistant.


ghstack-source-id: 2d4d0a0
Pull-Request: #194148
@bobrenjc93 bobrenjc93 changed the title [AI-assisted] torch.compiler.precompile: support Dynamo graph breaks [precompile] support Dynamo graph breaks Aug 24, 2026
[ghstack-poisoned]
[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests labels Aug 25, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Superseded by the canonical precompile stack #195353-#195362: the dynamo tracer was re-implemented in #195360 (the guard-drop policy replaces the bytecode environment-contract analyzer) and the install machinery in #195355. Closing to consolidate review there.

@bobrenjc93 bobrenjc93 closed this Sep 3, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/998/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