Skip to content

[precompile] Prepare an installed artifact at load, and let install consume it - #194394

Closed
bobrenjc93 wants to merge 2 commits into
gh/bobrenjc93/1029/basefrom
gh/bobrenjc93/1029/head
Closed

bobrenjc93 wants to merge 2 commits into
gh/bobrenjc93/1029/basefrom
gh/bobrenjc93/1029/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

An installed artifact defers its mutation to the first served call, which is
right -- the mutation should be attributable to a point in the caller's control
flow, not to the act of loading. Every way an artifact can be wrong for the host
it landed on was deferred with it, so the failure arrived several batches into a
training loop with a traceback whose top frame was _ensure.

The commit that first addressed this ran the pure half at load and threw the
result away, which paid for it twice and left backend deserialization -- the
dominant cost for inductor, and the failure install()'s own rollback comment
anticipates -- still on the first call.

Split it properly. CompilePackage.prepare() deserializes the backends and
builds the guard trees; install() consumes what it left rather than redoing
it. Nothing prepare does touches the interpreter: a guard manager reads its
example values from the state it was pickled with and only STORES the runtime
scope, so bindings install() adds afterwards to that same dict are still seen at
check time.

The prebuilt managers are keyed by the code object install() itself resolves,
not by the one prepare resolved. _lookup_code resolves a frame by name and
install binds globals as it goes, so the two could in principle disagree; keying
on install's answer means a disagreement falls back to building rather than
serving a stale tree.

_serve grows an optional prepared package. An artifact emitted before that
still serves -- its frozen driver takes one argument, and the signature is
checked -- it simply rebuilds what prepare already built.

Measured on an 8-block graph-breaking model: 3 guard trees built at load and
ZERO at the first call, against 3 and 3 before; first call 0.0045s to 0.0030s.
Deletes validate_cache_entry and _InstalledArtifact._validate.

Test Plan:

python test/test_precompile.py
python test/dynamo/test_package.py
python test/dynamo/test_guard_serialization.py
python test/dynamo/test_precompile_context.py
python test/dynamo/test_aot_compile.py

test_aot_compile.py has 3 pre-existing failures in this environment
(test_aot_compile_with_aoti*, fatal error: cuda.h).

The new test counts guard-tree builds either side of the first call and asserts
the second count is zero, which is the only thing that distinguishes this from
the throwaway version it replaces.

Authored with an AI assistant.

Differential Revision: D116962606

[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/194394

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

❌ 12 New Failures, 1 Unrelated Failure

As of commit 8166667 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 21, 2026
This was referenced Aug 21, 2026
This was referenced Aug 22, 2026
[ghstack-poisoned]
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@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/1029/head branch November 11, 2026 01:44
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