Skip to content

[precompile] Harden the artifact install/serve lifecycle and disk writes - #195926

Closed
bobrenjc93 wants to merge 8 commits into
gh/bobrenjc93/1128/basefrom
gh/bobrenjc93/1128/head
Closed

bobrenjc93 wants to merge 8 commits into
gh/bobrenjc93/1128/basefrom
gh/bobrenjc93/1128/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

An installed artifact is now prepared once at load (CompilePackage.prepare
builds the guard trees and deserializes the backends; install() consumes them
rather than rebuilding), so an artifact that does not fit its host says so at
load instead of several batches into a training loop. Serving runs from a
private copy of the artifact's dynamo state, so a serve-time recompile no
longer writes its backend id back into the artifact and breaks the next
install; a served frame's user globals win over the artifact's own names; an
installed entry gets back the defaults its code object lost; unload() takes
back only the PrecompileContext keys this install added, and only while they
still hold the object it recorded. The installed driver checks the same
Python and torch version locks the standalone driver does and raises the
documented PrecompileError; the standalone driver carries INLINED_SOURCES and
refuses drifted inlined source, treating an absent or source-less module as
unverifiable rather than rejecting a working artifact. The package stops
shipping every inlined module's whole source, resolves code defined under
property/cached_property, and revalidates a memoized module-by-file hit.
Neither driver rebuilds closure cells for the entry: capture refuses a
closure entry, so _entry_binding carries defaults only and
_reject_uninstallable_entry_defaults refuses a tensor or unpicklable default
before the capture runs.

_write_artifact writes each half through a uniquely named scratch file
beside its target, renames both into place only after both are fsynced, and
moves the previous artifact aside first so a failed second rename puts the
previous pair back; _artifact_paths refuses one file named for both halves.
Nothing calls _write_artifact/_read_artifact/_artifact_paths yet: the on-disk
entry points that use them land above this commit, and the lifecycle tests
here drive _write_artifact directly.

Test Plan:

python test/test_precompile.py -k artifact_write -k installed_entry_keeps -k user_global_wins -k serving_does_not_mutate -k takes_back_only_its_own_keys -k foreign_torch_build -k drifted_inlined_source -k handle_lifecycle
python test/dynamo/test_precompile_package.py -k descriptor -k pybind_property -k stale_module_memo
python test/test_precompile.py
python test/dynamo/test_precompile_package.py

Authored with an AI assistant.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 14 New Failures, 5 Cancelled Jobs, 1 Unrelated Failure

As of commit aa2ae85 with merge base 1ad121e (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

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 Sep 3, 2026
This was referenced Sep 3, 2026
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request release notes: dynamo labels Sep 4, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Sep 4, 2026
An installed artifact is now prepared once at load (CompilePackage.prepare
builds the guard trees and deserializes the backends; install() consumes them
rather than rebuilding), so an artifact that does not fit its host says so at
load instead of several batches into a training loop. Serving runs from a
private copy of the artifact's dynamo state, so a serve-time recompile no
longer writes its backend id back into the artifact and breaks the next
install; a served frame's user globals win over the artifact's own names; an
installed entry gets back the defaults its code object lost; unload() takes
back only the PrecompileContext keys this install added, and only while they
still hold the object it recorded. The installed driver checks the same
Python and torch version locks the standalone driver does and raises the
documented PrecompileError; the standalone driver carries INLINED_SOURCES and
refuses drifted inlined source, treating an absent or source-less module as
unverifiable rather than rejecting a working artifact. The package stops
shipping every inlined module's whole source, resolves code defined under
property/cached_property, and revalidates a memoized module-by-file hit.
Neither driver rebuilds closure cells for the entry: capture refuses a
closure entry, so _entry_binding carries defaults only and
_reject_uninstallable_entry_defaults refuses a tensor or unpicklable default
before the capture runs.

_write_artifact writes each half through a uniquely named scratch file
beside its target, renames both into place only after both are fsynced, and
moves the previous artifact aside first so a failed second rename puts the
previous pair back; _artifact_paths refuses one file named for both halves.
Nothing calls _write_artifact/_read_artifact/_artifact_paths yet: the on-disk
entry points that use them land above this commit, and the lifecycle tests
here drive _write_artifact directly.

Test Plan:

```
python test/test_precompile.py -k artifact_write -k installed_entry_keeps -k user_global_wins -k serving_does_not_mutate -k takes_back_only_its_own_keys -k foreign_torch_build -k drifted_inlined_source -k handle_lifecycle
python test/dynamo/test_precompile_package.py -k descriptor -k pybind_property -k stale_module_memo
python test/test_precompile.py
python test/dynamo/test_precompile_package.py
```

Authored with an AI assistant.

ghstack-source-id: 9f20a0b
Pull-Request: #195926
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Sep 5, 2026
An installed artifact is now prepared once at load (CompilePackage.prepare
builds the guard trees and deserializes the backends; install() consumes them
rather than rebuilding), so an artifact that does not fit its host says so at
load instead of several batches into a training loop. Serving runs from a
private copy of the artifact's dynamo state, so a serve-time recompile no
longer writes its backend id back into the artifact and breaks the next
install; a served frame's user globals win over the artifact's own names; an
installed entry gets back the defaults its code object lost; unload() takes
back only the PrecompileContext keys this install added, and only while they
still hold the object it recorded. The installed driver checks the same
Python and torch version locks the standalone driver does and raises the
documented PrecompileError; the standalone driver carries INLINED_SOURCES and
refuses drifted inlined source, treating an absent or source-less module as
unverifiable rather than rejecting a working artifact. The package stops
shipping every inlined module's whole source, resolves code defined under
property/cached_property, and revalidates a memoized module-by-file hit.
Neither driver rebuilds closure cells for the entry: capture refuses a
closure entry, so _entry_binding carries defaults only and
_reject_uninstallable_entry_defaults refuses a tensor or unpicklable default
before the capture runs.

_write_artifact writes each half through a uniquely named scratch file
beside its target, renames both into place only after both are fsynced, and
moves the previous artifact aside first so a failed second rename puts the
previous pair back; _artifact_paths refuses one file named for both halves.
Nothing calls _write_artifact/_read_artifact/_artifact_paths yet: the on-disk
entry points that use them land above this commit, and the lifecycle tests
here drive _write_artifact directly.

Test Plan:

```
python test/test_precompile.py -k artifact_write -k installed_entry_keeps -k user_global_wins -k serving_does_not_mutate -k takes_back_only_its_own_keys -k foreign_torch_build -k drifted_inlined_source -k handle_lifecycle
python test/dynamo/test_precompile_package.py -k descriptor -k pybind_property -k stale_module_memo
python test/test_precompile.py
python test/dynamo/test_precompile_package.py
```

Authored with an AI assistant.

ghstack-source-id: 0f6d75e
Pull-Request: #195926
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

/easycla

@bobrenjc93 bobrenjc93 closed this Oct 17, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1128/head branch November 17, 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 release notes: dynamo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant