Skip to content

[precompile] Record a backend for a graph the compiler short-circuited - #195215

Closed
bobrenjc93 wants to merge 1 commit into
gh/bobrenjc93/1081/basefrom
gh/bobrenjc93/1081/head
Closed

bobrenjc93 wants to merge 1 commit into
gh/bobrenjc93/1081/basefrom
gh/bobrenjc93/1081/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

A graph that runs nothing and returns nothing no longer reaches the backend:
output_graph substitutes noop_graph_call for it rather than pay a metadata
pass, a joint trace and a cache miss for a function with nothing in it. That is
a good optimization and it does not interact with torch.compile, which discards
such a frame anyway.

It interacts with capture, which does not discard it. _capture_config sets
allow_empty_graphs, so the frame stays compiled and its guards reach the
artifact -- that is the whole reason the flag exists. Dynamo's transformed
bytecode still names __compiled_fn_N, and backend_ids is derived by scanning
co_names, so the id lands in the cache entry with nothing filed behind it. The
harvest then reports it as a compiled graph that lost its code and fails the
capture:

Precompilation recorded 83 of 84 compiled backend(s), so 1 graph(s) would
reach the artifact with no code behind them: __compiled_fn_72_...

Unconditional, so no require_* gate relaxes it, and on a real model one such
frame is enough to take the whole capture down.

The id is recorded rather than excused. noop_graph_call is a module-level
function, so an EagerCacheArtifact holding it pickles by reference and
reconstructs to the same object, which keeps the entry self-consistent and
means the served artifact dispatches that frame to a no-op instead of skipping
it at install and silently running eager. Blunting the missing-backend check
instead would have traded a loud failure for a silent one, and that check has
caught real gaps.

Inductor only, in effect: the eager path already turns every cached backend
into an artifact, so it never saw this. It goes in _take_backend_artifacts
rather than _collect_backends because teardown clears cached_backends for a
non-eager backend and _collect_backends runs after it -- which is exactly the
path that was failing.

Test Plan:

python test/test_precompile.py
python test/dynamo/test_package.py
python test/dynamo/test_guard_serialization.py
python test/functorch/test_compile_to_python.py

test_precompile_records_a_backend_for_a_short_circuited_noop_graph captures a
region whose result is unused, so the graph's output prunes to nothing, and
asserts the artifact loads and serves. It fails without this change with the
verbatim error above.

The short-circuit is forced rather than provoked. Whether a real frame prunes to
an empty output depends on pruning details a toy model does not reproduce; the
test pins the packaging interaction, on a graph whose output IS already empty
and whose single call is dead, so short-circuiting it changes nothing
observable.

Authored with the assistance of an AI coding agent.

[ghstack-poisoned]
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 28, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 14 New Failures, 1 Unrelated Failure

As of commit 6971e19 with merge base 1b4e490 (image):

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.

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Aug 28, 2026
This was referenced Aug 28, 2026
This was referenced Aug 28, 2026
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Superseded by the canonical precompile stack #195353-#195362; this change lives in #195362 (with the guard-drop policy half in #195360). Closing to consolidate review there. The branch is kept on GitHub.

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

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request module: dynamo topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant