Skip to content

[precompile] Never drop the guard that pins an input's type - #194449

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

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

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

The invariant-guard policy drops every guard whose value held across all the
captured variants. TYPE_MATCH was in neither protected set, so a graph traced
for one class gets served another and returns the first one's answer:

capture obj of class A, serve class B
got=-1.9271   eager=-145.3570      no error, no warning

Ungated, unlike every other drop: not covered by require_no_risky_drops, not by
require_no_dropped_guards, no parameter to turn it off, and it ships at the
strict defaults -- RISKY_DROPPED_GUARDS is empty in the run above.

The set's own docstring already makes the argument for including it. A shape
mismatch at least crashes inside a kernel; a value or a TYPE does not, and the
value-equality guards are already here for exactly that reason. A type is the
same kind of thing.

There is a specific upstream dependency on this guard that made the drop worse
than a general hazard. PR #189482 deliberately removes an AsyncCollectiveTensor's
tensor-class guards so an ACT-traced graph can be reused for the resolved plain
tensor, and keeps that sound by REINSTALLING a TYPE_MATCH at the sites that
observe the class -- BuiltinVariable.call_isinstance and
TensorVariable.var_getattr("class"). Our policy deleted exactly that rail:

capture on an ACT, serve a plain tensor
before: got=2.0   eager=100.0      *** WRONG ***
after:  refused, "no captured variant"

That shape is not exotic for the model this came from -- a sharded TorchRec
model is full of isinstance-dispatched comm codecs.

Cost: +9.6% python_code on a resnet18 capture (872,276 -> 955,977 bytes), cache
unchanged, suites unchanged. Swapping in a structurally identical model still
works; only a different class is now refused.

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

Authored with an AI assistant.

Differential Revision: D117073084

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

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

❌ 13 New Failures, 1 Unrelated Failure, 1 Unclassified Failure

As of commit 39a7fb0 with merge base 1b4e490 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

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

This was referenced Aug 23, 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 #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/1036/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