Repository navigation
[aot_compile] Keep a no-match report entry to one line that says what its guards answered - #197134
bobrenjc93 wants to merge 11 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197134
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New Failures, 3 Pending, 1 Unclassified FailureAs of commit 0189073 with merge base 51d4378 ( 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:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
… its guards answered
This commit and `[aot_compile] Raise a report naming every input when no
compiled graph matches` (#<sibling>, the commit below) were one commit, split
for review budget: that commit raises the report, and this one owns what an
entry's line holds when its guards' verbose parts are empty or carry a line
boundary.
The report prints one line per compiled input, `[i] ` followed by the guards
`check_verbose` named for that input, joined with `; `. Two answers leave that
line saying nothing, or saying it across several lines.
A genuine failure can arrive with no parts: a set-index accessor asked about a
set shorter than the index it recorded answers false and appends nothing, so
below this commit the entry reads ` [0] ` with nothing after the index. The
call is refused either way -- the dispatch's `check()` decided that -- but the
line does not say why, and reading an empty part list as "passed" anywhere
would serve that call a graph compiled for a set of another size, so
`GuardDebugInfo.result` is what decides here and such an entry now reads
`<guard check failed without naming a guard>`. `SetIterModule` reaches it:
iterating a set guards each element through a set-index accessor, and
`drop_sequence_length_guards` keeps the `SEQUENCE_LENGTH` guard that would
otherwise name the wrong-sized set first out of the tree.
The line is a format read back with `splitlines()` -- by a reader's eye and by
the test below -- and a verbose part can carry a boundary that method breaks
on. The part embeds the guard's own source line, read through `linecache`,
whose `readlines()` ends a line at `\n` and at nothing else, so a `\x0c`,
`\x1e` or `\u2028` sitting in a comment on that line arrives in the part
intact, and one such comment prints a one-entry report as six lines, four of
them fragments of a single guard. Collapsing with `.replace("\n", " ")` would
handle `\n` and nothing else; joining `splitlines()` instead collapses exactly
the set the format is read back on, whatever the source line happens to hold.
Order to review: `_no_match_report` in torch/_dynamo/aot_compile.py (the
no-parts branch, then the `splitlines()` join), then `SetIterModule` and
`drop_sequence_length_guards` and the two tests in
test/dynamo/test_aot_compile.py.
Test Plan:
```
python test/dynamo/test_aot_compile.py -k test_no_match_message_when_a_failure_names_no_guard
python test/dynamo/test_aot_compile.py -k test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators
python test/dynamo/test_aot_compile.py
```
The whole file runs 192 tests, `OK (skipped=6)`; the parent runs two fewer.
Both tests fail with the parent's `aot_compile.py` under this test file:
`test_no_match_message_when_a_failure_names_no_guard` finds ` [0] ` with
nothing after it where it expects `[0] <guard check failed without naming a
guard>`, and `test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators`
counts `Expected 3 but got 6` lines. Disabling the no-parts branch at this
commit prints the same blank entry; replacing the `splitlines()` join with
`.replace("\n", " ")` is red with `Expected 3 but got 6`, and adding only the
form feed to that replace is red with `Expected 3 but got 5`.
`test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators` imports a
module whose guarded comment carries `\x0c`, `\x1e` and `\u2028`, and asserts
the whole report is three lines with the entry among them, plus that all three
separators reached the part and were collapsed -- without the second assertion
the first passes on a report that never saw a separator. The generated module
is written with `encoding="utf-8"`: the source carries `\u2028`, which the
Windows shards' preferred encoding (cp1252) cannot encode, so a bare
`open(..., "w")` fails there at `f.write` -- reproduced under `LC_ALL=C
PYTHONUTF8=0`.
Authored with the assistance of Claude Code.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
ghstack-source-id: b920fcc
Pull-Request: #197134
|
Claude finished @bobrenjc93's task in 29m 9s —— View job Reviewed — no blocking issues found; the two branches added to Full review of PR #197134PR Review: #197134SummaryMakes Code Quality
The empty-parts branch tests the list, then the collapse independently derives a string from the same list. Deriving parts = reason.verbose_code_parts
# Collapse every separator splitlines() reads the report back on.
joined = " ".join("; ".join(parts).splitlines())
if not joined:
# A failing accessor can answer false with no parts to quote.
lines.append(f" [{i}] <guard check failed without naming a guard>")
continue
if missing_at is None and any(map(_names_a_missing_global, parts)):
missing_at = i
lines.append(f" [{i}] {joined}")
Notes from verification (no action needed)These were the two things I expected to be wrong and were not:
RecommendationApprove Both added branches are covered by a test that fails against the parent, and the PR body records the negative controls (form-feed-only |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
|
Claude finished @bobrenjc93's task in 32m 35s —— View job Reviewed — one gap worth fixing before landing: the new placeholder branch tests the parts list rather than the string that actually gets printed, so a guard failure whose single part is the empty string still renders the bare Full review of PR #197134PR Review: #197134SummaryMakes each Code Quality
if not reason.verbose_code_parts: # <- tests the list
lines.append(f" [{i}] <guard check failed without naming a guard>")
continue
parts = reason.verbose_code_parts
...
joined = " ".join("; ".join(parts).splitlines())
lines.append(f" [{i}] {joined}") # <- prints a string derived from it
An earlier round of this review asserted this was unreachable, on the grounds that every part comes from // torch/csrc/dynamo/guards.cpp:1742-1748
GuardDebugInfo(bool result, const std::string& failed_reason, int num_guards_executed)
: GuardDebugInfo(result, num_guards_executed) {
verbose_code_parts.append(failed_reason);
}and three of its call sites pass Nothing on the way out repairs it. The binding is a plain It is reachable from an The fix is to derive the string first and branch on it, which subsumes the current test — parts = reason.verbose_code_parts
# Collapse every separator splitlines() reads the report back on.
joined = " ".join("; ".join(parts).splitlines())
if not joined.strip():
# A failing accessor can answer false with no parts to quote, and an
# exception-message part can be empty.
lines.append(f" [{i}] <guard check failed without naming a guard>")
continue
if any(map(_names_a_missing_global, parts)):
hinted.setdefault(result._missing_global_hint(), []).append(i)
lines.append(f" [{i}] {joined}")
RecommendationRequest Changes The Note: I could not execute the test file in this environment (no built |
[ghstack-poisoned]
…h matches Once module dispatch found no match, `AOTCompiledModel.__call__` fell through to `compiled_results[0]`, so the user saw whatever that one artifact's guard manager said -- with several compiled inputs, a failure report about the first one only, and no sign that the others existed or why they did not match. The dispatch commits below made the dispatch itself scan every result, re-check every result and serve an opted-out result before giving up, and kept that fall-through as the raise. This commit replaces it with a report that names every compiled input, built from the binding the dispatch already judged. This commit and the three above it -- `[aot_compile] Give the no-match report's missing-global hint one For [i, j]: line per distinct sentence` (#197149), `[aot_compile] Say when a no-match report entry's guards accepted the call the dispatch refused` (#197150) and `[aot_compile] Keep a no-match report entry to one line that says what its guards answered` (#197134) -- were one commit, split for review budget. This commit is the report: the raise, the header, one line per compiled input quoting the guards `check_verbose` named, the missing-global hint the fall-through already gave, and the closing advice. The siblings own where that hint sits, and what an entry's line holds when `check_verbose` names no guard: because the tree accepted the call, because a failing accessor named nothing, or because a part carries a line boundary. The raise carries one line per compiled input, and closes with what to do about it: add a `ModelInput`, or check whether `guard_filter_fn` KEPT a guard this call cannot satisfy. That last phrasing matters -- a guard the filter DROPPED cannot make a call fail to match, so the reverse advice sent the reader looking in the wrong place. Both levers are the capturing process's, and this report is reachable from a process that only loaded an artifact (nothing on `_load_aot_compiled_module` takes either), so the line says so rather than implying the reader holds them. When an entry's guards died on a global the process does not have, its line carries the function path's own `_missing_global_hint`, appended with ` -- ` exactly as the fall-through's `AOTCompiledFunction.__call__` appended it to `[0]`'s `GuardManager check failed` message -- the sentence worded for the scope that result's guards were resolved against (CAPTURED, SUPPLIED or RECONSTRUCTED), so the two paths say the same thing about the same scope. The hint is part of this commit rather than a follow-up because the parent already delivered it on the module path and five tests below (`test_aot_compile_module_missing_global_hint_names_the_resolved_module` and the four `deserialize_refuses_*` / `fallback_scope_hint` tests) assert its text through a module call; a report without it fails all five. Here it rides on every entry that named a missing global, as the parent's message carried it for `[0]`; giving the report one self-locating `For [i, j]:` line per distinct sentence, naming the entries that share it, and the helper a bare sentence each caller leads into, is #197149's, the next commit. The SUPPLIED wording is the parent's, unchanged: `the live scope this artifact was loaded against, here vars(<module>)`. Naming the instance's `forward` there, for a load whose guards hold the dict that attribute resolves to, is #197048's, above the siblings. The advice and that hint are independent, so a report every entry of which named a missing global carries both. Withholding the advice there would assume a new `ModelInput`'s guards must fail on the same absent name, which only holds when every path of `forward` reads that global: an entry fails on a global because ITS tree reads it, and an input captured for the branch this call takes need not read it at all -- such an input is captured and served with the name still undefined. Withholding also makes the only actionable line in the report turn on whether an unrelated global happens to be defined, and that masking is easy to hit, since guards are installed in `sorted(guards)` order and `GuardSource.LOCAL` sorts before `GLOBAL`, which sorts before `LOCAL_UNSPECIALIZED_NN_MODULE`: the root's `G` accessor fails before an `nn.Module` attribute guard runs, so the mismatch the reader needs to hear about is hidden behind the `KeyError`. The report cannot tell the two shapes apart and the advice is already hedged, so it is emitted next to the hint rather than in place of it. An entry's line quotes the guards `check_verbose` named, joined with `; `. `GuardDebugInfo.user_stack` and `num_guards_executed` are dropped on purpose: the verbose part usually embeds `# <source> # file:line in forward` already, the stack is `None` for the `KeyError on G[...]` case this report exists to explain, and one line per input is the point. Three of `check_verbose`'s answers leave that line saying nothing, or spread it over several lines, and each is a sibling's. A tree that ACCEPTS the call both dispatch passes rejected answers with no parts, so here its entry prints nothing after `[i]`; the call is refused all the same, and what the entry should say about it is #197150's. A genuine failure can also arrive with no parts, and a part can carry a boundary `splitlines()` breaks on; here such an entry prints nothing after `[i]`, or spans several lines, the call is refused either way, and those two lines are #197134's. A describer that raises is not caught here. `check_verbose` runs paths `check()` does not -- `DIMENSION_DYNAMIC_MARKING_GUARD` calls `py::repr` on user objects, and a `TENSOR_MATCH` failure on a tensor of the compiled type calls `is_parameter`, which runs `_ParameterMeta.__instancecheck__` -- so an entry's describer can raise where the dispatch's rejection was clean, and when it does the exception escapes the `raise RuntimeError(...)` argument and takes the report with it, exactly as it escaped the parent's fall-through, whose `AOTCompiledFunction.__call__` runs the same `check_verbose` unguarded. An earlier revision ran each entry's `check_verbose` under its own `try` and described the other entries anyway; that catch is unsound below #197049 and the lines it saved were wrong (FAQ below), so it is gone from here, and the place a raising tree is read as no answer and reported as one line is #196826, above the TorchFunction restore #197049 adds. One call the fall-through served is refused by the report, and that is intended: a tree that rejected the call in both dispatch passes and accepts it on a third evaluation. PARENT: for `[0]` only, the fall-through's `AOTCompiledFunction.__call__` evaluated its guards a third time and served the graph when that evaluation accepted -- with a `CountedKey(misses=2)` in the slot of the one global `[0]`'s tree reads: `SERVED equal_to_x*3= True compares= 3`. HEAD: the report's `check_verbose` is that third evaluation, an accept there leaves the entry with nothing after its index, and the call raises: `RAISED compares= 3`. An accept that arrives only on the third evaluation is not a certified match -- a guard that does not answer consistently, or a tag-safe fast path that refused without running the tree -- and the parent extended that third chance to `[0]` alone, by its position; a result in any other slot never had it. The entry that says so, and `test_no_match_message_when_a_guard_answers_inconsistently`, which pins the raise and the three evaluations, are #197150's. A model with no compiled results is not a case this commit changes: `results[0]` at the top of `__call__` raises `IndexError: tuple index out of range` before any stage runs, on the parent and here alike. Otherwise the exception type stays `RuntimeError`, and the text `GuardManager check failed` is replaced on the module path only: the function path's `__call__` still raises it, and the five regexes this commit updates in test_aot_compile.py belong to the dispatch tests below. One of those tests, `test_module_dispatch_no_match_falls_through_to_the_first_result`, was named and commented for the fall-through its zero-opt-out row now proves gone, so it is renamed `test_module_dispatch_no_match_raises_unless_a_result_opted_out` and its comment says what the rows show: a call neither result guards raises and is handed to no result, and with `[0]` opted out its graph runs. Three sibling dispatch tests named the same fall-through for the stage before or after the one they pin -- `test_module_dispatch_rechecks_an_opted_out_result_whose_tree_accepts`, `test_module_dispatch_serves_an_opted_out_result_from_any_position` and `test_module_dispatch_rechecks_before_honouring_an_opt_out` -- and their comments now name the stages the dispatch has: the opt-out last resort, then this report. Their assertions are unchanged. The report reuses the binding the dispatch judged, one per result, so it explains the same binding rather than a fresh one, and the one bind per call #197071 introduced holds end to end; the fall-through it replaces bound twice more inside `AOTCompiledFunction.__call__`. `test_module_dispatch_binds_a_call_once_for_results_sharing_a_signature` now also counts `prepare_f_locals` for a call nothing matches, and counts it apart from the matched call's: the list is asserted `[results[0]]` and cleared after the matched call, and asserted `[results[0]]` again after the no-match call, so each bind is attributed to the call that made it -- a combined `[results[0], results[0]]` would also accept a dispatch that bound the matched call nowhere and the no-match call twice. The fall-through fails the second assertion with `The length of the sequences mismatch: 3 != 1`, its no-match call binding three times. The same test counts the report's entry lines -- one per result off that single bind -- rather than its total line count, so a footer line added later does not break it. Measured once when this report was first written, against the dispatch before the one-bind-per-call commit and this commit, and not re-run since: a report costs 12.6us against the old 15.0us, and the no-match path costs 18.5us against 27.9us at one input and 29.9us against 33.0us at two, and crosses over by four, 50.9us against 41.3us, where the report's N `check_verbose` calls and the re-check's N `check()` calls outweigh the binds saved; with one bind per call rather than per result it costs 30.2us against 43.1us at four. That path ends in a raise, and the match path is the one every call takes. The report is handed the results the dispatch judged as well: `__call__` reads `compiled_results` once, and the report indexes `bound` against that tuple rather than re-reading a public list an append or a replacement can have changed under it -- re-read, an appended result asks for a binding the dispatch never made, and an `IndexError` raised inside the `raise RuntimeError(...)` argument takes the report's place. `test_no_match_report_names_the_results_the_dispatch_judged` makes `[0]`'s `check()` splice a second result into the list AHEAD of it mid-call, and asserts the report counts one input and never ran the spliced result's `check_verbose`, which is wrapped; the splice is `[:] = [later, first]`, so the re-check pass running the patched `check()` a second time leaves the list as it is. Counting alone would not pin which result an entry describes: a report that re-read the list and zipped it against `bound` would describe the spliced result against `[0]`'s binding under a `Tried 1` header, and the two results differ only in a closure scale, so their dtype-mismatch lines read alike. The second call, over the spliced list, reports `Tried 2` and runs the spliced describer once, so the watch is on the object the report reads. The supplied-scope hint on an un-rebound load is pinned by #196825, a test-only commit higher in the stack, which also pins that the advice above still reaches a report whose only failure is a missing global. Folding that commit's test lines down here would put a guarded global the loading process does not have in the same commit as this report, which is the split this re-slice exists to make; they land together in any case. Four more of the report's tests sit in #197001, above #197048, since three of them pin that commit's forward naming: that the hint stays scope-neutral for a caller-supplied `guard_globals=`, that a CAPTURED result's report names no `forward` and never resolves it, that the advice reaches a report whose every entry named a missing global, and that a missing KEY inside a present global is not a missing global. > **FAQ: an earlier revision ran each entry's `check_verbose` under its own > `try`, so one raising describer did not cost the other entries their lines. > Why is that gone?** Because below #197049 the catch continues on a thread the > throw left broken, and the lines it saves are wrong. > `RootGuardManager::check_verbose_nopybind` sets the TorchFunction TLS to > `ALL_DISABLED` for its accessors and restores it on each of its return paths, > not under RAII, so a `py::error_already_set` unwinding out of the tree skips > the restore; `_reset_relational_guard_state()` is skipped the same way, and > has no Python binding to call instead. Measured at that revision's tree with > `_ParameterMeta.__instancecheck__` patched to raise -- the Python > `is_parameter` reaches from `TENSOR_MATCH::check_verbose_nopybind`'s failure > branch, the route a tensor subclass `__getattr__` takes -- on a two-input > `ScaleModule` called with `x.double()`: the report arrived, `[0]` read `<guard > check could not be described: RuntimeError(...)>`, and `[1]` read > `GLOBAL_STATE changed: torch_function` instead of its dtype mismatch, since > `[1]`'s tree was evaluated on the thread `[0]`'s throw had left disabled; > after the report was caught, `torch._C._get_torch_function_state()` read > `ALL_DISABLED` against `ENABLED` before the call, and `t + 1` on a > `__torch_function__` subclass returned a plain `Tensor` without dispatching. > Without the `try`, the same script raises `RuntimeError('user __getattr__ > raised')` out of `__call__` on this tree and on the parent's alike, and leaves > the thread the same way -- an exposure `AOTCompiledFunction.__call__` has > always had, which #197049 repairs inside `GuardManagerWrapper.check_verbose` > for every caller. Fixing the C++ exit itself is outside this Python-only > stack. So the catch belongs above the restore, in #196826, and the test that > pinned it here, `test_no_match_report_describes_the_other_entries_when_one_raises`, > goes with it. > **FAQ: an entry whose `check_verbose` ACCEPTS the call, or fails without > naming a guard, prints nothing after `[i]` here, and a part carrying a line > boundary spans several lines. Why not branch on `reason.result` and an empty > `verbose_code_parts`, and collapse `splitlines()`, in this commit?** Because > those branches are #197150's (the entry for a tree that accepted on the third > evaluation) and #197134's (the entry for a failure that named no guard, and > the one-line collapse), split out of this commit for review budget so that > each lands next to the test that pins it and the report's plumbing here -- > the raise, the header, the per-entry join off the dispatch's own `bound` and > `results`, the hint and the advice -- stays reviewable on its own; the call > is refused all the same on every one of those answers, so nothing is served > in the meantime that a sibling later refuses. What the reader is told in the > meantime, measured at this tree against the parent's: with a > `CountedKey(misses=2)` on the global `[1]`'s tree reads and a `mode=1` call, > this tree raises `[0] L['mode'] == 0` over a blank `[1]` (`compares= 3`), > and the parent raised `[0]`'s `L['mode'] == 0` alone (`compares= 2`) -- it > never evaluated `[1]` a third time and said nothing of it, and with the probe > on a global `[0]`'s tree reads it served the graph (above); so no `result=1` > repr was ever printed for this answer. With #197134's fixture -- a > `SetIterModule` iterating a set, `SEQUENCE_LENGTH` dropped by the filter, > called with a shorter set -- this tree prints ` [0] ` blank, and the parent > printed `GuardDebugInfo(result=0, verbose_code_parts=[], num_guards_executed=6, > user_stack=None)`: no guard named either, but a `result=0` the blank entry > here does not carry. That one entry is what this commit says less about than > the fall-through did, for the three commits until #197134, which lands with > it. Neither blank entry loses a hint: the hint rides on a part that reads > `KeyError on G[...]`, matched whole by `_names_a_missing_global`, so an > answer with no parts named no missing global -- an accept has no failure to > hint, and the short-set failure is not about a global -- and the absent hint > is the accurate answer there, not a second loss. > **FAQ: a report whose entries all failed on the same missing global repeats > the hint on every one of them. Why not one hint per report here?** Because > where the hint sits is #197149's, the next commit, which gives the report one > `For [i, j]:` line per distinct sentence naming the entries that share it, > and pins the count at one in > `test_aot_compile_module_missing_global_hint_names_the_resolved_module` and > `test_no_match_message_hints_only_the_entry_that_named_a_missing_global`. > Here each entry carries its own hint, appended with ` -- ` as the > fall-through appended it to `[0]`'s message, so the five tests below that > assert the hint's text keep passing across the split. Measured at this tree, > the report `test_aot_compile_module_missing_global_hint_names_the_resolved_module` > produces on its first load is four lines, the two entries 203 characters each > and identical, with `a guarded global is missing` twice; that test asserts > the text with `assertIn`, so it sees neither count, and pinning the > repetition here only to remove it one commit up would assert something no > user is meant to rely on. The class docstring describes what this commit > does -- one line per result, carrying the hint when that result's guards > failed on a missing global -- and #197149 rewrites it for the `For` line. > **FAQ: `test_no_match_message_keeps_the_advice_for_every_entry` asserts the > hint with `assertIn` over the whole message rather than on the `[1]` line. > Why not anchor it here?** Because the hint's line is #197149's, the next > commit, which replaces that very assertion with `For [1]: a guarded global is > missing` and `message.count("a guarded global is missing") == 1` -- the > anchoring, at the placement the report keeps. Here the hint is appended to > `[1]`'s own line, and an assertion pinning it there would pin a placement the > next commit removes and be rewritten one commit up. The two substrings the > test does assert are not one check twice: `a guarded global is missing` > opens all three scopes' sentences, while `the module the compiled function > was traced in` is the CAPTURED wording alone -- SUPPLIED reads `the live > scope this artifact was loaded against` and RECONSTRUCTED `the scope rebuilt > from the artifact` -- so the second pins that an in-process capture's result > is hinted for the scope it resolved against. Test Plan: ``` python test/dynamo/test_aot_compile.py -k test_aot_compile_module_no_match_error python test/dynamo/test_aot_compile.py -k test_no_match_message_keeps_the_advice_for_every_entry python test/dynamo/test_aot_compile.py -k test_no_match_report_names_the_results_the_dispatch_judged python test/dynamo/test_aot_compile.py -k test_module_dispatch_binds_a_call_once_for_results_sharing_a_signature python test/dynamo/test_aot_compile.py -k test_module_dispatch_no_match_raises_unless_a_result_opted_out python test/dynamo/test_aot_compile.py ``` The whole file runs 208 tests, `OK (skipped=6)`; the parent's file defines three fewer. Every `-k` above fails with the parent's `aot_compile.py` under this test file (5/5): the three that assert on report text (`No AOT compiled graph matched this call`, `[0] L['mode'] == 0`, `Tried 1 compiled input(s)`) find the fall-through's `GuardManager check failed` message instead, the binding test sees three binds for the no-match call against the one it expects, `The length of the sequences mismatch: 3 != 1`, and the renamed test's zero-opt-out row finds `GuardManager check failed` where it expects `No AOT compiled graph matched` (its two opt-out rows pass on both, as they should: an opted-out `[0]` is served on the parent and here alike). `test_aot_compile_module_no_match_error` asserts that each of the two entries is one line of the report -- the two lines after the header, with unindented advice after them -- rather than that the whole report is four lines, and that each entry says something after its index: reporting an entry as `str(GuardDebugInfo)` instead of the joined one-line reason makes line 2 read `result=...` and fails it, printing ` [0] ` with nothing after the index fails it with `entry says nothing: ' [0] '`, while an advice line a later commit appends does not. Withholding the advice when an entry named a missing global fails `test_no_match_message_keeps_the_advice_for_every_entry` on `Add a ModelInput`. Reading `self.compiled_results` in the report again fails `test_no_match_report_names_the_results_the_dispatch_judged` with `IndexError: list index out of range` raised in place of the report; re-reading it zipped against `bound`, with the header off `results`, passes the header and entry counts and fails it with `Expected 'check_verbose' to not have been called. Called 1 times.` Both mutations were run at this tree. `test_no_match_message_keeps_the_advice_for_every_entry` captures through `_aot_compile_mode_branches`, whose `_hide_leaked_dynamo_globals` pops the minted globals a sibling's capture leaked and strips this test's own in cleanup (run alone in a fresh process, the inline capture it replaces left eight minted names in this module's dict -- two `__builtins_dict___*`, two `__compiled_fn_*` and four `__import_*` aliases; this form leaves none), and it registers the `AOT_BRANCH_SCALE` restore with `addCleanup` before deleting the name, so an interrupt anywhere leaves the module dict whole. Authored with the assistance of Claude Code. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: 93bb35b Pull-Request: #196823
…[i, j]: line per distinct sentence This commit and `[aot_compile] Raise a report naming every input when no compiled graph matches` (#196823, the commit below) were one commit, split for review budget: that commit raises the report and carries the fall-through's missing-global hint on each entry that named one, and this commit owns where that hint sits in the report and how the helper that words it is shared with the function path. Below this commit, the entry line for a failure on a global the process does not have ends in ` -- a guarded global is missing ...`: the sentence `_missing_global_hint` returns with its lead-in built in, appended to the entry as the fall-through's `AOTCompiledFunction.__call__` appended it to `[0]`'s `GuardManager check failed` message. On the function path that sentence continues a line of its own, and the lead-in belongs there. In the report it turns a `KeyError on G['NAME']` entry into a paragraph, and a model whose every entry reads the same absent global -- the shape `deserialize` builds, handing every result one `guard_globals` -- repeats the same advice once per entry. The report now carries the hint after the entries and before the footer, one line per DISTINCT sentence, prefixed `For [i, j]: ` with every entry that sentence is for, in first-seen order; the class docstring says so. Every entry line still carries the name it failed on. Deduplicating on the text rather than taking the first entry keeps the two shapes apart: a model `deserialize` built hands every result one scope, so its entries share one sentence and the report carries exactly one `For [0, 1]:` line; the public constructor accepts results of differing scopes, and there each scope's advice is materially different (define the name in the module the function was traced in, in the live scope the artifact was loaded against, or load with a complete `f_globals=`), so a CAPTURED `[0]` next to a SUPPLIED `[1]` gets a `For [0]:` line and a `For [1]:` line rather than `[1]` being read `[0]`'s advice. The helper returns a bare sentence and each caller adds its own lead-in: the function path adds ` -- ` at its one call site in `AOTCompiledFunction.__call__`, so its message is byte-identical to the parent's (`test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` keeps asserting `) -- a guarded global is missing`), and the report's `For [...]: ` prefix makes the line self-locating rather than a fragment between the entries and the footer. The three sentences (CAPTURED, SUPPLIED, RECONSTRUCTED) are otherwise unchanged; the two RECONSTRUCTED variants share their opening through a local instead of spelling it twice. The SUPPLIED wording stays `the live scope this artifact was loaded against, here vars(<module>)`; naming the instance's `forward` there, for a load whose guards hold the dict that attribute resolves to, is #197048's, above `[aot_compile] Keep a no-match report entry to one line that says what its guards answered` (#197134). Order to review: `_missing_global_hint` and its call site in `AOTCompiledFunction.__call__`; then the `hinted` dict and the `For [...]:` loop in `AOTCompiledModel._no_match_report`; the docstring sentence; the tests. Tests. `test_no_match_message_hints_only_the_entry_that_named_a_missing_global` (was `test_no_match_message_keeps_the_advice_for_every_entry`, renamed for what it pins now that the hint is no longer on every entry) asserts `For [1]: a guarded global is missing` where it asserted the bare sentence, and that the sentence appears once: `[0]` is a plain `L['mode'] == 0` mismatch and gets no hint. `test_no_match_message_hints_each_scope_a_mixed_model_failed_in` is new: it splices a CAPTURED result from `_aot_compile` next to a SUPPLIED one from `deserialize` through the public constructor, deletes the global both guard, and asserts the report's `For [` lines are exactly `For [0]: ` with the CAPTURED sentence and `For [1]: ` with the SUPPLIED one. `test_aot_compile_module_missing_global_hint_names_the_resolved_module`, whose two entries both fail on the deleted `GLOBAL_POOLING_CONFIG` in the one scope the load resolved, now asserts the sentence appears exactly once on a `For [0, 1]:` line, in both of its halves. The four `deserialize_refuses_*` / `fallback_scope_hint` tests pass on both sides of this commit, since the substrings they assert are in the line either way; `test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` pins the function path's ` -- `. Test Plan: ``` python test/dynamo/test_aot_compile.py -k no_match_message_hints python test/dynamo/test_aot_compile.py -k missing_global_hint python test/dynamo/test_aot_compile.py ``` The whole file runs 209 tests, `OK (skipped=6)`: the parent's 208 plus the new mixed-scope test. With the parent's `aot_compile.py` under this test file, three tests fail: the renamed test on `'For [1]: a guarded global is missing' not found in "... [1] KeyError on G['AOT_BRANCH_SCALE'] -- a guarded global is missing from the globals of the module ..."`, the mixed-scope test on `The length of the sequences mismatch: 0 != 2` (no `For [` line), and the resolved-module test on the count (`Expected 1 but got 2`). With a variant that keeps only the FIRST entry's hint (`For [0]:`), the mixed-scope test fails on `1 != 2` and the resolved-module test on `'For [0, 1]: a guarded global is missing' not found in "...\nFor [0]: a guarded global is missing from the live scope ..."`. With a variant that appends a `For [i]:` line per entry that named a missing global, only the count assertion catches it: `test_aot_compile_module_missing_global_hint_names_the_resolved_module` fails with `Scalars are not equal! Expected 1 but got 2.`. Dropping the ` -- ` the function path adds fails `test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` on `) -- a guarded global is missing`. Authored with the assistance of Claude Code. Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: 504341a Pull-Request: #197149
|
Claude finished @bobrenjc93's task in 58m 11s —— View job Reviewed — all three findings from the prior rounds are addressed (the placeholder now branches on the printed string, the docstring has a third clause, and the collapse's placement is justified in a comment); only three minor items remain, none blocking. Full review of PR #197134PR Review: #197134SummaryMakes each Code Quality
The entry line is now collapsed, but the hint line two lines below interpolates lines.append(f"For [{', '.join(map(str, at))}]: {hint}")
Testing
CLAUDE.md's Testing section says "For tests over multiple inputs, use the Notes from verification (no action needed)The previous round's blocking finding is genuinely fixed, and the new test that pins it holds up under the checks that would have invalidated it:
RecommendationApprove Every branch added to I could not execute the test file in this environment (no built |
[ghstack-poisoned]
…h matches Once module dispatch found no match, `AOTCompiledModel.__call__` fell through to `compiled_results[0]`, so the user saw whatever that one artifact's guard manager said -- with several compiled inputs, a failure report about the first one only, and no sign that the others existed or why they did not match. The dispatch commits below made the dispatch itself scan every result, re-check every result and serve an opted-out result before giving up, and kept that fall-through as the raise. This commit replaces it with a report that names every compiled input, built from the binding the dispatch already judged. This commit and the three above it -- `[aot_compile] Give the no-match report's missing-global hint one For [i, j]: line per distinct sentence` (#197149), `[aot_compile] Say when a no-match report entry's guards accepted the call the dispatch refused` (#197150) and `[aot_compile] Keep a no-match report entry to one line that says what its guards answered` (#197134) -- were one commit, split for review budget. This commit is the report: the raise, the header, one line per compiled input quoting the guards `check_verbose` named, the missing-global hint the fall-through already gave, and the closing advice. The siblings own where that hint sits, and what an entry's line holds when `check_verbose` names no guard: because the tree accepted the call, because a failing accessor named nothing, or because a part carries a line boundary. The raise carries one line per compiled input, and closes with what to do about it: add a `ModelInput`, or check whether `guard_filter_fn` KEPT a guard this call cannot satisfy. That last phrasing matters -- a guard the filter DROPPED cannot make a call fail to match, so the reverse advice sent the reader looking in the wrong place. Both levers are the capturing process's, and this report is reachable from a process that only loaded an artifact (nothing on `_load_aot_compiled_module` takes either), so the line says so rather than implying the reader holds them. When an entry's guards died on a global the process does not have, its line carries the function path's own `_missing_global_hint`, appended with ` -- ` exactly as the fall-through's `AOTCompiledFunction.__call__` appended it to `[0]`'s `GuardManager check failed` message -- the sentence worded for the scope that result's guards were resolved against (CAPTURED, SUPPLIED or RECONSTRUCTED), so the two paths say the same thing about the same scope. The hint is part of this commit rather than a follow-up because the parent already delivered it on the module path and five tests below (`test_aot_compile_module_missing_global_hint_names_the_resolved_module` and the four `deserialize_refuses_*` / `fallback_scope_hint` tests) assert its text through a module call; a report without it fails all five. Here it rides on every entry that named a missing global, as the parent's message carried it for `[0]`; giving the report one self-locating `For [i, j]:` line per distinct sentence, naming the entries that share it, and the helper a bare sentence each caller leads into, is #197149's, the next commit. The SUPPLIED wording is the parent's, unchanged: `the live scope this artifact was loaded against, here vars(<module>)`. Naming the instance's `forward` there, for a load whose guards hold the dict that attribute resolves to, is #197048's, above the siblings. The advice and that hint are independent, so a report every entry of which named a missing global carries both. Withholding the advice there would assume a new `ModelInput`'s guards must fail on the same absent name, which only holds when every path of `forward` reads that global: an entry fails on a global because ITS tree reads it, and an input captured for the branch this call takes need not read it at all -- such an input is captured and served with the name still undefined. Withholding also makes the only actionable line in the report turn on whether an unrelated global happens to be defined, and that masking is easy to hit, since guards are installed in `sorted(guards)` order and `GuardSource.LOCAL` sorts before `GLOBAL`, which sorts before `LOCAL_UNSPECIALIZED_NN_MODULE`: the root's `G` accessor fails before an `nn.Module` attribute guard runs, so the mismatch the reader needs to hear about is hidden behind the `KeyError`. The report cannot tell the two shapes apart and the advice is already hedged, so it is emitted next to the hint rather than in place of it. An entry's line quotes the guards `check_verbose` named, joined with `; `. `GuardDebugInfo.user_stack` and `num_guards_executed` are dropped on purpose: the verbose part usually embeds `# <source> # file:line in forward` already, the stack is `None` for the `KeyError on G[...]` case this report exists to explain, and one line per input is the point. Three of `check_verbose`'s answers leave that line saying nothing, or spread it over several lines, and each is a sibling's. A tree that ACCEPTS the call both dispatch passes rejected answers with no parts, so here its entry prints nothing after `[i]`; the call is refused all the same, and what the entry should say about it is #197150's. A genuine failure can also arrive with no parts, and a part can carry a boundary `splitlines()` breaks on; here such an entry prints nothing after `[i]`, or spans several lines, the call is refused either way, and those two lines are #197134's. A describer that raises is not caught here. `check_verbose` runs paths `check()` does not -- `DIMENSION_DYNAMIC_MARKING_GUARD` calls `py::repr` on user objects, and a `TENSOR_MATCH` failure on a tensor of the compiled type calls `is_parameter`, which runs `_ParameterMeta.__instancecheck__` -- so an entry's describer can raise where the dispatch's rejection was clean, and when it does the exception escapes the `raise RuntimeError(...)` argument and takes the report with it, exactly as it escaped the parent's fall-through, whose `AOTCompiledFunction.__call__` runs the same `check_verbose` unguarded. An earlier revision ran each entry's `check_verbose` under its own `try` and described the other entries anyway; measured without #197049's TorchFunction restore -- now the bottom of this stack -- that catch continued on a thread the throw had left broken and the lines it saved were wrong (FAQ below), so it is gone from here, and the place a raising tree is read as no answer and reported as one line is #196826, above, with the test that pins it. One call the fall-through served is refused by the report, and that is intended: a tree that rejected the call in both dispatch passes and accepts it on a third evaluation. PARENT: for `[0]` only, the fall-through's `AOTCompiledFunction.__call__` evaluated its guards a third time and served the graph when that evaluation accepted -- with a `CountedKey(misses=2)` in the slot of the one global `[0]`'s tree reads: `SERVED equal_to_x*3= True compares= 3`. HEAD: the report's `check_verbose` is that third evaluation, an accept there leaves the entry with nothing after its index, and the call raises: `RAISED compares= 3`. An accept that arrives only on the third evaluation is not a certified match -- a guard that does not answer consistently, or a tag-safe fast path that refused without running the tree -- and the parent extended that third chance to `[0]` alone, by its position; a result in any other slot never had it. The entry that says so, and `test_no_match_message_when_a_guard_answers_inconsistently`, which pins the raise and the three evaluations, are #197150's. A model with no compiled results is not a case this commit changes: `results[0]` at the top of `__call__` raises `IndexError: tuple index out of range` before any stage runs, on the parent and here alike. Otherwise the exception type stays `RuntimeError`, and the text `GuardManager check failed` is replaced on the module path only: the function path's `__call__` still raises it, and the five regexes this commit updates in test_aot_compile.py belong to the dispatch tests below. One of those tests, `test_module_dispatch_no_match_falls_through_to_the_first_result`, was named and commented for the fall-through its zero-opt-out row now proves gone, so it is renamed `test_module_dispatch_no_match_raises_unless_a_result_opted_out` and its comment says what the rows show: a call neither result guards raises and is handed to no result, and with `[0]` opted out its graph runs. Three sibling dispatch tests named the same fall-through for the stage before or after the one they pin -- `test_module_dispatch_rechecks_an_opted_out_result_whose_tree_accepts`, `test_module_dispatch_serves_an_opted_out_result_from_any_position` and `test_module_dispatch_rechecks_before_honouring_an_opt_out` -- and their comments now name the stages the dispatch has: the opt-out last resort, then this report. Their assertions are unchanged. A fourth, `test_module_dispatch_serves_a_call_the_guard_tree_accepts`, said the fall-through "re-checked compiled_results[0] and raised [0]'s L['mode'] == 0"; nothing is re-checked alone any more, so its comment now says what a call the re-check did not rescue meets: this report, with `[0]`'s guard one line of it. The report reuses the binding the dispatch judged, one per result, so it explains the same binding rather than a fresh one, and the one bind per call #197071 introduced holds end to end; the fall-through it replaces bound twice more inside `AOTCompiledFunction.__call__`. `test_module_dispatch_binds_a_call_once_for_results_sharing_a_signature` now also counts `prepare_f_locals` for a call nothing matches, and counts it apart from the matched call's: the list is asserted `[results[0]]` and cleared after the matched call, and asserted `[results[0]]` again after the no-match call, so each bind is attributed to the call that made it -- a combined `[results[0], results[0]]` would also accept a dispatch that bound the matched call nowhere and the no-match call twice. The fall-through fails the second assertion with `The length of the sequences mismatch: 3 != 1`, its no-match call binding three times. The same test counts the report's entry lines -- one per result off that single bind -- rather than its total line count, so a footer line added later does not break it. Measured once when this report was first written, against the dispatch before the one-bind-per-call commit and this commit, and not re-run since: a report costs 12.6us against the old 15.0us, and the no-match path costs 18.5us against 27.9us at one input and 29.9us against 33.0us at two, and crosses over by four, 50.9us against 41.3us, where the report's N `check_verbose` calls and the re-check's N `check()` calls outweigh the binds saved; with one bind per call rather than per result it costs 30.2us against 43.1us at four. That path ends in a raise, and the match path is the one every call takes. The report is handed the results the dispatch judged as well: `__call__` reads `compiled_results` once, and the report indexes `bound` against that tuple rather than re-reading a public list an append or a replacement can have changed under it -- re-read, an appended result asks for a binding the dispatch never made, and an `IndexError` raised inside the `raise RuntimeError(...)` argument takes the report's place. `test_no_match_report_names_the_results_the_dispatch_judged` makes `[0]`'s `check()` splice a second result into the list AHEAD of it mid-call, wraps both results' `check_verbose` under one `Mock` so their call order is recorded, and asserts the report counts one input and ran the first result's describer alone; the splice is `[:] = [later, first]`, so the re-check pass running the patched `check()` a second time leaves the list as it is. Counting alone would not pin which result an entry describes: a report that re-read the list and zipped it against `bound` would describe the spliced result against `[0]`'s binding under a `Tried 1` header, and the two results differ only in a closure scale, so their dtype-mismatch lines read alike. The second call, over the spliced list, reports `Tried 2` with entries `[0]` and `[1]` -- two, not one -- and the recorded order is `first, later, first`: the spliced result's tree is described first, as the list now orders it, so a report over `results[:1]` or `reversed(results)` fails here rather than only in a test elsewhere. The supplied-scope hint on an un-rebound load is pinned by #196825, a test-only commit higher in the stack, which also pins that the advice above still reaches a report whose only failure is a missing global. Folding that commit's test lines down here would put a guarded global the loading process does not have in the same commit as this report, which is the split this re-slice exists to make; they land together in any case. Four more of the report's tests sit in #197001, above #197048, since three of them pin that commit's forward naming: that the hint stays scope-neutral for a caller-supplied `guard_globals=`, that a CAPTURED result's report names no `forward` and never resolves it, that the advice reaches a report whose every entry named a missing global, and that a missing KEY inside a present global is not a missing global. > **FAQ: an earlier revision ran each entry's `check_verbose` under its own > `try`, so one raising describer did not cost the other entries their lines. > Why is that gone?** Because without #197049's restore the catch continues on > a thread the throw left broken, and the lines it saves are wrong; #197049 is > now the bottom of this stack, and the catch is #196826's with its test. > `RootGuardManager::check_verbose_nopybind` sets the TorchFunction TLS to > `ALL_DISABLED` for its accessors and restores it on each of its return paths, > not under RAII, so a `py::error_already_set` unwinding out of the tree skips > the restore; `_reset_relational_guard_state()` is skipped the same way, and > has no Python binding to call instead. Measured at that revision's tree with > `_ParameterMeta.__instancecheck__` patched to raise -- the Python > `is_parameter` reaches from `TENSOR_MATCH::check_verbose_nopybind`'s failure > branch, the route a tensor subclass `__getattr__` takes -- on a two-input > `ScaleModule` called with `x.double()`: the report arrived, `[0]` read `<guard > check could not be described: RuntimeError(...)>`, and `[1]` read > `GLOBAL_STATE changed: torch_function` instead of its dtype mismatch, since > `[1]`'s tree was evaluated on the thread `[0]`'s throw had left disabled; > after the report was caught, `torch._C._get_torch_function_state()` read > `ALL_DISABLED` against `ENABLED` before the call, and `t + 1` on a > `__torch_function__` subclass returned a plain `Tensor` without dispatching. > Without the `try`, the same script raises `RuntimeError('user __getattr__ > raised')` out of `__call__` on this tree and on the parent's alike, and leaves > the thread the same way -- an exposure `AOTCompiledFunction.__call__` has > always had, which #197049 repairs inside `GuardManagerWrapper.check_verbose` > for every caller. Fixing the C++ exit itself is outside this Python-only > stack. Above that restore the catch is sound, and it is one change with the > test that pinned it here, > `test_no_match_report_describes_the_other_entries_when_one_raises`; both are > #196826's, split out of this commit for review budget. > **FAQ: an entry whose `check_verbose` ACCEPTS the call, or fails without > naming a guard, prints nothing after `[i]` here, and a part carrying a line > boundary spans several lines. Why not branch on `reason.result` and an empty > `verbose_code_parts`, and collapse `splitlines()`, in this commit?** Because > those branches are #197150's (the entry for a tree that accepted on the third > evaluation) and #197134's (the entry for a failure that named no guard, and > the one-line collapse), split out of this commit for review budget so that > each lands next to the test that pins it and the report's plumbing here -- > the raise, the header, the per-entry join off the dispatch's own `bound` and > `results`, the hint and the advice -- stays reviewable on its own; the call > is refused all the same on every one of those answers, so nothing is served > in the meantime that a sibling later refuses. What the reader is told in the > meantime, measured at this tree against the parent's: with a > `CountedKey(misses=2)` on the global `[1]`'s tree reads and a `mode=1` call, > this tree raises `[0] L['mode'] == 0` over a blank `[1]` (`compares= 3`), > and the parent raised `[0]`'s `L['mode'] == 0` alone (`compares= 2`) -- it > never evaluated `[1]` a third time and said nothing of it, and with the probe > on a global `[0]`'s tree reads it served the graph (above); so no `result=1` > repr was ever printed for this answer. With #197134's fixture -- a > `SetIterModule` iterating a set, `SEQUENCE_LENGTH` dropped by the filter, > called with a shorter set -- this tree prints ` [0] ` blank, and the parent > printed `GuardDebugInfo(result=0, verbose_code_parts=[], num_guards_executed=6, > user_stack=None)`: no guard named either, but a `result=0` the blank entry > here does not carry. That one entry is what this commit says less about than > the fall-through did, for the three commits until #197134, which lands with > it. Neither blank entry loses a hint: the hint rides on a part that reads > `KeyError on G[...]`, matched whole by `_names_a_missing_global`, so an > answer with no parts named no missing global -- an accept has no failure to > hint, and the short-set failure is not about a global -- and the absent hint > is the accurate answer there, not a second loss. > **FAQ: a report whose entries all failed on the same missing global repeats > the hint on every one of them. Why not one hint per report here?** Because > where the hint sits is #197149's, the next commit, which gives the report one > `For [i, j]:` line per distinct sentence naming the entries that share it, > and pins the count at one in > `test_aot_compile_module_missing_global_hint_names_the_resolved_module` and > `test_no_match_message_hints_only_the_entry_that_named_a_missing_global`. > Here each entry carries its own hint, appended with ` -- ` as the > fall-through appended it to `[0]`'s message, so the five tests below that > assert the hint's text keep passing across the split. Measured at this tree, > the report `test_aot_compile_module_missing_global_hint_names_the_resolved_module` > produces on its first load is four lines, the two entries 203 characters each > and identical, with `a guarded global is missing` twice; that test asserts > the text with `assertIn`, as do the other tests built on > `_two_input_global_guard_artifact`, so none sees the count, and pinning the > repetition here only to remove it one commit up would assert something no > user is meant to rely on. The class docstring describes what this commit > does -- one line per result, carrying the hint when that result's guards > failed on a missing global -- and #197149 rewrites it for the `For` line. > **FAQ: `test_no_match_message_keeps_the_advice_for_every_entry` asserts the > hint with `assertIn` over the whole message. Why not assert it is a suffix > of the `[1]` line?** Because the hint's line is #197149's, the next commit, > which replaces that very assertion with `For [1]: a guarded global is > missing` and `message.count("a guarded global is missing") == 1` -- the > anchoring, at the placement the report keeps. Here the hint is appended to > `[1]`'s own line, and a suffix assertion would pin a placement the next > commit removes and be rewritten one commit up. What holds at both placements > is asserted here: the `[0]` line (`lines[1]`) does not carry the hint, and > neither does the advice, which is the last line. Measured at this tree, a > hint hoisted onto the advice, a hint appended to every entry with the > `_names_a_missing_global` gate dropped, and a hint attached to the previous > entry's line each fail those assertions, and #197149 cherry-picks clean on > top of them with its renamed test green. The two substrings the test also > asserts are not one check twice: `a guarded global is missing` opens all > three scopes' sentences, while `the module the compiled function was traced > in` is the CAPTURED wording alone -- SUPPLIED reads `the live scope this > artifact was loaded against` and RECONSTRUCTED `the scope rebuilt from the > artifact` -- so the second pins that an in-process capture's result is > hinted for the scope it resolved against. Test Plan: ``` python test/dynamo/test_aot_compile.py -k test_aot_compile_module_no_match_error python test/dynamo/test_aot_compile.py -k test_no_match_message_keeps_the_advice_for_every_entry python test/dynamo/test_aot_compile.py -k test_no_match_report_names_the_results_the_dispatch_judged python test/dynamo/test_aot_compile.py -k test_module_dispatch_binds_a_call_once_for_results_sharing_a_signature python test/dynamo/test_aot_compile.py -k test_module_dispatch_no_match_raises_unless_a_result_opted_out python test/dynamo/test_aot_compile.py ``` The whole file runs 210 tests, `OK (skipped=6)`; the parent's file defines three fewer. Every `-k` above fails with the parent's `aot_compile.py` under this test file (5/5): the three that assert on report text (`No AOT compiled graph matched this call`, `[0] L['mode'] == 0`, `Tried 1 compiled input(s)`) find the fall-through's `GuardManager check failed` message instead, the binding test sees three binds for the no-match call against the one it expects, `The length of the sequences mismatch: 3 != 1`, and the renamed test's zero-opt-out row finds `GuardManager check failed` where it expects `No AOT compiled graph matched` (its two opt-out rows pass on both, as they should: an opted-out `[0]` is served on the parent and here alike). `test_aot_compile_module_no_match_error` asserts that each of the two entries is one line of the report -- the two lines after the header, with unindented advice after them -- rather than that the whole report is four lines, and that each entry says something after its index: reporting an entry as `str(GuardDebugInfo)` instead of the joined one-line reason makes line 2 read `result=...` and fails it, printing ` [0] ` with nothing after the index fails it with `entry says nothing: ' [0] '`, while an advice line a later commit appends does not. Withholding the advice when an entry named a missing global fails `test_no_match_message_keeps_the_advice_for_every_entry` on `Add a ModelInput`. Reading `self.compiled_results` in the report again fails `test_no_match_report_names_the_results_the_dispatch_judged` with `IndexError: list index out of range` raised in place of the report; re-reading it zipped against `bound`, with the header off `results`, passes the header and entry counts and fails it on the describer order. Describing `results[:1]` fails it on the second call's entries, `'Add a ' != ' [1] '`, and `reversed(results)` on the order, `'first' != 'later'`. Hoisting the hint onto the advice, dropping the `_names_a_missing_global` gate, and attaching the hint to the previous entry's line each fail `test_no_match_message_keeps_the_advice_for_every_entry` with `'a guarded global is missing' unexpectedly found in` the advice or the `[0]` line. All were run at this tree. `test_no_match_message_keeps_the_advice_for_every_entry` captures through `_aot_compile_mode_branches`, whose `_hide_leaked_dynamo_globals` pops the minted globals a sibling's capture leaked and strips this test's own in cleanup (run alone in a fresh process, the inline capture it replaces left eight minted names in this module's dict -- two `__builtins_dict___*`, two `__compiled_fn_*` and four `__import_*` aliases; this form leaves none), and it registers the `AOT_BRANCH_SCALE` restore with `addCleanup` before deleting the name, so an interrupt anywhere leaves the module dict whole. Authored with the assistance of Claude Code. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: 31dd3ef Pull-Request: #196823
…[i, j]: line per distinct sentence This commit and `[aot_compile] Raise a report naming every input when no compiled graph matches` (#196823, the commit below) were one commit, split for review budget: that commit raises the report and carries the fall-through's missing-global hint on each entry that named one, and this commit owns where that hint sits in the report and how the helper that words it is shared with the function path. Below this commit, the entry line for a failure on a global the process does not have ends in ` -- a guarded global is missing ...`: the sentence `_missing_global_hint` returns with its lead-in built in, appended to the entry as the fall-through's `AOTCompiledFunction.__call__` appended it to `[0]`'s `GuardManager check failed` message. On the function path that sentence continues a line of its own, and the lead-in belongs there. In the report it turns a `KeyError on G['NAME']` entry into a paragraph, and a model whose every entry reads the same absent global -- the shape `deserialize` builds, handing every result one `guard_globals` -- repeats the same advice once per entry. The report now carries the hint after the entries and before the footer, one line per DISTINCT sentence, prefixed `For [i, j]: ` with every entry that sentence is for, in first-seen order; the class docstring says so. Every entry line still carries the name it failed on. Deduplicating on the text rather than taking the first entry keeps the two shapes apart: a model `deserialize` built hands every result one scope, so its entries share one sentence and the report carries exactly one `For [0, 1]:` line; the public constructor accepts results of differing scopes, and there each scope's advice is materially different (define the name in the module the function was traced in, in the live scope the artifact was loaded against, or load with a complete `f_globals=`), so a CAPTURED `[0]` next to a SUPPLIED `[1]` gets a `For [0]:` line and a `For [1]:` line rather than `[1]` being read `[0]`'s advice. The helper returns a bare sentence and each caller adds its own lead-in: the function path adds ` -- ` at its one call site in `AOTCompiledFunction.__call__`, so its message is byte-identical to the parent's (`test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` keeps asserting `) -- a guarded global is missing`), and the report's `For [...]: ` prefix makes the line self-locating rather than a fragment between the entries and the footer. The three sentences (CAPTURED, SUPPLIED, RECONSTRUCTED) are otherwise unchanged; the two RECONSTRUCTED variants share their opening through a local instead of spelling it twice. The SUPPLIED wording stays `the live scope this artifact was loaded against, here vars(<module>)`; naming the instance's `forward` there, for a load whose guards hold the dict that attribute resolves to, is #197048's, above `[aot_compile] Keep a no-match report entry to one line that says what its guards answered` (#197134). Order to review: `_missing_global_hint` and its call site in `AOTCompiledFunction.__call__`; then the `hinted` dict and the `For [...]:` loop in `AOTCompiledModel._no_match_report`; the docstring sentence; the tests. Tests. `test_no_match_message_hints_only_the_entry_that_named_a_missing_global` (was `test_no_match_message_keeps_the_advice_for_every_entry`, renamed for what it pins now that the hint is no longer on every entry) asserts `For [1]: a guarded global is missing` where it asserted the bare sentence, and that the sentence appears once: `[0]` is a plain `L['mode'] == 0` mismatch and gets no hint. `test_no_match_message_hints_each_scope_a_mixed_model_failed_in` is new: it splices a CAPTURED result from `_aot_compile` next to a SUPPLIED one from `deserialize` through the public constructor, deletes the global both guard, and asserts the report's `For [` lines are exactly `For [0]: ` with the CAPTURED sentence and `For [1]: ` with the SUPPLIED one. `test_aot_compile_module_missing_global_hint_names_the_resolved_module`, whose two entries both fail on the deleted `GLOBAL_POOLING_CONFIG` in the one scope the load resolved, now asserts the sentence appears exactly once on a `For [0, 1]:` line, in both of its halves. The four `deserialize_refuses_*` / `fallback_scope_hint` tests pass on both sides of this commit, since the substrings they assert are in the line either way; `test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` pins the function path's ` -- `. Test Plan: ``` python test/dynamo/test_aot_compile.py -k no_match_message_hints python test/dynamo/test_aot_compile.py -k missing_global_hint python test/dynamo/test_aot_compile.py ``` The whole file runs 209 tests, `OK (skipped=6)`: the parent's 208 plus the new mixed-scope test. With the parent's `aot_compile.py` under this test file, three tests fail: the renamed test on `'For [1]: a guarded global is missing' not found in "... [1] KeyError on G['AOT_BRANCH_SCALE'] -- a guarded global is missing from the globals of the module ..."`, the mixed-scope test on `The length of the sequences mismatch: 0 != 2` (no `For [` line), and the resolved-module test on the count (`Expected 1 but got 2`). With a variant that keeps only the FIRST entry's hint (`For [0]:`), the mixed-scope test fails on `1 != 2` and the resolved-module test on `'For [0, 1]: a guarded global is missing' not found in "...\nFor [0]: a guarded global is missing from the live scope ..."`. With a variant that appends a `For [i]:` line per entry that named a missing global, only the count assertion catches it: `test_aot_compile_module_missing_global_hint_names_the_resolved_module` fails with `Scalars are not equal! Expected 1 but got 2.`. Dropping the ` -- ` the function path adds fails `test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` on `) -- a guarded global is missing`. Authored with the assistance of Claude Code. Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: eb4b0a0 Pull-Request: #197149
… its guards answered This commit and `[aot_compile] Raise a report naming every input when no compiled graph matches` (#196823, three commits below) were one commit, split for review budget: that commit raises the report, and this one owns what an entry's line holds when its guards' verbose parts say nothing or carry a line boundary. The report prints one line per compiled input, `[i] ` followed by the guards `check_verbose` named for that input, joined with `; `. Two answers leave that line saying nothing, or saying it across several lines. A genuine failure can arrive with nothing to quote, two ways. A set-index accessor asked about a set shorter than the index it recorded answers false and appends no part (`GuardDebugInfo(false, 0)`, the one such site in guards.cpp). And a guard whose own evaluation raised answers false with `str(exc)` as its one part: `LAMBDA_GUARD::check_verbose_nopybind`, `CallFunctionNoArgsGuardAccessor` and `PythonLambdaGuardAccessor` each hand `get_exception_message()` to the three-argument `GuardDebugInfo` constructor, which appends that string raw -- it never passes through `get_verbose_code_part`'s `f"{code_part:<60}{extra}"` -- and `str(ValueError())` is `""`, so a message-less raise arrives as `[""]`, a non-empty list whose entry is as blank as the empty one. Below this commit both print ` [0] ` with nothing after the index. The call is refused either way -- the dispatch's `check()` decided that -- but the line does not say why, and reading a blank answer as "passed" anywhere would serve that call a graph compiled for another input, so `GuardDebugInfo.result` is what decides here, and the entry is decided on the string the line would print rather than on the list: when the parts, joined and collapsed as below, are blank once stripped, the entry reads `<guard check failed without naming a guard>`. Stripped, because `str(ValueError(" "))` and a separator-only message both collapse to a blank tail while staying truthy. `SetIterModule` reaches the first way: iterating a set guards each element through a set-index accessor, and `drop_sequence_length_guards` keeps the `SEQUENCE_LENGTH` guard that would otherwise name the wrong-sized set first out of the tree. `FlakyTwoTensor` reaches the second from user code: `TENSOR_SUBCLASS_METADATA_MATCH` installs a `LAMBDA_GUARD` around the subclass's `__metadata_guard__`, rooted at a local and not in `UNSUPPORTED_SERIALIZATION_GUARD_TYPES`, so the default `guard_filter_fn` keeps it, and a `__metadata_guard__` that raises `ValueError()` after the compile lands `[""]` in the report. The line is a format read back with `splitlines()` -- by a reader's eye and by the test below -- and a verbose part can carry a boundary that method breaks on. The part embeds the guard's own source line, read through `linecache`, whose `readlines()` ends a line at `\n` and at nothing else, so a `\x0c`, `\x1e` or `\u2028` sitting in a comment on that line arrives in the part intact, and one such comment prints a one-entry report as six lines, four of them fragments of a single guard. Collapsing with `.replace("\n", " ")` would handle `\n` and nothing else; joining `splitlines()` instead collapses exactly the set the format is read back on, whatever the source line happens to hold. The collapse stays in the report rather than moving into `get_verbose_code_part`, the parts' producer: the recompile logs consume the same parts and are outside this commit (see the FAQ), and the comment at the collapse says so. The class docstring's description of the report now lists the `<guard check failed without naming a guard>` line beside the guard-quoting line and the `<guards rejected this call twice and then accepted it here: ...>` explanation. Behaviour change vs the parent, in the report's entries only; nothing about which calls are served changes. An entry whose failure carries no verbose parts prints `<guard check failed without naming a guard>` instead of ` [i] ` (`test_no_match_message_when_a_failure_names_no_guard`); an entry whose parts collapse to a blank string, `[""]` or `[" "]`, prints the same placeholder (`test_no_match_message_when_a_failure_quotes_a_blank_message`); and an entry whose parts carry `\x0c`, `\x1e` or `\u2028` is one line (`test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators`). Order to review: `_no_match_report` in torch/_dynamo/aot_compile.py (the `splitlines()` join, then the blank branch it feeds), the class docstring's report paragraph, then `SetIterModule`, `drop_sequence_length_guards`, `FlakyTwoTensor` and the three tests in test/dynamo/test_aot_compile.py. Test Plan: ``` python test/dynamo/test_aot_compile.py -k test_no_match_message_when_a_failure_names_no_guard python test/dynamo/test_aot_compile.py -k test_no_match_message_when_a_failure_quotes_a_blank_message python test/dynamo/test_aot_compile.py -k test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators python test/dynamo/test_aot_compile.py ``` The whole file runs 213 tests, `OK (skipped=6)`; the parent runs 210. All three tests fail with the parent's `aot_compile.py` under this test file: `test_no_match_message_when_a_failure_names_no_guard` finds ` [0] ` with nothing after it where it expects `[0] <guard check failed without naming a guard>`; `test_no_match_message_when_a_failure_quotes_a_blank_message` fails both its subtests, `' [0] ' != ' [0] <guard check failed without naming a guard>'` for `""` and `' [0] '` for `" "`; and `test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators` counts `Expected 3 but got 6` lines. Mutations at this commit: deleting the blank branch fails the first two tests the same way (three failures); testing `if not joined:` in place of `if not joined.strip():` fails only the `" "` subtest; replacing the `splitlines()` join with `.replace("\n", " ")` is red with `Expected 3 but got 6`, and adding only the form feed to that replace is red with `Expected 3 but got 5`. An earlier form of this commit branched on `not reason.verbose_code_parts`, the list, and printed ` [0] ` for `[""]`; the blank-message test is red against that form on both subtests. `test_no_match_message_when_a_failure_quotes_a_blank_message` compiles `ScaleModule` on a `FlakyTwoTensor` -- a `TwoTensor` whose `__metadata_guard__` raises the exception stored on the class, none at compile time -- then stores `ValueError("")` and `ValueError(" ")` in turn and calls with the same tensor, so the metadata guard is the only guard that answers false. It asserts that the lines starting with ` [` are exactly the one placeholder line, so a bare ` [0] ` beside it would fail rather than hide behind an `assertIn`, and that the advice still follows. `test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators` imports a module whose guarded comment carries `\x0c`, `\x1e` and `\u2028`, and asserts the whole report is three lines with the entry among them, plus that all three separators reached the part and were collapsed -- without the second assertion the first passes on a report that never saw a separator. The generated module is written with `encoding="utf-8"`: the source carries `\u2028`, which the Windows shards' preferred encoding (cp1252) cannot encode, so a bare `open(..., "w")` fails there at `f.write` -- reproduced under `LC_ALL=C PYTHONUTF8=0`. Authored with the assistance of Claude Code. > **FAQ: Why does the collapse stay in the report rather than move into > `get_verbose_code_part`, where the separator originates?** Two other consumers > read the same parts: `get_and_maybe_log_recompilation_reasons` in guards.py > and the `fail_on_recompile` message in eval_frame.py indent them with > `textwrap.indent`, which splits on the same set, so a part carrying `\x0c` > becomes several `- ` lines there too. A producer-side collapse would change > what those logs print, and one consumer, `get_guard_fail_reason_helper`, > `eval`s a part as code -- safe only because the separators sit in the > trailing `# ...` comment, a property a producer-side change would have to > argue for every consumer. Both are outside this commit, which owns the module > report's entry and nothing the recompile path prints; the comment at the > collapse records that. > **FAQ: Why a tensor subclass for the blank-message case rather than a stubbed > `check_verbose` returning `[""]`?** A stub pins the branch; the subclass pins > that the branch is reachable from an `_aot_compile`d model, which is the claim > above: `TENSOR_SUBCLASS_METADATA_MATCH`'s lambda survives the default filter > and its raise reaches the report as `[""]`. `TwoTensor` is a test-internal > traceable wrapper subclass, and the test adds one class and no mocking. Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: 7f2d32c Pull-Request: #197134
…ard for and which share a line Tests only, for the no-match report the report commit (#196823) raises, split out of it so that its review fits in one pass -- the pattern of #196824 and #196825, which pin the dispatch's last resort and a guarded global the loading process does not have from test-only commits. Split again for review budget: the five-test revision of this commit died at the review bot's 60-minute ceiling, so the two tests that pin WHEN the report resolves `forward` -- only for a SUPPLIED scope, and once -- moved up into `[aot_compile] Pin when the no-match report resolves forward` (#<sibling>), and the three that pin WHICH entries the hint names it for, and which entries share a hint line, stay here. Each of the three passes at the parent, whose report it pins, and fails below the report commit (at #196896, the commit under it), where the no-match fall-through `results[0](self.model, *args, **kwargs)` raises the function path's `GuardManager check failed` message. That message quotes the guard's `KeyError on G[...]` part and, for a whole missing global, appends the function path's hint sentence, so the `loaded against; define it there` substring the tests also look for is present there; what it lacks is the `[i]` entry prefix, the `For [i]:` hint line and the `Tried N` header, and with no report there is no resolve. Measured with that tree's `aot_compile.py` under this tree's test file: `stays_neutral` fails on `"[0] KeyError on G['AOT_HERMETIC_WEIGHT']" not found`, `names_forward_only_for_the_dict_it_resolves_to` and `shares_a_hint_line_across_entries_worded_alike` on `Expected '_resolve_guard_scope' to be called once. Called 0 times`. The one that compiles in its own body calls `_hide_leaked_dynamo_globals()` on entry, as the capture-only `test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` does; the other two share `_two_input_global_guard_artifact` with `test_no_match_message_hints_each_scope_a_mixed_model_failed_in` and the landed `test_aot_compile_module_missing_global_hint_names_the_resolved_module` and, like them, do not, its kept guards being rooted at `GLOBAL_POOLING_CONFIG` alone. The report at this tree decides its hint per entry. An entry whose verbose parts name a whole missing global gets `_missing_global_hint(forward=...)`, with `forward` set when `resolved is not None and resolved is result._guard_globals`; `resolved` is what one `_resolve_guard_scope(self.model)` returned, run at most once, at the first hinted entry whose scope is SUPPLIED, and reused for every entry after it (when it runs, and that it runs once, is #<sibling>'s). The hints are keyed by text into `hinted`, one `For [i, j]:` line per distinct sentence, and the footer follows unconditionally. What each test catches, and which other tests in the file would catch the same edit, was measured by editing the report and running the whole file (222 tests): `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` loads through `AOTCompiledModel.deserialize(..., guard_globals=...)` with a dict that never had the guarded name, so the guards hold a dict no `forward` resolves to, asserts the scope-neutral wording under its `For [0]:` prefix, and then the advice it gives: `compiled_results[0]._guard_globals is scope`, and defining the name in that dict serves the call -- with `AOT_HERMETIC_WEIGHT` defined in this module's dict, where the class's `forward` lives, the whole time. Reducing the compare to `resolved is not None` fails it with a report that names `this HermeticModule instance's forward`, and fails exactly two others (`failures=3`): the landed #196818's `..._names_the_resolved_module`, whose second half loads with `guard_globals=dict(globals())` -- a copy of the module dict, taken while the module itself lacked the name, that is not the dict `forward` resolves to -- and asserts `loaded against; define it there`, and this commit's `names_forward_only_for_the_dict_it_resolves_to`, whose caller-supplied entry is then told which forward as well. #197048's `test_no_match_report_survives_a_forward_resolve_that_raises` reaches the neutral wording through `resolved is None`, its `test_no_match_message_hint_covers_a_rebound_forward` through a resolve that IS the dict the guards hold, and this commit's `shares_a_hint_line` through a resolve that returns no dict, so all three pass under that edit. What this test adds over `..._names_the_resolved_module` is the other way to the wording, a supplied dict that never had the name rather than a stale copy carrying the module's `__name__`, and the recovery: no other `AOTCompiledModel.deserialize(..., guard_globals=)` test defines a missing name in the supplied dict and asserts the call is served (`..._deserialize_takes_a_guard_globals_scope` supplies a copy that already carries its names, and `covers_a_rebound_forward` defines the name in the dict the load RESOLVED, not one the caller passed). `test_no_match_message_names_forward_only_for_the_dict_it_resolves_to` is the shape that tells a per-entry `forward` from one shared across the report. Two SUPPLIED results whose guards hold different dicts -- one from `deserialize(GlobalConfigModule(), data)`, which resolves the scope from `model.forward` and so holds this module's dict, the one `_resolve_guard_scope` returns; one from `deserialize(..., guard_globals=scope)` with a dict that never had the name -- go into one `AOTCompiledModel` by hand, as `hints_each_scope_a_mixed_model_failed_in` builds its CAPTURED + SUPPLIED pair, and are dispatched with `GLOBAL_POOLING_CONFIG` deleted, in both orders. Each order enters a fresh `patch(..., wraps=_resolve_guard_scope)`, so its count is that order's alone, and asserts `assert_called_once_with(mixed.model)` -- one resolve, asked about the model the report is for -- two `For [i]:` lines, and that the entry holding the resolved dict is the one told `this GlobalConfigModule instance's forward` while the other gets the live-scope wording. Deciding `forward` once, at the first hinted entry, and applying it to every entry fails it on the second entry's wording (`'the live scope this artifact was loaded against; define it there' not found in "For [1]: ... this GlobalConfigModule instance's forward resolves to ..."`) and nothing else in the file (`failures=1`): `..._names_the_resolved_module`'s two entries share one dict in each half, `hints_each_scope`'s SUPPLIED entry is its only one, and `shares_a_hint_line`'s three entries all hold dicts no forward resolves to. The line count does not catch that edit, because the resolved dict carries a `__name__` and the supplied one does not, so the two hints stay two sentences either way; the wording does. The `_with(mixed.model)` is what pins which module is resolved: asking `_resolve_guard_scope(type(self.model)())` instead resolves a fresh instance to the same dict here, so the wording cannot tell, and fails this test on `expected call not found` (`failures=4`: the other three are #197048's `covers_a_rebound_forward` and `survives_a_forward_resolve_that_raises` on wording, since a fresh instance does not carry the `forward` those rebind, and this commit's `shares_a_hint_line`, which also checks which model was asked). `test_no_match_message_shares_a_hint_line_across_entries_worded_alike` is the report's first three-entry test (`Tried 3` appears nowhere else in the file) and pins four things at once. Three SUPPLIED results from three `deserialize(GlobalConfigModule(), data, guard_globals=...)` loads, each holding a caller dict of its own (`len({id(r._guard_globals) for r in results}) == 3`): `[0]` and `[2]` lack `GLOBAL_POOLING_CONFIG`, `[1]` has it bound to `{}`, so its guard fails on the KEY, `KeyError on G['GLOBAL_POOLING_CONFIG']['pooling']`; the three entry lines are asserted exactly. First, the hint lines are keyed by sentence, not by dict: `[0]` and `[2]` carry no `__name__`, so their neutral sentences are identical and they share one non-contiguous `For [0, 2]:` line. Keying `hinted` by `(id(result._guard_globals), hint)` instead fails it on the line count (`Expected 1 but got 2`) and nothing else (`failures=1`): `..._names_the_resolved_module`'s `For [0, 1]` entries share one dict object. The merge is the intended reading: a per-dict line would print the same sentence twice, and the sentence names no dict, so the reader could not tell the two lines apart; two entries that give one instruction get one line. Second, `[1]` is the nested-key mismatch the whole-part match keeps off the hint: replacing the report's `_names_a_missing_global` with a `"KeyError on G[" in part` substring test fails it on `For [0, 1, 2]:` and nothing else (`failures=1`), the fence the dropped `test_missing_key_inside_a_present_global_is_not_a_missing_global` carried (see the FAQ); the predicate itself is pinned on the function path by `test_aot_compile_fn_missing_nested_key_gets_no_missing_global_hint`. Third, the model is `_unresolvable_forward_module()`, whose forward is a partial `get_traced_fn` refuses, so the report's one resolve -- `assert_called_once_with(mixed.model)` -- returns `(None, reason)` without raising and no entry is told which forward; the fixture's three other uses pass no `guard_globals=`, so their results are RECONSTRUCTED and never reach the resolve. Fourth, the footer follows a report whose hinted list is non-contiguous. Two tests of the previous revision are gone. `test_no_match_message_advises_an_input_for_a_missing_global` and its `SelfModeBranchGlobalModule` fixture pinned the footer under a report whose every entry was hinted; the footer is unconditional, and returning before it when `sum(map(len, hinted.values())) == len(results)` fails two tests at this tree without it (`failures=2`, both on `'Add a ModelInput' not found`): #196825's `test_aot_compile_module_absent_global_fails_guard` and #197048's `survives_a_forward_resolve_that_raises` (and, one commit up, #<sibling>'s `resolves_forward_only_for_a_supplied_scope`). Its other assertions -- that the `L['self'].mode` mismatch is absent from the first report and named by the second -- pinned the guard tree's install order and fail-count re-sort in guards.cpp, not the report. `test_missing_key_inside_a_present_global_is_not_a_missing_global` is folded into `shares_a_hint_line`'s entry `[1]`, which fences the same substring edit. Test Plan: ``` python test/dynamo/test_aot_compile.py -k test_no_match_message_hint_stays_neutral_for_a_supplied_scope python test/dynamo/test_aot_compile.py -k test_no_match_message_names_forward_only_for_the_dict_it_resolves_to python test/dynamo/test_aot_compile.py -k test_no_match_message_shares_a_hint_line_across_entries_worded_alike python test/dynamo/test_aot_compile.py ``` The whole file runs 222 tests here, 219 on the parent commit: `Ran 222 tests`, `OK (skipped=6)`. ## FAQ > **FAQ: The review found that > `test_aot_compile_module_missing_global_hint_names_the_resolved_module`, in > the landed #196818, already fails under the edit that this commit's > `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` was once > described as the one test to catch. Why keep the test?** > > Because the coverage claim was wrong, and the test's other half is not pinned > anywhere else. Re-measured on the whole file with the compare reduced to > `resolved is not None`: `Ran 222 tests`, `FAILED (failures=3)`, the three > being `..._names_the_resolved_module` (`'loaded against; define it there' not > found`), this test, and this commit's > `names_forward_only_for_the_dict_it_resolves_to`; every other test passes. So > the identity compare is fenced at #196818 as well, and the message says so > instead of crediting this test alone. What this test alone covers is a > `guard_globals=` dict that never had the name -- > `..._names_the_resolved_module` reaches the same wording through > `dict(globals())`, a copy taken while the module itself lacked the name -- > and the recovery, defining the name in that dict and asserting the call is > served, which no other `AOTCompiledModel.deserialize(..., guard_globals=)` > test does. > **FAQ: The review found two of an earlier revision's five tests largely > redundant with the base, and two report branches -- where `tried_forward` is > set, and hint dedup keyed by text -- unpinned. What changed?** > > Both redundancies were measured and both tests are gone; both branches are > now pinned, one here and one in #<sibling>. Gating the footer on every entry > being hinted, the edit > `test_no_match_message_advises_an_input_for_a_missing_global` fenced, fails > two tests at this tree without it -- #196825's `absent_global_fails_guard` > and #197048's `survives_a_forward_resolve_that_raises` -- so that test and > its fixture add no fence on the report, and its `L['self'].mode` assertions > pin guards.cpp's accessor order, not this function. Replacing the report's > whole-part predicate with a substring test, the edit > `test_missing_key_inside_a_present_global_is_not_a_missing_global` fenced > alone, is now fenced alone by > `shares_a_hint_line_across_entries_worded_alike`, whose entry `[1]` is the > same nested-key mismatch next to two whole-global ones, so the fold loses no > coverage and the module path still has its own pin of the predicate. Keying > `hinted` by dict identity fails only `shares_a_hint_line` (`Expected 1 but > got 2` hint lines); the `tried_forward` mark is pinned by #<sibling>'s > `resolves_forward_once_past_a_resolve_that_raises`. > **FAQ: The report's comment on `hinted` says entries that share a scope > share a sentence, but the dict is keyed by hint text, so two entries holding > different dicts with identical wording collapse into one `For [0, 2]:` line. > Is that intended, and why pin it rather than change it?** > > It is intended, and this commit changes no code. The hint sentence is the > whole of what the reader gets: it names a scope only when the dict carries a > `__name__` (`here vars(mod)`), and two caller-supplied dicts without one > yield the identical sentence, so a per-dict line would print that sentence > twice with nothing to tell the two lines apart. Two entries whose advice > reads the same get one line; two entries whose advice differs -- a resolved > module dict next to a supplied one, a CAPTURED entry next to a SUPPLIED one > -- keep their own, which `names_forward_only_for_the_dict_it_resolves_to` > and `hints_each_scope_a_mixed_model_failed_in` pin. The comment's "share a > scope" is the common case of sharing a sentence, and belongs to #197149. > **FAQ: Every new test passes at the parent commit. Where is the red-on-parent > evidence?** > > There is none by construction: this is a tests-only commit pinning the > report the parent already ships, so every test passes on the parent's tree. > The two measurements that stand in for it are above: each test fails under > the tree below the report commit (#196896), where no report exists, and each > fails under a targeted edit of `_no_match_report` that no other test in the > file catches -- the mutation table is what shows the pins are not vacuous. > **FAQ: The review listed `"; ".join(parts)` with more than one verbose code > part per entry as uncovered. Why is there no test for it here?** > > Because that join is #197134's (`Keep a no-match report entry to one line > that says what its guards answered`), whose > `test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators` owns > the entry format; how many parts an entry quotes has no bearing on the hint, > which is what this commit pins. A multi-part entry test belongs next to that > one, in that PR. Authored with the assistance of Claude Code. Co-Authored-By: Claude Fable 5.1 <[email protected]> ghstack-source-id: a9fe180 Pull-Request: #197001
[ghstack-poisoned]
Reviewing PR #197134
|
|
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. |
…[i, j]: line per distinct sentence (#197149) This commit and `[aot_compile] Raise a report naming every input when no compiled graph matches` (#196823, the commit below) were one commit, split for review budget: that commit raises the report and carries the fall-through's missing-global hint on each entry that named one, and this commit owns where that hint sits in the report and how the helper that words it is shared with the function path. Below this commit, the entry line for a failure on a global the process does not have ends in ` -- a guarded global is missing ...`: the sentence `_missing_global_hint` returns with its lead-in built in, appended to the entry as the fall-through's `AOTCompiledFunction.__call__` appended it to `[0]`'s `GuardManager check failed` message. On the function path that sentence continues a line of its own, and the lead-in belongs there. In the report it turns a `KeyError on G['NAME']` entry into a paragraph, and a model whose every entry reads the same absent global -- the shape `deserialize` builds, handing every result one `guard_globals` -- repeats the same advice once per entry. The report now carries the hint after the entries and before the footer, one line per DISTINCT sentence, prefixed `For [i, j]: ` with every entry that sentence is for, in first-seen order; the class docstring says so. Every entry line still carries the name it failed on. Deduplicating on the text rather than taking the first entry keeps the two shapes apart: a model `deserialize` built hands every result one scope, so its entries share one sentence and the report carries exactly one `For [0, 1]:` line; the public constructor accepts results of differing scopes, and there each scope's advice is materially different (define the name in the module the function was traced in, in the live scope the artifact was loaded against, or load with a complete `f_globals=`), so a CAPTURED `[0]` next to a SUPPLIED `[1]` gets a `For [0]:` line and a `For [1]:` line rather than `[1]` being read `[0]`'s advice. The helper returns a bare sentence and each caller adds its own lead-in: the function path adds ` -- ` at its one call site in `AOTCompiledFunction.__call__`, so its message is byte-identical to the parent's (`test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` keeps asserting `) -- a guarded global is missing`), and the report's `For [...]: ` prefix makes the line self-locating rather than a fragment between the entries and the footer. The three sentences (CAPTURED, SUPPLIED, RECONSTRUCTED) are otherwise unchanged; the two RECONSTRUCTED variants share their opening through a local instead of spelling it twice. The SUPPLIED wording stays `the live scope this artifact was loaded against, here vars(<module>)`; naming the instance's `forward` there, for a load whose guards hold the dict that attribute resolves to, is #197048's, above `[aot_compile] Keep a no-match report entry to one line that says what its guards answered` (#197134). Order to review: `_missing_global_hint` and its call site in `AOTCompiledFunction.__call__`; then the `hinted` dict and the `For [...]:` loop in `AOTCompiledModel._no_match_report`; the docstring sentence; the tests. Tests. `test_no_match_message_hints_only_the_entry_that_named_a_missing_global` (was `test_no_match_message_keeps_the_advice_for_every_entry`, renamed for what it pins now that the hint is no longer on every entry) asserts `For [1]: a guarded global is missing` where it asserted the bare sentence, and that the sentence appears once: `[0]` is a plain `L['mode'] == 0` mismatch and gets no hint. `test_no_match_message_hints_each_scope_a_mixed_model_failed_in` is new: it splices a CAPTURED result from `_aot_compile` next to a SUPPLIED one from `deserialize` through the public constructor, deletes the global both guard, and asserts the report's `For [` lines are exactly `For [0]: ` with the CAPTURED sentence and `For [1]: ` with the SUPPLIED one. `test_aot_compile_module_missing_global_hint_names_the_resolved_module`, whose two entries both fail on the deleted `GLOBAL_POOLING_CONFIG` in the one scope the load resolved, now asserts the sentence appears exactly once on a `For [0, 1]:` line, in both of its halves. The four `deserialize_refuses_*` / `fallback_scope_hint` tests pass on both sides of this commit, since the substrings they assert are in the line either way; `test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` pins the function path's ` -- `. Test Plan: ``` python test/dynamo/test_aot_compile.py -k no_match_message_hints python test/dynamo/test_aot_compile.py -k missing_global_hint python test/dynamo/test_aot_compile.py ``` The whole file runs 209 tests, `OK (skipped=6)`: the parent's 208 plus the new mixed-scope test. With the parent's `aot_compile.py` under this test file, three tests fail: the renamed test on `'For [1]: a guarded global is missing' not found in "... [1] KeyError on G['AOT_BRANCH_SCALE'] -- a guarded global is missing from the globals of the module ..."`, the mixed-scope test on `The length of the sequences mismatch: 0 != 2` (no `For [` line), and the resolved-module test on the count (`Expected 1 but got 2`). With a variant that keeps only the FIRST entry's hint (`For [0]:`), the mixed-scope test fails on `1 != 2` and the resolved-module test on `'For [0, 1]: a guarded global is missing' not found in "...\nFor [0]: a guarded global is missing from the live scope ..."`. With a variant that appends a `For [i]:` line per entry that named a missing global, only the count assertion catches it: `test_aot_compile_module_missing_global_hint_names_the_resolved_module` fails with `Scalars are not equal! Expected 1 but got 2.`. Dropping the ` -- ` the function path adds fails `test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` on `) -- a guarded global is missing`. Authored with the assistance of Claude Code. Co-Authored-By: Claude Fable 5.1 <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: #197149 Approved by: https://github.com/pytorchgreenlight ghstack dependencies: #197049, #196823
…ard for and which share a line (#197001) **Problem.** The no-match report decides, entry by entry, whether its missing-global hint names "this `Module` instance's forward" or stays neutral ("the live scope this artifact was loaded against"), by comparing the dict `forward` resolves to against the dict each entry's guards hold. Nothing pinned that a caller-supplied `guard_globals=` dict stays neutral, or that in a report with two entries holding different dicts only the entry holding the resolved one is told which forward. **Fix.** Two tests pin exactly that: one where no entry holds the resolved dict (and defining the name in the supplied dict then serves the call), and one where exactly one of two does, checked in both orders with a single resolve asserted. No source change. **Summary.** Tests only, for the no-match report the report commit (#196823) raises, split out of it so that its review fits in one pass -- the pattern of #196824 and #196825, which pin the dispatch's last resort and a guarded global the loading process does not have from test-only commits. Split twice more for review budget: the five-test revision of this commit died at the review bot's 60-minute ceiling, so the two tests that pin WHEN the report resolves `forward` -- only for a SUPPLIED scope, and once -- moved up into `[aot_compile] Pin when the no-match report resolves forward` (#197301), and the three-entry test that pins which entries share a hint line moved up into `[aot_compile] Pin that the no-match report shares one hint line across entries worded alike`. What stays here is the pair that pins WHICH entry the hint names a `forward` for: one where no entry is, and one where exactly one of two is. Both pass at the parent, whose report they pin, fail below the report commit (#196896) where no report exists, and each fails under a targeted edit of `_no_match_report` that no other test in the file catches, measured by editing the report and running the whole file. Two tests of the previous revision are gone, one because the footer gate it fenced is already fenced by two other tests and one because it is folded into the three-entry test's entry `[1]` in the commit above. ## What the report does at this tree The report decides its hint per entry. An entry whose verbose parts name a whole missing global gets `_missing_global_hint(forward=...)`, with `forward` set when `resolved is not None and resolved is result._guard_globals`; `resolved` is what one `_resolve_guard_scope(self.model)` returned, run at most once, at the first hinted entry whose scope is SUPPLIED, and reused for every entry after it (when it runs, and that it runs once, is #197301's). ``` # the two wordings the tests tell apart For [i]: a guarded global is missing from the live scope this artifact was loaded against; define it there ... # neutral For [i]: ... this GlobalConfigModule instance's forward resolves to ... # named ``` ## Both fail below the report commit Both tests pass at the parent, whose report they pin, and fail below the report commit (at #196896, the commit under it), where the no-match fall-through `results[0](self.model, *args, **kwargs)` raises the function path's `GuardManager check failed` message. That message quotes the guard's `KeyError on G[...]` part and, for a whole missing global, appends the function path's hint sentence, so the `loaded against; define it there` substring the tests also look for is present there; what it lacks is the `[i]` entry prefix, the `For [i]:` hint line and the `Tried N` header, and with no report there is no resolve. Measured with that tree's `aot_compile.py` under this tree's test file: | test | failure below the report commit | | --- | --- | | `..._hint_stays_neutral_for_a_supplied_scope` | `"[0] KeyError on G['AOT_HERMETIC_WEIGHT']" not found` | | `..._names_forward_only_for_the_dict_it_resolves_to` | `Expected '_resolve_guard_scope' to be called once. Called 0 times` | The one that compiles in its own body calls `_hide_leaked_dynamo_globals()` on entry, as the capture-only `test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` does; the other shares `_two_input_global_guard_artifact` with `test_no_match_message_hints_each_scope_a_mixed_model_failed_in` and the landed `test_aot_compile_module_missing_global_hint_names_the_resolved_module` and, like them, does not, its kept guards being rooted at `GLOBAL_POOLING_CONFIG` alone. ## `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` ```python scope: dict[str, object] = {"__builtins__": builtins} # never had AOT_HERMETIC_WEIGHT compiled = AOTCompiledModel.deserialize(HermeticModule(), data, guard_globals=scope) with self.assertRaises(RuntimeError) as ctx: compiled(x) message = str(ctx.exception) self.assertIn("[0] KeyError on G['AOT_HERMETIC_WEIGHT']", message) self.assertIn("For [0]: a guarded global is missing from the live scope this artifact was loaded against; define it there", message) self.assertNotIn("instance's forward", message) # the advice, followed: the guards hold the supplied dict, and defining the name there serves the call self.assertIs(compiled.compiled_results[0]._guard_globals, scope) scope["AOT_HERMETIC_WEIGHT"] = AOT_HERMETIC_WEIGHT self.assertEqual(compiled(x), x @ AOT_HERMETIC_WEIGHT) ``` It loads through `AOTCompiledModel.deserialize(..., guard_globals=...)` with a dict that never had the guarded name, so the guards hold a dict no `forward` resolves to, asserts the scope-neutral wording under its `For [0]:` prefix, and then the advice it gives: `compiled_results[0]._guard_globals is scope`, and defining the name in that dict serves the call -- with `AOT_HERMETIC_WEIGHT` defined in this module's dict, where the class's `forward` lives, the whole time. Reducing the compare to `resolved is not None` fails it with a report that names `this HermeticModule instance's forward`, and fails exactly two others: the landed #196818's `..._names_the_resolved_module`, whose second half loads with `guard_globals=dict(globals())` -- a copy of the module dict, taken while the module itself lacked the name, that is not the dict `forward` resolves to -- and asserts `loaded against; define it there`, and this commit's `names_forward_only_for_the_dict_it_resolves_to`, whose caller-supplied entry is then told which forward as well. #197048's `test_no_match_report_survives_a_forward_resolve_that_raises` reaches the neutral wording through `resolved is None`, and its `test_no_match_message_hint_covers_a_rebound_forward` through a resolve that IS the dict the guards hold, so both pass under that edit. What this test adds over `..._names_the_resolved_module` is the other way to the wording, a supplied dict that never had the name rather than a stale copy carrying the module's `__name__`, and the recovery: no other `AOTCompiledModel.deserialize(..., guard_globals=)` test defines a missing name in the supplied dict and asserts the call is served (`..._deserialize_takes_a_guard_globals_scope` supplies a copy that already carries its names, and `covers_a_rebound_forward` defines the name in the dict the load RESOLVED, not one the caller passed). ## `test_no_match_message_names_forward_only_for_the_dict_it_resolves_to` ```python by_forward = AOTCompiledModel.deserialize(GlobalConfigModule(), data) # resolves scope from model.forward: this module's dict by_caller = AOTCompiledModel.deserialize(GlobalConfigModule(), data, guard_globals=scope) # a dict that never had the name self.assertIs(by_forward.compiled_results[0]._guard_globals, globals()) self.assertIs(by_caller.compiled_results[0]._guard_globals, scope) del GLOBAL_POOLING_CONFIG pair = by_forward.compiled_results[:1] + by_caller.compiled_results[:1] cases = ((pair, [named, neutral]), (pair[::-1], [neutral, named])) # both orders for results, wording in cases: mixed = AOTCompiledModel(GlobalConfigModule(), results) with patch(target, wraps=_resolve_guard_scope) as resolves, self.assertRaises(RuntimeError) as ctx: mixed(x) resolves.assert_called_once_with(mixed.model) # one resolve, asked about the model the report is for hints = [line for line in message.splitlines() if line.startswith("For [")] self.assertEqual([line[:9] for line in hints], ["For [0]: ", "For [1]: "], message) for hint, want in zip(hints, wording): self.assertIn(want, hint) ``` This is the shape that tells a per-entry `forward` from one shared across the report. Two SUPPLIED results whose guards hold different dicts -- one from `deserialize(GlobalConfigModule(), data)`, which resolves the scope from `model.forward` and so holds this module's dict, the one `_resolve_guard_scope` returns; one from `deserialize(..., guard_globals=scope)` with a dict that never had the name -- go into one `AOTCompiledModel` by hand, as `hints_each_scope_a_mixed_model_failed_in` builds its CAPTURED + SUPPLIED pair, and are dispatched with `GLOBAL_POOLING_CONFIG` deleted, in both orders. Each order enters a fresh `patch(..., wraps=_resolve_guard_scope)`, so its count is that order's alone, and asserts `assert_called_once_with(mixed.model)` -- one resolve, asked about the model the report is for -- two `For [i]:` lines, and that the entry holding the resolved dict is the one told `this GlobalConfigModule instance's forward` while the other gets the live-scope wording. | edit to `_no_match_report` | fails | | --- | --- | | decide `forward` once, at the first hinted entry, and apply it to every entry | this test alone, on the second entry's wording (`'the live scope this artifact was loaded against; define it there' not found in "For [1]: ... this GlobalConfigModule instance's forward resolves to ..."`) | | resolve `_resolve_guard_scope(type(self.model)())` instead of `self.model` | this test on `expected call not found`, plus #197048's `covers_a_rebound_forward` and `survives_a_forward_resolve_that_raises` on wording | Nothing else in the file catches the first edit: `..._names_the_resolved_module`'s two entries share one dict in each half, and `hints_each_scope`'s SUPPLIED entry is its only one. The line count does not catch that edit, because the resolved dict carries a `__name__` and the supplied one does not, so the two hints stay two sentences either way; the wording does. The `_with(mixed.model)` is what pins which module is resolved: asking about a fresh instance resolves to the same dict here, so the wording cannot tell, and a fresh instance does not carry the `forward` the two #197048 tests rebind. ## Two tests of the previous revision are gone `test_no_match_message_advises_an_input_for_a_missing_global` and its `SelfModeBranchGlobalModule` fixture pinned the footer under a report whose every entry was hinted; the footer is unconditional, and returning before it when `sum(map(len, hinted.values())) == len(results)` fails two tests at this tree without it (both on `'Add a ModelInput' not found`): #196825's `test_aot_compile_module_absent_global_fails_guard` and #197048's `survives_a_forward_resolve_that_raises` (and, one commit up, #197301's `resolves_forward_only_for_a_supplied_scope`). Its other assertions -- that the `L['self'].mode` mismatch is absent from the first report and named by the second -- pinned the guard tree's install order and fail-count re-sort in guards.cpp, not the report. `test_missing_key_inside_a_present_global_is_not_a_missing_global` is folded into the three-entry test's entry `[1]`, which fences the same substring edit, and rides with it in the commit above. Test Plan: ``` python test/dynamo/test_aot_compile.py -k test_no_match_message_hint_stays_neutral_for_a_supplied_scope python test/dynamo/test_aot_compile.py -k test_no_match_message_names_forward_only_for_the_dict_it_resolves_to python test/dynamo/test_aot_compile.py ``` The whole file is green here and on the parent commit. ## FAQ > **FAQ: The review found that > `test_aot_compile_module_missing_global_hint_names_the_resolved_module`, in > the landed #196818, already fails under the edit that this commit's > `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` was once > described as the one test to catch. Why keep the test?** > > Because the coverage claim was wrong, and the test's other half is not pinned > anywhere else. Re-measured on the whole file with the compare reduced to > `resolved is not None`: the failures are `..._names_the_resolved_module` > (`'loaded against; define it there' not found`), this test, and this commit's > `names_forward_only_for_the_dict_it_resolves_to`; every other test passes. So > the identity compare is fenced at #196818 as well, and the message says so > instead of crediting this test alone. What this test alone covers is a > `guard_globals=` dict that never had the name -- > `..._names_the_resolved_module` reaches the same wording through > `dict(globals())`, a copy taken while the module itself lacked the name -- > and the recovery, defining the name in that dict and asserting the call is > served, which no other `AOTCompiledModel.deserialize(..., guard_globals=)` > test does. > **FAQ: The review found two of an earlier revision's five tests largely > redundant with the base, and two report branches -- where `tried_forward` is > set, and hint dedup keyed by text -- unpinned. What changed?** > > Both redundancies were measured and both tests are gone; both branches are > now pinned, one in the commit above and one in #197301. Gating the footer on > every entry being hinted, the edit > `test_no_match_message_advises_an_input_for_a_missing_global` fenced, fails > two tests at this tree without it -- #196825's `absent_global_fails_guard` > and #197048's `survives_a_forward_resolve_that_raises` -- so that test and > its fixture add no fence on the report, and its `L['self'].mode` assertions > pin guards.cpp's accessor order, not this function. Replacing the report's > whole-part predicate with a substring test, the edit > `test_missing_key_inside_a_present_global_is_not_a_missing_global` fenced > alone, and keying `hinted` by dict identity are both fenced by the > three-entry `shares_a_hint_line_across_entries_worded_alike` in the commit > above, so the fold loses no coverage and the module path still has its own > pin of the predicate. The `tried_forward` mark is pinned by #197301's > `resolves_forward_once_past_a_resolve_that_raises`. > **FAQ: Every new test passes at the parent commit. Where is the red-on-parent > evidence?** > > There is none by construction: this is a tests-only commit pinning the > report the parent already ships, so every test passes on the parent's tree. > The two measurements that stand in for it are above: each test fails under > the tree below the report commit (#196896), where no report exists, and each > fails under a targeted edit of `_no_match_report` that no other test in the > file catches -- the mutation table is what shows the pins are not vacuous. > **FAQ: The review listed `"; ".join(parts)` with more than one verbose code > part per entry as uncovered. Why is there no test for it here?** > > Because that join is #197134's (`Keep a no-match report entry to one line > that says what its guards answered`), whose > `test_no_match_report_keeps_an_entry_on_one_line_past_odd_separators` owns > the entry format; how many parts an entry quotes has no bearing on the hint, > which is what this commit pins. A multi-part entry test belongs next to that > one, in that PR. Authored with the assistance of Claude Code. Co-Authored-By: Claude Fable 5.1 <[email protected]> Pull Request resolved: #197001 Approved by: https://github.com/pytorchgreenlight ghstack dependencies: #197049, #196823, #197149, #197048, #196825, #196897, #197218, #196909, #196826, #197390, #197391, #197188, #197179, #197195, #197220

Stack from ghstack (oldest at bottom):
This commit and
[aot_compile] Raise a report naming every input when no compiled graph matches(#196823, the commit below) were one commit, splitfor review budget: that commit raises the report, and this one owns what an
entry's line holds when its guards' verbose parts are empty or carry a line
boundary.
The report prints one line per compiled input,
[i]followed by the guardscheck_verbosenamed for that input, joined with;. Two answers leave thatline saying nothing, or saying it across several lines.
A genuine failure can arrive with no parts: a set-index accessor asked about a
set shorter than the index it recorded answers false and appends nothing, so
below this commit the entry reads
[0]with nothing after the index. Thecall is refused either way -- the dispatch's
check()decided that -- but theline does not say why, and reading an empty part list as "passed" anywhere
would serve that call a graph compiled for a set of another size, so
GuardDebugInfo.resultis what decides here and such an entry now reads<guard check failed without naming a guard>.SetIterModulereaches it:iterating a set guards each element through a set-index accessor, and
drop_sequence_length_guardskeeps theSEQUENCE_LENGTHguard that wouldotherwise name the wrong-sized set first out of the tree.
The line is a format read back with
splitlines()-- by a reader's eye and bythe test below -- and a verbose part can carry a boundary that method breaks
on. The part embeds the guard's own source line, read through
linecache,whose
readlines()ends a line at\nand at nothing else, so a\x0c,\x1eor\u2028sitting in a comment on that line arrives in the partintact, and one such comment prints a one-entry report as six lines, four of
them fragments of a single guard. Collapsing with
.replace("\n", " ")wouldhandle
\nand nothing else; joiningsplitlines()instead collapses exactlythe set the format is read back on, whatever the source line happens to hold.
Order to review:
_no_match_reportin torch/_dynamo/aot_compile.py (theno-parts branch, then the
splitlines()join), thenSetIterModuleanddrop_sequence_length_guardsand the two tests intest/dynamo/test_aot_compile.py.
Test Plan:
The whole file runs 192 tests,
OK (skipped=6); the parent runs two fewer.Both tests fail with the parent's
aot_compile.pyunder this test file:test_no_match_message_when_a_failure_names_no_guardfinds[0]withnothing after it where it expects
[0] <guard check failed without naming a guard>, andtest_no_match_report_keeps_an_entry_on_one_line_past_odd_separatorscounts
Expected 3 but got 6lines. Disabling the no-parts branch at thiscommit prints the same blank entry; replacing the
splitlines()join with.replace("\n", " ")is red withExpected 3 but got 6, and adding only theform feed to that replace is red with
Expected 3 but got 5.test_no_match_report_keeps_an_entry_on_one_line_past_odd_separatorsimports amodule whose guarded comment carries
\x0c,\x1eand\u2028, and assertsthe whole report is three lines with the entry among them, plus that all three
separators reached the part and were collapsed -- without the second assertion
the first passes on a report that never saw a separator. The generated module
is written with
encoding="utf-8": the source carries\u2028, which theWindows shards' preferred encoding (cp1252) cannot encode, so a bare
open(..., "w")fails there atf.write-- reproduced underLC_ALL=C PYTHONUTF8=0.Authored with the assistance of Claude Code.
Co-Authored-By: Claude Fable 5.1 [email protected]
🤖 Generated with Claude Code