Skip to content

[precompile] Search the whole guard state for the unpicklable value - #194622

Closed
bobrenjc93 wants to merge 4 commits into
gh/bobrenjc93/1066/basefrom
gh/bobrenjc93/1066/head
Closed

bobrenjc93 wants to merge 4 commits into
gh/bobrenjc93/1066/basefrom
gh/bobrenjc93/1066/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

An unpicklable value in the guard state raises with its type and, since
D116962600, the attribute path that reaches it -- unless it lives outside the
two scopes, where it still arrives bare:

TypeError: cannot pickle '_thread.RLock' object

Two things were wrong, and only the second one mattered.

pickle_guards_state empties output_graph.global_scope before dumping, as
part of pruning what an AOT precompile does not need, and the diagnostic runs
afterwards from the except and reads the scope that was just emptied. Real,
fixed by snapshotting the roots first -- and on the capture that prompted this,
worth two objects, which is why it changed nothing.

The reason it changed nothing is the root set. The walk started at
local_scope + global_scope, five objects on that capture, while the pickler
walks state: the whole output graph, its guards, its guard-tree values. A
value held by a compiler internal reachable from the guards is not reachable
from either scope, so the search could not find it however well the scopes were
preserved. Both reported frames were that shape -- one a lock inside
triton.compiler, one under a resume function -- and both reported nothing
while four sibling frames in the same run reported local_scope['self']
correctly. The diagnostic was not failing to run; it was searching the wrong
five objects.

Search from state. The scopes stay as SEEDS ahead of it in the queue, so a
value living in one still reports the short readable path rather than a longer
route through the graph. The visit cap goes up accordingly: the walk runs once,
on a path that is already raising.

Test Plan:

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

Two new tests. One asserts a value reachable only through a global is found
from the snapshot and not from the pruned scope, so it fails if the snapshot is
taken a line too late. The other puts a lock on a compiler-internal-shaped
object hanging off the guards, reachable from neither scope, and asserts both
that it is now named and that a value reachable BOTH ways still reports the
short scope path -- the property that makes rooting at state an addition
rather than a regression in readability.

Not reproduced end to end. Getting an unpicklable value into a real guard state
needs a guard that reads it -- the pruning correctly discards it otherwise --
and every natural shape I built captured cleanly. The defect is plain enough on
inspection that I would rather fix it and say the tests are unit tests than
leave it because the model that hit it is not one I can run.

Authored with an AI assistant.

Differential Revision: D117286103

[ghstack-poisoned]
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 24, 2026
@pytorch-bot

pytorch-bot Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 13 New Failures, 1 Unrelated Failure

As of commit 8ad8f64 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 24, 2026
This was referenced Aug 24, 2026
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 changed the title [precompile] Keep the unpicklable-value path findable through a global [precompile] Search the whole guard state for the unpicklable value Aug 24, 2026
@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.

[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.

[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/1066/head branch November 11, 2026 01:46
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