Skip to content

[precompile] The capture session, the public capture entry point, and guard-state pickling - #195924

Closed
bobrenjc93 wants to merge 58 commits into
gh/bobrenjc93/1126/basefrom
gh/bobrenjc93/1126/head
Closed

bobrenjc93 wants to merge 58 commits into
gh/bobrenjc93/1126/basefrom
gh/bobrenjc93/1126/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

This is where multi-graph capture becomes usable end to end. It lands the
PrecompileSession that drives a capture, the public precompile.capture
entry point built on it, and the session save path (save /
snapshot_artifact) that writes the (python_code, cache) artifact. The
guard-state pickling fix below is what lets a round-tripping capture serialize
its guards at all.

The guard-drop policy re-serializes a loaded guard state, and that second
pass exposed pickler defects the one-shot path never hit. The pickle now keeps
a guard's own subject out of value pruning (a TENSOR_MATCH carries its subject
in its create_fn partial, and when the source root round-trips by alias that
copy is a different object from the one the source walk reaches), shares equal
user_stack objects so the memo folds them, re-reduces a _Missing sentinel
compactly, carries a tensor's guard-traversed Python attributes in the pickle
STATE slot (after the tensor is memoized, so a self-referential attribute
terminates) and a wrapper subclass's requires_grad, keeps a retained-grad
non-leaf's .grad, and makes the bound-method reducer a fixed point over its own
output through _reduces_to_missing, which mirrors every rule under which
reducer_override substitutes _Missing. Dimension markings register in the
guard tree where they are read, so serialization no longer prunes them.
Precompile's own served-artifact handles reduce to _Missing rather than
losing the frame to an unpicklable condition variable.

test_opaque_obj_v2's reducer_override check now unpacks the (func, args) head
explicitly and asserts the full pickle round-trips.

Test Plan:

python test/dynamo/test_guard_serialization.py
python test/test_opaque_obj_v2.py -k pickle
python test/test_precompile.py -k bound_method_whose_receiver -k pruned_receiver -k tensor_attribute_round_trips -k marked_artifact_serves -k shadowing_fake_tensor -k module_global_tensor
python test/test_precompile.py

Authored with an AI assistant.

[no ci]

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

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

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]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
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