Skip to content

[precompile] Check an installed artifact against its host at load - #194320

Closed
bobrenjc93 wants to merge 3 commits into
gh/bobrenjc93/1019/basefrom
gh/bobrenjc93/1019/head
Closed

bobrenjc93 wants to merge 3 commits into
gh/bobrenjc93/1019/basefrom
gh/bobrenjc93/1019/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

An installed artifact does not touch the interpreter until its first served
call. That is deliberate and worth keeping -- the mutation should be
attributable to a point in the caller's control flow rather than to the act of
loading -- but every way an artifact can be wrong for the host it landed on was
deferred along with it. In practice that means the failure arrives in the middle
of a training step, several batches in, with a traceback whose top frame is
_ensure and whose bottom is a bare AttributeError from inside a guard
build.

Run the pure half at load and discard it: constructing the package performs the
torch-version and inlined-source checks, and each frame's guard tree is rebuilt
against a COPY of its module dict, so a build cannot write into the user's
module. Nothing is installed, so the deferral the design wanted is intact.

Unconditional rather than a validate= opt-in. The caller who needs it is the
one who will not pass it, and the cost is small next to the install it precedes:
0.09s of guard building on the largest artifact here, against a 0.12s install.

One class stays deferred and is worth naming: backend deserialization. It is the
dominant install cost for inductor and the one install()'s own rollback
comment anticipates, but it is not pure, so moving it means splitting
install() into a prepare and a commit phase -- a change to a function that
also serves precompile_load and caching-precompile, and one whose hoist of
_lookup_code past the globals that install binds I could not convince
myself was safe in general. Left for its own change.

Test Plan:

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

The new test injects an artifact whose guards do not rebuild -- the commits
below refuse to produce one -- asserts it is in the installed serving mode, and
then asserts load() is what raises. Without this change the same artifact
loads clean and dies on the first call, which is the behaviour being fixed.

Authored with an AI assistant.

Differential Revision: D116884331

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

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

❌ 24 New Failures, 1 Unrelated Failure

As of commit 337ffe0 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
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 21, 2026
This was referenced Aug 22, 2026
[ghstack-poisoned]
[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/1019/head branch November 12, 2026 01:45
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