Skip to content

[precompile] Drop invariant guards on exit, and write the invariants report - #195920

Closed
bobrenjc93 wants to merge 56 commits into
gh/bobrenjc93/1122/basefrom
gh/bobrenjc93/1122/head
Closed

bobrenjc93 wants to merge 56 commits into
gh/bobrenjc93/1122/basefrom
gh/bobrenjc93/1122/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Only the guards that DISCRIMINATE need to be serialized. On a 62-frame ranking
model 738 of 1207 guard slots held the same fact in every captured variant;
such a guard selects nothing, and precompile's contract -- the environment is
identical at capture and at runtime, every variation comes from the inputs --
is what licenses dropping it. Which slots discriminate is knowable only once
every variant exists, but guards are serialized per compilation as each is
produced, and a capture is not free of side effects (a training step's
gradients accumulate, BatchNorm stats advance), so re-running the examples was
never an option. _apply_guard_policy therefore runs on exit and
re-serializes each frame's guards from the pickle the capture already made,
inside the try that converts failures to PackageError.

The policy is fail-closed: only the explicit _INVARIANT_DROPPABLE_GUARD_TYPES
may be dropped, and only when rooted in the environment (a global, or sourceless
process state) -- a droppable type reached through an input is a pin on that
input and stays; shape-bearing and semantic guards survive even a single-example
capture, unmodelled and unclassified types are kept, and no-op marker types are
neither dropped nor reported. The pruned guard states are committed only after
every frame re-serialized, so a failure leaves the package and its accounting
exactly as the capture made them. Policy-dropped facts are re-marked rather than
deleted, so the invariants report -- invariants() per frame, and
write_invariants() as a file stable across runs whose header promises that
a dropped line is a precondition NOTHING checks -- lists them. The report is
written on a clean exit only; a partial capture reads exactly like a complete
one, so the session says why the file did not appear instead.

Test Plan:

python test/dynamo/test_precompile_package.py
python test/test_precompile.py

Authored with an AI assistant.

[no ci]

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

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 Sep 3, 2026
This was referenced Sep 3, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 closed this Oct 16, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1122/head branch November 17, 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 release notes: dynamo topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant