Skip to content

[precompile] Always serialize shape-bearing guards - #194248

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

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

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Invariant-guard dropping is what makes a real artifact viable -- most guards
cannot be serialized at all, and of those that can the majority held identically
in every captured variant, so keeping them means refusing models over guards
that never chose anything. The rule is "it discriminated nothing", and it is
sound when there is something to discriminate between.

With a SINGLE example there is one variant per frame, so nothing can differ and
the rule drops everything: not just the shape check but every input guard, the
whole TENSOR_MATCH carrying dtype, device, stride and rank. What is left is
GLOBAL_STATE and the torch-function mode stack, which is to say a guard tree
that accepts anything -- mgr.check({"x": "hello"}) returns True. An
out-of-domain call then reaches a kernel specialized for a different shape:
loud on inductor (its size assert fires), silent on eager.

That is a degenerate case rather than the documented trade. The justification is
"held identically in every variant", and with one variant nothing was PROVED
invariant, only observed once -- which is exactly the argument the code already
makes for _UNMODELLED_GUARD_TYPES ("never shown to be constant, only never
analyzed") and then failed to apply here.

Shape-bearing guards are now exempt alongside those, on the same grounds and for
the axis a caller is most likely to vary and least likely to expect to be
unchecked. The exemption sits where the filter is APPLIED rather than in
varying_guard_slots, so what the analysis reports as discriminating is unchanged
and only the serialization decision moves.

Test Plan:

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

The new test captures one example and asserts the captured call still serves
while a different batch, a different feature dim, a different rank and a
different dtype are each refused with "no captured variant" -- all four of which
previously either crashed inside a kernel or were served unchecked.

Authored with an AI assistant.

Differential Revision: D116840941

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 11 New Failures, 1 Unrelated Failure

As of commit bf43912 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 20, 2026
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 20, 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 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.

@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/1000/head branch November 11, 2026 01:44
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