Skip to content

[guards] Build a precompiled frame's guard tree twice, not three times - #194385

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

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

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

CheckFunctionManager builds the guard tree once to answer the filter's
questions, once for the runtime manager, and once more for the serialized
subset. The first of those is unnecessary whenever there is no RUNTIME filter:
with guard_filter_fn None the runtime build already sees every guard, so it
IS the inspection build, and its builder answers make_guard_filter_entry
identically.

That is every compilation in a precompile capture, which supplies a
serialization filter and no runtime one. Deriving the entries from the runtime
builder instead deletes a whole pass per compiled frame.

Measured on a resnet18 capture at three batch sizes: 18 guard-tree builds down
to 12, capture 3.11s to 2.87s, and the artifact within 12 bytes of identical.

Ordering is preserved, which is the thing to be careful about here: the eager
inspection build exists because Guard.set_export_info EXTENDS code_list
on every build, so entries derived from a LATER build report each code part
several times over. The runtime build is still the first one, so the entries
still see each part once -- the duplication factor simply drops from three to
two.

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 new test asserts the ratio rather than an absolute count, so it does not
become a tripwire for anything that legitimately changes how many frames are
compiled.

Authored with an AI assistant.

Differential Revision: D116962608

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

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

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

As of commit fdf55cd 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 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/1022/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