Skip to content

[guards] Make the bound-method reducer a fixed point over its own output - #194966

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

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

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Serializing guard state twice aborts the capture when a bound method's receiver
was pruned:

PackageError: AttributeError: '_Missing' object has no attribute 'forward'
  reached via: local_scope['pipeline']._original_forwards[0]

The branch emits a bound method -- _unpickle_bound_method(func, method_self) --
and then decides, on a later pass, whether to take that branch again by READING
the receiver: getattr(method_self, func.name). Pruning replaces a receiver
no guard reaches with the _Missing sentinel, so the second pass reads the name
off a sentinel and dies. func.name is what supplies the "forward" in the
message; the _Missing is the method's self, not the value the path names.

Only torch.compiler.precompile's public path serializes twice: it sets
_prune_invariant_guards, so PrecompileSession.exit runs _apply_guard_policy,
which rebuilds each frame from the pickle capture already made, with
save_guards=True. The capture session's _drop_unrebuildable_guards probes
without save_guards and never re-pickles, so the same model captured fine there
and aborted here.

Decide from the receiver's FATE instead of reading it. When the receiver is, or
is about to become, the sentinel, carry the binding unconditionally. The branch
then reduces its own output to itself, which is the property the second pass
needs, and the reduction stops depending on the receiver resolving the name at
load -- which is a second bug: where the attribute was NOT shadowed the branch
fell through to pickle's default method reduce, (getattr, (self, name)), and
raised a raw unwrapped AttributeError out of pickle.loads on the serving
machine.

The method stays a real method. Degrading it to the sentinel instead also stops
the abort, and was the first thing I tried, but it re-pins a TYPE_MATCH on the
method to _Missing: the artifact captures, loads, and then matches no live
receiver ever again. An abort is better than a permanent silent serve-miss, so
the test asserts SERVING rather than capture -- that assertion is the only thing
that distinguishes the two fixes.

Nothing extra is retained: the receiver still ships as the sentinel, and only
the encoding of an already-serialized method changes.

Not the cause, but worth recording while it is fresh. The pruning invariant
holds -- get_guard_manager_from_source recurses into source.base, so a guard on
x.a.b registers x and x.a too, and a value on a guard's path is never pruned.
The receiver here is reached by no guard at all. Separately,
_prune_unguarded_attributes marking an exact list/dict/tuple/set is a silent
no-op, because CPython's C pickler never routes exact builtins through
reducer_override; that is why the method was in the pickle to begin with.

Test Plan:

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

test_precompile_serves_a_bound_method_whose_receiver_was_pruned is parametrized
over the eight shapes this family has -- receiver an nn.Module or a plain
object, the attribute shadowed or not, the saved method read by the region or
only carried -- and each one captures, loads, and is checked against eager.
Three abort on the unfixed tree and two more die in pickle.loads.

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 27, 2026
@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Aug 27, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 13 New Failures, 2 Unrelated Failures

As of commit 234af16 with merge base 1b4e490 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but was 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.

This was referenced Aug 26, 2026
This was referenced Aug 26, 2026
[ghstack-poisoned]
@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/1076/head branch November 11, 2026 01:47
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