Skip to content

[precompile] Drop a guard that cannot be rebuilt instead of refusing the artifact - #194383

Closed
bobrenjc93 wants to merge 3 commits into
gh/bobrenjc93/1020/basefrom
gh/bobrenjc93/1020/head
Closed

bobrenjc93 wants to merge 3 commits into
gh/bobrenjc93/1020/basefrom
gh/bobrenjc93/1020/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Whether a guard can be rebuilt from its serialized form and whether it is worth
keeping are different questions, and the check added a few commits ago let the
first one answer the second: any frame with one unrebuildable guard cost the
whole artifact. On the model this came from, that is 48 other frames refused
over a CONSTANT_MATCH on a weakref's __callback__ -- a value that is almost
certainly None and pins nothing anyone will vary.

Whether a guard rebuilds is now decided per guard rather than per frame. That
needed a way to ask, so build_guards grows an opt-in collect mode: with a
list supplied, a guard whose create raises is recorded and skipped instead
of aborting the build, and the remaining builds in that CheckFunctionManager
skip it too. Guard.create's own traceback logging is silenced while collecting,
since the caller is going to report the guard itself.

The drop is recorded as RISKY, not as an ordinary drop, and that is the whole
safety argument. Dropping a guard is not free: a guard whose source is an
attribute leaves its companion HASATTR behind, and that one is rebuilt by
re-reading the reconstructed value, so it comes back INVERTED and routes calls
into the graph traced for the other branch -- measured at exactly 7x wrong on a
two-variant model. Recording these as risky means the default
require_no_risky_drops still refuses the artifact, and only a caller who has
already said it accepts unchecked slots gets one. The policy is the caller's,
where it was already.

The check also moves out of __exit__ and into artifact() / save().
Every other artifact-quality gate -- require_complete, require_no_risky_drops,
require_no_dropped_guards -- raises from there, where a caller can catch it and
decide. Raising out of the with block instead meant a caller who had set its
own "a bad capture must not kill my job" flag lost the job anyway, and could not
tell a refused capture from a failed training step.

On the torch.compiler.precompile path nothing new is paid: the collect rides
along on the rebuild _apply_guard_policy already does. Only a direct
precompile_capture user pays for a pass, and only where the policy did not.

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 reworked test asserts the shape this commit is about: the artifact is
refused by DEFAULT because the drop is risky, and produced under
require_no_risky_drops=False with the offending guard named in
RISKY_DROPPED_GUARDS -- for both entry points, since covering only one was the
original defect.

Two failure classes reach this without injection and are worth knowing about:
a DDP module (_unpickle_ddp_module rebuilds through DDP.__getstate__,
which deletes process_group/reducer/logger) and any capture of a function
calling torch._C._is_cow_tensor (COW_TENSOR_MATCH reads storage state no
source can name). Neither is fixed here; both now cost a recorded guard instead
of the artifact.

Authored with an AI assistant.

Differential Revision: D116962604

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 21, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 23 New Failures, 1 Unrelated Failure

As of commit 2162c1a 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 21, 2026
This was referenced Aug 21, 2026
This was referenced Aug 22, 2026
[ghstack-poisoned]
[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/1020/head branch November 12, 2026 01:46
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