Skip to content

[precompile] Report guard drift and drop unrebuildable guards - #195925

Closed
bobrenjc93 wants to merge 7 commits into
gh/bobrenjc93/1127/basefrom
gh/bobrenjc93/1127/head
Closed

bobrenjc93 wants to merge 7 commits into
gh/bobrenjc93/1127/basefrom
gh/bobrenjc93/1127/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Serialization records a guard's VALUE, and rebuilding the tree walks its
SOURCE against the reconstructed scope, so a source reaching state the
reconstruction does not restore serializes fine and then fails on the serving
machine. A guard that cannot be rebuilt is now dropped, and actually removed
from the pickle that ships, with a report -- recorded as RISKY, so the default
require_no_risky_drops still refuses -- instead of the whole artifact being
refused. Its HASATTR companion leaves with it, since that guard is recomputed
from the dropped subject at load and would rebuild inverted. A guard that
rebuilds into a DIFFERENT check than the live build made is reported as drift
and refused under the same gate; drift is measured on the C++ LEAF guards of
the tree the serving machine builds, via GuardManagerWrapper.leaf_fingerprint,
so LAMBDA_GUARD and relational guards are not compared. The live leaves are
recorded through a ContextVar keyed by the guard state each variant
serializes, so drift into ANOTHER variant's value is still caught, and a
torch.compile on another thread neither records into a capture's leaves nor
clobbers another session's.
Each frame's guard tree is built twice, not three times; the probe rebuilds
pass explicit_capture, and so does load_guard_manager. The HASATTR builder
registers the attribute value for tensor bases only, where the inversion
actually occurs. Every dropped slot's rendered check is recorded as
summary().dropped_guard_code and the artifact's DROPPED_GUARD_CODE section,
so the drop lists can be audited; save() shares _gated_summary rather than
duplicating the gate code. The policy pass only drops environment-rooted slots
(_environment_rooted) and judges a Guard's DERIVED types too.

Test Plan:

python test/test_precompile.py -k cannot_be_rebuilt -k guard_drift_is_reported -k records_what_each_dropped_slot -k hasattr_guard_survives -k derived_type_must_survive
python test/dynamo/test_guard_serialization.py -k live_guard_leaf
python test/test_precompile.py
python test/dynamo/test_precompile_package.py
python test/dynamo/test_aot_compile.py

Authored with an AI assistant.

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

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

❌ 37 New Failures, 1 Unrelated Failure

As of commit 9cd0a96 with merge base 1ad121e (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 Sep 3, 2026
This was referenced Sep 3, 2026
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 added ciflow/trunk Trigger trunk jobs on your pull request release notes: dynamo labels Sep 4, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Sep 4, 2026
Serialization records a guard's VALUE, and rebuilding the tree walks its
SOURCE against the reconstructed scope, so a source reaching state the
reconstruction does not restore serializes fine and then fails on the serving
machine. A guard that cannot be rebuilt is now dropped, and actually removed
from the pickle that ships, with a report -- recorded as RISKY, so the default
require_no_risky_drops still refuses -- instead of the whole artifact being
refused. Its HASATTR companion leaves with it, since that guard is recomputed
from the dropped subject at load and would rebuild inverted. A guard that
rebuilds into a DIFFERENT check than the live build made is reported as drift
and refused under the same gate; drift is measured on the C++ LEAF guards of
the tree the serving machine builds, via GuardManagerWrapper.leaf_fingerprint,
so LAMBDA_GUARD and relational guards are not compared. The live leaves are
recorded through a ContextVar keyed by the guard state each variant
serializes, so drift into ANOTHER variant's value is still caught, and a
torch.compile on another thread neither records into a capture's leaves nor
clobbers another session's.
Each frame's guard tree is built twice, not three times; the probe rebuilds
pass explicit_capture, and so does load_guard_manager. The HASATTR builder
registers the attribute value for tensor bases only, where the inversion
actually occurs. Every dropped slot's rendered check is recorded as
summary().dropped_guard_code and the artifact's DROPPED_GUARD_CODE section,
so the drop lists can be audited; save() shares _gated_summary rather than
duplicating the gate code. The policy pass only drops environment-rooted slots
(_environment_rooted) and judges a Guard's DERIVED types too.

Test Plan:

```
python test/test_precompile.py -k cannot_be_rebuilt -k guard_drift_is_reported -k records_what_each_dropped_slot -k hasattr_guard_survives -k derived_type_must_survive
python test/dynamo/test_guard_serialization.py -k live_guard_leaf
python test/test_precompile.py
python test/dynamo/test_precompile_package.py
python test/dynamo/test_aot_compile.py
```

Authored with an AI assistant.

ghstack-source-id: 2dbd92f
Pull-Request: #195925
[ghstack-poisoned]
[ghstack-poisoned]
bobrenjc93 added a commit that referenced this pull request Sep 5, 2026
Serialization records a guard's VALUE, and rebuilding the tree walks its
SOURCE against the reconstructed scope, so a source reaching state the
reconstruction does not restore serializes fine and then fails on the serving
machine. A guard that cannot be rebuilt is now dropped, and actually removed
from the pickle that ships, with a report -- recorded as RISKY, so the default
require_no_risky_drops still refuses -- instead of the whole artifact being
refused. Its HASATTR companion leaves with it, since that guard is recomputed
from the dropped subject at load and would rebuild inverted. A guard that
rebuilds into a DIFFERENT check than the live build made is reported as drift
and refused under the same gate; drift is measured on the C++ LEAF guards of
the tree the serving machine builds, via GuardManagerWrapper.leaf_fingerprint,
so LAMBDA_GUARD and relational guards are not compared. The live leaves are
recorded through a ContextVar keyed by the guard state each variant
serializes, so drift into ANOTHER variant's value is still caught, and a
torch.compile on another thread neither records into a capture's leaves nor
clobbers another session's.
Each frame's guard tree is built twice, not three times; the probe rebuilds
pass explicit_capture, and so does load_guard_manager. The HASATTR builder
registers the attribute value for tensor bases only, where the inversion
actually occurs. Every dropped slot's rendered check is recorded as
summary().dropped_guard_code and the artifact's DROPPED_GUARD_CODE section,
so the drop lists can be audited; save() shares _gated_summary rather than
duplicating the gate code. The policy pass only drops environment-rooted slots
(_environment_rooted) and judges a Guard's DERIVED types too.

Test Plan:

```
python test/test_precompile.py -k cannot_be_rebuilt -k guard_drift_is_reported -k records_what_each_dropped_slot -k hasattr_guard_survives -k derived_type_must_survive
python test/dynamo/test_guard_serialization.py -k live_guard_leaf
python test/test_precompile.py
python test/dynamo/test_precompile_package.py
python test/dynamo/test_aot_compile.py
```

Authored with an AI assistant.

ghstack-source-id: 91aad8e
Pull-Request: #195925
@bobrenjc93 bobrenjc93 closed this Oct 17, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1127/head branch November 17, 2026 01:43
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant