Skip to content

[aot_compile] Name guarded state that changed as a cause of the no-match report's accept line - #197300

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

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

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

This commit and [aot_compile] Say when a no-match report entry's guards accepted the call the dispatch refused (#197150, directly below) were one
commit, split for review budget: that commit gives a no-match report entry
whose tree ACCEPTS the call on the report's evaluation an explanation in place
of any guards, naming one cause; this one adds the second cause to that text.

Below this commit the entry reads <guards rejected this call twice and then accepted it here: a guard that does not answer consistently>. That is one
way a tree the dispatch ran twice and refused twice can accept on the third
evaluation. The other needs no inconsistent guard: every guard answers
consistently and the state it guards moved between the second dispatch pass
and the report. Guards read live state on each evaluation (a global's dict is
re-descended, a tensor's dtype and shape re-read), and __call__ holds no
lock across the dispatch, so a concurrent rebind of a guarded global, or an
in-place mutation of a guarded tensor, landing in the window between the
second pass's last check() and the report's check_verbose gets the same
accept; the dispatch already contemplates concurrent calls (the
_binding_verdict comment: a hint, not a lock). Naming only the first cause
sends a reader whose guarded value raced off to hunt for a nondeterministic
guard, so the entry now reads <guards rejected this call twice and then accepted it here: a guard that does not answer consistently, or guarded state that changed between those evaluations>. The branch, the continue after
it, and the class docstring are #197150's and unchanged: the docstring quotes
the entry up to accepted it here: ... and describes the condition, so it
holds for both tails.

This changes what the entry says and nothing about which calls are served.
test_no_match_message_when_guarded_state_changes_before_the_report pins the
second cause with a deterministic tree: AOT_BRANCH_SCALE is rebound to a
wrong value before the call, so [1]'s tree refuses it in both passes
(check.call_count == 2 through patch.object(manager, "check", wraps=...)),
and a wrapper around the report's check_verbose rebinds the right value
before calling through, placing the writer in the window a concurrent one
could land in; the call raises with the entry, two [ lines for two
results, and [0]'s real mismatch. The entry's full text now has two
readers, so it moves out of
test_no_match_message_when_a_guard_answers_inconsistently's inline literal
into one module constant, _ACCEPTED_IN_THE_REPORT, beside
AOT_BRANCH_SCALE, and both tests assert it; that test is otherwise
unchanged. Both build their model through _aot_compile_mode_branches(),
the helper their siblings on this path use.

Order to review: the string in AOTCompiledModel._no_match_report; then
_ACCEPTED_IN_THE_REPORT and the new test; then the first test's swap to the
constant.

FAQ: The new test plays the concurrent writer from inside the report's
own check_verbose rather than from a second thread. Why?
The window is
the few microseconds between the second pass's last check() and the
report's check_verbose; a thread that has to land a rebind in it would make
the test flaky or need a synchronisation hook in the dispatch, which is not
worth adding for a message test. The wrapper puts the rebind at exactly the
point such a writer could reach and leaves the tree alone: every evaluation
is the real tree against the real module dict, and the wrapped check()
count says both passes refused the wrong value before anything changed.

FAQ: Why two causes and not a third, the tag-safe dict-tag fast path the
dispatch comment names?
#197150's FAQ covers it: find_tag_safe_roots()
runs only with config.use_recursive_dict_tags_for_guards (default False)
and its justknob on, so that exit is unreachable on defaults, and an entry
naming it would hand a reader a hypothesis their build cannot take. Both
causes the entry names now are reachable in every build without a flag.

Test Plan:

python test/dynamo/test_aot_compile.py -k test_no_match_message_when_guarded_state_changes_before_the_report
python test/dynamo/test_aot_compile.py -k test_no_match_message_when_a_guard_answers_inconsistently
python test/dynamo/test_aot_compile.py

The whole file runs 213 tests, OK (skipped=6); the parent runs one fewer.
With the parent's aot_compile.py under this test file both tests fail on
the entry's text, ' [1] <guards rejected this call twice and then accepted it here: a guard that does not answer consistently, or guarded state that changed between those evaluations>' not found in "... [1] <guards rejected this call twice and then accepted it here: a guard that does not answer consistently>\nAdd a ModelInput ...", the new test after its check()-count
assertion passed: on the parent too both passes refuse, the report accepts,
the call is refused, and the entry names one cause. The assertion is the
entry's whole text, so the parent's tail is the mutant that cuts the new
clause.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Fable 5.1 [email protected]

[ghstack-poisoned]
@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Sep 16, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ 4 Pending, 2 Unrelated Failures

As of commit cf9ce38 with merge base 51d4378 (image):

UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Sep 16, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

This was referenced Sep 16, 2026
@bobrenjc93 bobrenjc93 changed the title [aot_compile] Name guarded state that changed as a cause of the no-match report's accept line [no-ci] [aot_compile] Name guarded state that changed as a cause of the no-match report's accept line Sep 16, 2026
bobrenjc93 added a commit that referenced this pull request Sep 16, 2026
…tch report's accept line

This commit and `[aot_compile] Say when a no-match report entry's guards
accepted the call the dispatch refused` (#197150, directly below) were one
commit, split for review budget: that commit gives a no-match report entry
whose tree ACCEPTS the call on the report's evaluation an explanation in place
of any guards, naming one cause; this one adds the second cause to that text.

Below this commit the entry reads `<guards rejected this call twice and then
accepted it here: a guard that does not answer consistently>`. That is one
way a tree the dispatch ran twice and refused twice can accept on the third
evaluation. The other needs no inconsistent guard: every guard answers
consistently and the state it guards moved between the second dispatch pass
and the report. Guards read live state on each evaluation (a global's dict is
re-descended, a tensor's dtype and shape re-read), and `__call__` holds no
lock across the dispatch, so a concurrent rebind of a guarded global, or an
in-place mutation of a guarded tensor, landing in the window between the
second pass's last `check()` and the report's `check_verbose` gets the same
accept; the dispatch already contemplates concurrent calls (the
`_binding_verdict` comment: a hint, not a lock). Naming only the first cause
sends a reader whose guarded value raced off to hunt for a nondeterministic
guard, so the entry now reads `<guards rejected this call twice and then
accepted it here: a guard that does not answer consistently, or guarded state
that changed between those evaluations>`. The branch, the `continue` after
it, and the class docstring are #197150's and unchanged: the docstring quotes
the entry up to `accepted it here: ...` and describes the condition, so it
holds for both tails.

This changes what the entry says and nothing about which calls are served.
`test_no_match_message_when_guarded_state_changes_before_the_report` pins the
second cause with a deterministic tree: `AOT_BRANCH_SCALE` is rebound to a
wrong value before the call, so `[1]`'s tree refuses it in both passes
(`check.call_count == 2` through `patch.object(manager, "check", wraps=...)`),
and a wrapper around the report's `check_verbose` rebinds the right value
before calling through, placing the writer in the window a concurrent one
could land in; the call raises with the entry, two `  [` lines for two
results, and `[0]`'s real mismatch. The entry's full text now has two
readers, so it moves out of
`test_no_match_message_when_a_guard_answers_inconsistently`'s inline literal
into one module constant, `_ACCEPTED_IN_THE_REPORT`, beside
`AOT_BRANCH_SCALE`, and both tests assert it; that test is otherwise
unchanged. Both build their model through `_aot_compile_mode_branches()`,
the helper their siblings on this path use.

Order to review: the string in `AOTCompiledModel._no_match_report`; then
`_ACCEPTED_IN_THE_REPORT` and the new test; then the first test's swap to the
constant.

> **FAQ: The new test plays the concurrent writer from inside the report's
> own `check_verbose` rather than from a second thread. Why?** The window is
> the few microseconds between the second pass's last `check()` and the
> report's `check_verbose`; a thread that has to land a rebind in it would make
> the test flaky or need a synchronisation hook in the dispatch, which is not
> worth adding for a message test. The wrapper puts the rebind at exactly the
> point such a writer could reach and leaves the tree alone: every evaluation
> is the real tree against the real module dict, and the wrapped `check()`
> count says both passes refused the wrong value before anything changed.

> **FAQ: Why two causes and not a third, the tag-safe dict-tag fast path the
> dispatch comment names?** #197150's FAQ covers it: `find_tag_safe_roots()`
> runs only with `config.use_recursive_dict_tags_for_guards` (default `False`)
> and its justknob on, so that exit is unreachable on defaults, and an entry
> naming it would hand a reader a hypothesis their build cannot take. Both
> causes the entry names now are reachable in every build without a flag.

Test Plan:

```
python test/dynamo/test_aot_compile.py -k test_no_match_message_when_guarded_state_changes_before_the_report
python test/dynamo/test_aot_compile.py -k test_no_match_message_when_a_guard_answers_inconsistently
python test/dynamo/test_aot_compile.py
```

The whole file runs 213 tests, `OK (skipped=6)`; the parent runs one fewer.
With the parent's `aot_compile.py` under this test file both tests fail on
the entry's text, `'  [1] <guards rejected this call twice and then accepted
it here: a guard that does not answer consistently, or guarded state that
changed between those evaluations>' not found in "... [1] <guards rejected
this call twice and then accepted it here: a guard that does not answer
consistently>\nAdd a ModelInput ..."`, the new test after its `check()`-count
assertion passed: on the parent too both passes refuse, the report accepts,
the call is refused, and the entry names one cause. The assertion is the
entry's whole text, so the parent's tail is the mutant that cuts the new
clause.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ghstack-source-id: 7617536
Pull-Request: #197300
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 changed the title [no-ci] [aot_compile] Name guarded state that changed as a cause of the no-match report's accept line [aot_compile] Name guarded state that changed as a cause of the no-match report's accept line Sep 16, 2026
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@claude

@claude

claude Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Claude finished @bobrenjc93's task in 16m 35s —— View job


Reviewed: the message change and the new test are correct — the only notes are a misleadingly-named test constant and two small asymmetries with the sibling test.

Full review

PR Review: #197300

Summary

Extends the no-match report's "guards accepted here after two refusals" entry to name a second cause (guarded state moved between the second dispatch pass and the report) and adds a deterministic test for it. I verified the mechanics and found no correctness problems; three minor points below.

I confirmed by reading the code (not by running it — no build/venv is available in this job):

  • patch.object(manager, "check_verbose", ...) does intercept the report's call: _live_guard_manager() (torch/_dynamo/aot_compile.py:645-650) returns self._artifacts.guard_manager, the same object the test grabs, and check_verbose is captured pre-patch so rebind_then_check does not recurse.
  • check.call_count == 2 is right for [1]: one call in the scan loop (aot_compile.py:1568), one in the re-check loop (:1578). shared/_binds_alike only gates whether prepare_f_locals re-runs, not the number of check() calls.
  • _ACCEPTED_IN_THE_REPORT is byte-exact against the f-string at aot_compile.py:1607-1609 for i=1, two-space prefix included.
  • Global restoration is ordered correctly: addCleanup is registered before the mutation, and LIFO cleanup restores the value before _hide_leaked_dynamo_globals's restore() runs (which only deletes names absent from its snapshot, so it cannot clobber it).

Code Quality

  • test/dynamo/test_aot_compile.py:605 — _ACCEPTED_IN_THE_REPORT bakes the entry index into the constant ( [1] <...>) but the name says nothing about [1]. A third test on a differently-indexed result has to either fork the literal or rename this. Since the index is the only varying part, prefer a name that says so (_ACCEPTED_IN_THE_REPORT_1) or a small formatter over the index-free tail. Fix this →

Testing

  • test/dynamo/test_aot_compile.py:2699-2731 — nothing in the new test positively pins "every guard answers consistently"; the distinction from test_no_match_message_when_a_guard_answers_inconsistently rests entirely on the absence of a probe. The sibling asserts probe.compares == 3; an equivalent positive assertion here (e.g. that AOT_BRANCH_SCALE is only ever read through the real global, or that no probe/counter is in play) would keep the two tests from drifting into the same scenario.
  • Same test — it drops the sibling's self.assertIn("Add a ModelInput", message). That trailing advice is part of what the entry sits inside, and the asymmetry between two otherwise-parallel tests reads as an omission rather than a decision.
  • Neither test asserts the full message shape (the parent stack does this elsewhere), so a regression that duplicated or reordered the explanation line while keeping the substring would pass. Low priority given len(entries) == 2.

Recommendation

Approve — the behavior change is one string, the test is deterministic and correctly targeted, and the points above are cleanups rather than blockers.

Process note: Dr. CI flags a missing release notes: label. This does change a user-visible error message, so it wants either release notes: dynamo or topic: not user facing.

| Branch: `gh/bobrenjc93/1250/head`

@bobrenjc93

Copy link
Copy Markdown
Contributor Author

Folded into #196823 (the no-match report now ships with the accepted-in-report line, the empty-parts line and the one-line normalisation); closing this slice.

@bobrenjc93 bobrenjc93 closed this Sep 16, 2026
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1250/head branch November 21, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant