Skip to content

[precompile] Keep a guard's own subject out of the value pruning, and validate what ships - #194427

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

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

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

A TENSOR_MATCH carries its subject inside its create_fn partial, and
normalize_create_fn dereferences the weakref, so the pickle ships that copy
as well as the scope. On a SECOND serialization the two stop being the same
object: a module in global_scope round-trips by ALIAS, so the source walk
reaches the LIVE tensor and repopulates guard_tree_values with its id, while
the guard's carried copy round-trips by VALUE and comes back a FakeTensor. The
id-keyed pruning then finds the carried copy unreachable and writes
_Missing("tensor guard tree") over a KEPT guard's own subject. Load dies:

Name: "G['__import_fbgemm_gpu_dot_triton_dot_common'].E2M1_LUT"
    Create Function: TENSOR_MATCH
TypeError: _dispatch_keys(): incompatible function arguments
    Invoked with: _Missing(tensor guard tree)

Any model that reads a module-global tensor from an inlined frame hits it; no
rebinding of the global is required, though rebind-on-first-use is how it was
found. Local-rooted TENSOR_MATCHes are fine, because after load the scope entry
and the carried copy are the same object through the pickle memo.

Seed the pruning with the tensors kept guards carry. TENSOR_MATCH is the only
guard that carries one -- HASATTR, DICT_NOT_CONTAINS and DUPLICATE_INPUT carry
strings and Sources -- so this is complete for today's guard set, and subclass
inner tensors follow once the outer is in the dict. It costs +184 bytes, because
the tensor reducer stores metadata rather than data, and the guard keeps its
teeth: change the global's dtype and the artifact still refuses to serve.

The existing merge two builds down does not cover this and cannot: both sides of
it are populated by source walks, and the carried copy is never a source-walk
result.

DROPPING the guard instead was measured and rejected. With it gone, changing the
global's dtype makes an eager artifact serve correctly (eager re-dispatches) and
an INDUCTOR artifact serve float32 where eager gives float64, silently. That is
the harm _SHAPE_BEARING_GUARD_TYPES exists to prevent.

Second half: validate the pickle that SHIPS. _apply_guard_policy rebuilt the
pickle it READ and shipped the one it WROTE, and those differ on every frame --
across test_precompile.py, 230 of 230 shipped blobs were never rebuilt and 88 of
them had lost values the validated one still had. So the capture-time gate's
guarantee was "the bytes I read rebuild", not "the bytes I ship rebuild", and a
failure landed on the serving machine 35 minutes later. Both the policy path and
the session path now rebuild what they wrote and heal it through the existing
drop machinery, in a bounded loop because healing re-serializes.

Test Plan:

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

The new test writes a module with a global tensor, captures a function reading
it, serves it, and then changes the global's dtype and asserts the artifact
refuses -- the second half being the point, since a guard that survives without
discriminating is not worth keeping. It fails without the seeding.

The build-count test now counts builds PER MANAGER rather than in total, because
validating what ships is a deliberate extra build; what it pins -- no redundant
inspection build inside one manager -- is unchanged and still fails if the third
build comes back.

Authored with an AI assistant.

Differential Revision: D117030054

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 14 New Failures, 1 Unrelated Failure

As of commit dc143b7 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 22, 2026
This was referenced Aug 22, 2026
This was referenced Aug 22, 2026
[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/1034/head branch November 11, 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