Skip to content

[aot_compile] Pin where an opted-out result sits in module dispatch - #196824

Closed
bobrenjc93 wants to merge 34 commits into
gh/bobrenjc93/1173/basefrom
gh/bobrenjc93/1173/head
Closed

bobrenjc93 wants to merge 34 commits into
gh/bobrenjc93/1173/basefrom
gh/bobrenjc93/1173/head

Conversation

@bobrenjc93

@bobrenjc93 bobrenjc93 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Tests only, for the last-resort stage of the dispatch the previous commit
rewrote. disable_guard_check() is the escape hatch for an artifact whose
guards fail on the serving machine, and where an opted-out result sits in the
three-stage ordering decides answers that are wrong-answer bugs with no error
raised if the stages slip. Every case below is built so that the wrong stage
order returns a different NUMBER and nothing else.

The fixture: same shapes, same dtypes, different numbers

GLOBAL_POOLING_CONFIG = {"pooling": "sum"}

class GlobalConfigModule(torch.nn.Module):
    def forward(self, x):
        if GLOBAL_POOLING_CONFIG["pooling"] == "sum":
            return x.sum(1)
        return x.mean(1) * 10.0

model._aot_compile([
    ModelInput(args=(x,), kwargs={}, contexts=[_set_pooling("sum")]),    # compiled_results[0]
    ModelInput(args=(x,), kwargs={}, contexts=[_set_pooling("mean")]),   # compiled_results[1]
])

Both graphs accept a (4, 8) float tensor and differ only in what they return,
so a dispatch that picks the wrong one raises nothing and only assertEqual
against eager notices. Whether the global is GUARDED depends on the filter:
keep_global_guards keeps it, so each result matches only under its own mode;
the default filter drops it, so both results accept every call.

Opting out changes what a result accepts, not where it sits

test_aot_compile_module_opted_out_result_keeps_its_place_in_the_scan uses the
default filter, so both trees pass, opts out [0], and calls under the mode
[1] was traced for:

with _set_pooling("mean"):
    assert results[0].guard_check(mod, x) and results[1].guard_check(mod, x)
    results[0].disable_guard_check()
    model(x) == expected["sum"]      # [0] served: the first accepting result in INDEX order

A dispatch that consults the checked results first, or holds the opted-out ones
back for the passes below, serves [1] instead, the graph the process global
would pick, so nothing but the number says which result answered. Only a mix of
one opted-out and one checked result can see that: with none or all opted out,
putting the checked results first reorders nothing, and holding the opted-out
ones back is what the dispatch commit's
test_module_dispatch_rechecks_an_opted_out_result_whose_tree_accepts already
fails on. Every other flag vector's case coincides with one of those two tests,
so this is the one case in the file that a mixed vector pins.

The scan outranks the opt-out, and the last resort serves the first opt-out

test_aot_compile_module_opted_out_result_is_the_last_resort uses
keep_global_guards, so each result matches only its own mode:

results[0].disable_guard_check()             # [0] = sum, opted out
with _set_pooling("mean"):
    model(x) == expected["mean"]             # [1]'s guards genuinely pass, so the scan serves [1]

results[1].disable_guard_check()             # both opted out
with _set_pooling("other"):                  # neither tree passes
    model(x) == expected["sum"]              # the last resort serves the FIRST opted-out result

The first arm is the wrong-answer bug if the opt-out is consulted before the
real guard checks: [0] would serve the first artifact for a call the second
was compiled for, same shapes, same dtypes, different numbers. The second arm
pins that the last resort is itself ordered: a call no artifact guards gets the
graph the earliest opted-out ModelInput was traced for. Both cases coincide
with the compiled_results[0] fall-through the parent replaced, since the
result they opt out first IS compiled_results[0], so the test pins the
ordering against future reordering rather than regressing the rewrite.

A scan that skipped opted-out results is not one of them, for two different
reasons: in the first arm the result that must serve is the CHECKED one, which
the skip never applies to, so it is served by the scan itself and the second
pass is never reached; in the second both trees fail the call anyway and the
answer this ordering demands is the first opted-out result, which the last
resort serves either way. What tells a skipping scan apart is an opted-out
result whose tree the scan would accept: the keeps-its-place test above pins
that with honest guards, and the dispatch commit's re-check test covers the
false-rejection variant.

What the escape hatch costs

test_aot_compile_module_disable_guard_check drives the opt-out through
requires_grad, which is part of TENSOR_MATCH, so the artifact recorded for
requires_grad=False genuinely cannot match the call:

model = torch.compile(ScaleModule(), fullgraph=True, backend="aot_eager")
model._aot_compile([ModelInput(args=(torch.randn(3, 3),), kwargs={}, contexts=[])])

x = torch.randn(3, 3, requires_grad=True)
model(x)                                            # RuntimeError: ... requires_grad mismatch
model.forward.compiled_results[0].disable_guard_check()
out = model(x)                                      # served anyway: that is the escape hatch
out == x.detach() * 2 and not out.requires_grad     # and it is an INFERENCE graph: no grad history

It asserts what the opt-out COSTS rather than what it buys: with the guard that
would have rejected a requires_grad=True call disabled, dispatch serves an
inference graph that aot_autograd's runtime wrapper runs with grad disabled, so
the caller silently gets a result with no grad history. The expected value is
detached for that reason, since assertEqual does not compare requires_grad
and the tensor the call was made with does carry it. That is why this one test
compiles with aot_eager instead of the eager the ordering tests use: an
eager backend installs no such wrapper and would still record the grad history.
It does not discriminate against the pre-rewrite fall-through, since the result
it opts out is again compiled_results[0] and AOTCompiledFunction.__call__
short-circuits on the very same flag and serves the very same graph, so what it
is separated for is that its failure mode is loud: lose the opt-out stage and
the call reports "No AOT compiled graph matched" instead of answering wrongly,
which also keeps either direction of drift visible, a change that starts
handing back a differentiable result and a change that starts refusing the call
the opt-out was asked to allow.

What is deliberately not duplicated here

Every case above opts out compiled_results[0] first, so a last resort that
read that one result instead of walking to the first that opted out satisfies
all of them. That walk, [1] opted out with [0] still checked and a call
neither artifact guards, served by [1] where reading compiled_results[0]
would refuse it with a no-match report, is pinned by the parent's
test_module_dispatch_serves_an_opted_out_result_from_any_position, in the
commit that introduces the loop. A copy of it here under keep_global_guards
was the same experiment on the dispatch axis (no edit to the three stages
separates the two), and the axis it did add, a rejection from a global guard,
is already what test_aot_compile_module_dispatches_on_global_guard and
test_module_dispatch_evaluates_a_matching_tree_once fail on when the pooling
guard is dropped, so it was removed rather than kept with a uniqueness claim it
could not make.

Test Plan:

python test/dynamo/test_aot_compile.py -k test_aot_compile_module_disable_guard_check
python test/dynamo/test_aot_compile.py -k test_aot_compile_module_opted_out_result_keeps_its_place_in_the_scan
python test/dynamo/test_aot_compile.py -k test_aot_compile_module_opted_out_result_is_the_last_resort

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Opus 5 [email protected]

FAQ

FAQ: The review asked for the missing last-resort case to be folded into
test_aot_compile_module_opted_out_result_is_the_last_resort by reordering its
assertions so the first opt-out is [1]. Why is it a separate test?

Because the existing test's value is that all of its ordering assertions run
against one capture in one order, and the case that was missing does not belong
to that sequence: it is the only one that discriminates against reading
compiled_results[0] instead of walking to the first result that opted out, and
it needs [0] to still be checked while [1] is not -- the opposite of the
state the ordering cases share. Reordering to make room for it costs the first
ordering assertion its discrimination: with [1] opted out first, the call that
assertion makes is one the opted-out result itself guards, so an opt-out
consulted during the scan answers it correctly and the assertion passes anyway;
rewriting it around a call [0] guards restores the check. The separate test
states its own premise, keeps the ordering test's sequence intact, and fails
loudly (a no-match report where a graph should have been served) rather than
answering wrongly.

FAQ: nothing pins the continue that made the second check() pass skip
opted-out results -- shouldn't there be a test?
There is now, and it is a fix
rather than a pin. This round's audit built the case the earlier answer here said
could not exist: both results opted out, the scan false-rejecting the one whose
guards match (a CountedKey with one scripted miss), and dispatch served the
FIRST opted-out result's graph for a call only the second matched -- wrong
numerics, nothing raised -- because the re-check skipped every opted-out result
and the last resort is ordered by index, not by guard. The skip is gone from
#196823, whose re-check now evaluates every result the scan rejected, and that
commit carries the test (asserting the served value and compares == 2, red with
the skip restored). The four ordering tests here are unchanged by the fix,
measured over the whole file.

FAQ: The globals-probe swap in
test_aot_compile_module_opted_out_result_waits_for_the_full_recheck uses
try/finally where the file's three other CountedKey swaps use addCleanup;
the cleanup order is already correct, so match the sibling and drop the
try/finally -- a mechanical translation. Why keep it?
Moot: that test is
gone. A later pass showed every edit that reddened it also reddened one of its
two siblings (test_module_dispatch_serves_a_call_the_guard_tree_accepts,
neither result opted out, and
test_module_dispatch_rechecks_an_opted_out_result_whose_tree_accepts, both),
because all three walked the same dispatch path with a flag vector the correct
code ignores; its replacement,
test_aot_compile_module_opted_out_result_keeps_its_place_in_the_scan, pins the
one case a mixed vector can see -- an opted-out result whose guards genuinely
pass is served in index order, not after the checked results -- under the default
guard filter, and swaps no probe at all. The try/finally-versus-addCleanup
question therefore has no site left in this commit; the siblings that keep a
CountedKey are #196823's, and they use the form their own comments justify.

FAQ: test_aot_compile_module_last_resort_iterates_past_a_checked_result
was the same experiment as the parent's
test_module_dispatch_serves_an_opted_out_result_from_any_position -- two
results, [0] checked, [1] opted out, a call neither guards, [1] served.
Fold or drop one?

Dropped, after one round of trying to keep it. On the dispatch axis the two
were the same test: no edit to the three stages reddens one and not the other.
The first attempt kept this copy with a comment claiming a guard-filter axis
of its own, and that comment was wrong twice over -- _guard_source_globals
cannot drop a guard at all (it only picks live global values for a rebuilt
bytecode's globals, behind a gate this in-process test never reaches), and a
filter regression that dropped the pooling guard already reddens
test_aot_compile_module_dispatches_on_global_guard and
test_module_dispatch_evaluates_a_matching_tree_once. The walk past a
still-checked result stays pinned where the loop is introduced, in the parent
commit.

FAQ: The comment on
test_aot_compile_module_opted_out_result_is_the_last_resort said a scan that
skipped opted-out results is not pinned because "the second pass re-checks
them and recovers the graph"; neither assertion of that test ever reaches the
second pass.

Right, and the comment now names the two actual reasons. With only [0] opted
out, the result that must serve is the CHECKED [1], which a skipping scan
never skips, so [1] passes on its first evaluation and is served by the scan
itself -- stage two is never entered. With both opted out under mode
"other", both trees genuinely fail the second pass too, and the answer the
ordering rule demands is the first opted-out result, which the last resort
serves either way. So the mutation is invisible to this test not because
anything is recovered but because the skip never touches the result that
decides. What does tell a skipping scan apart is an opted-out result whose
tree the scan would accept:
test_aot_compile_module_opted_out_result_keeps_its_place_in_the_scan, in
this same commit, pins that with honest guards (both results accept under the
default filter, [0] opts out, a skipping scan serves [1]'s graph instead),
and test_module_dispatch_rechecks_an_opted_out_result_whose_tree_accepts in
the dispatch commit covers the false-rejection variant; the comment now says
so instead of claiming only a false rejection can see it.

🤖 Generated with Claude Code

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 2 Unrelated Failures

As of commit d3968e1 with merge base 4c54342 (image):

GREEN LIGHT - PR approved to be merged without human review:

  • Scope
    • Test-only: the whole diff is 115 added lines in test/dynamo/test_aot_compile.py, three new methods and no production file touched
    • No existing test is edited or deleted; the hunk is inserted between test_module_dispatch_no_match_falls_through_to_the_first_result and test_aot_compile_module_scope_resolves_through_forward_hook
  • Correctness of the pinned behavior
    • The assertions match AOTCompiledModel.__call__ in torch/_dynamo/aot_compile.py:1483-1508: index-ordered scan, a second check() pass, then results[0](...) as last resort
    • disable_guard_check (aot_compile.py:1041) only sets _guard_check_enabled on the instance, and AOTCompiledFunction.__call__ (:885) short-circuits on it, so serving an unguarded call and the "requires_grad mismatch" text from torch/csrc/dynamo/guards.cpp:301 are both real
    • Helpers used all pre-exist in the file: ScaleModule (:492), GlobalConfigModule (:548), _set_pooling (:562), keep_global_guards (:678)
  • Test hygiene
    • No name collisions: each of the three method names appears exactly once in the tree
    • Global mutation is scoped -- _set_pooling restores in a finally (:565-568), the two tests that capture call _hide_leaked_dynamo_globals (:1865), and the opted-out results are locals
  • CI signal
    • The one new failure Dr. CI reports is functorch/test_ac on macos-py3-arm64, a path this diff does not touch

reason: clean
Reviewed commit: d3968e1

Inference job

NEW FAILURE - The following job has failed:

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

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

This was referenced Sep 11, 2026
@bobrenjc93 bobrenjc93 changed the title [aot_compile] Pin where an opted-out result sits in module dispatch [no-ci] [aot_compile] Pin where an opted-out result sits in module dispatch Sep 15, 2026
@bobrenjc93 bobrenjc93 changed the title [no-ci] [aot_compile] Pin where an opted-out result sits in module dispatch [aot_compile] Pin where an opted-out result sits in module dispatch Sep 15, 2026
[ghstack-poisoned]
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 changed the title [aot_compile] Pin where an opted-out result sits in module dispatch [no-ci] [aot_compile] Pin where an opted-out result sits in module dispatch Sep 15, 2026
[ghstack-poisoned]
@bobrenjc93 bobrenjc93 changed the title [no-ci] [aot_compile] Pin where an opted-out result sits in module dispatch [aot_compile] Pin where an opted-out result sits in module dispatch Sep 15, 2026
[ghstack-poisoned]
@bobrenjc93
bobrenjc93 marked this pull request as ready for review September 15, 2026 15:10
@bobrenjc93

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: trunk / macos-py3-arm64 / test (default, 2, 3, macos-m1-stable), inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 1, 2, mt-l-x86iamx-8-64, unstable), inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 2, 2, mt-l-x86iamx-8-64, unstable)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request Sep 15, 2026
…alike (#197071)

Binding dominates the per-call cost of `AOTCompiledModel.__call__`.
`prepare_f_locals` (`inspect.Signature.bind` plus `apply_defaults`) costs
2.4us on this machine against 1.3us for a `check()` that passes, and the parent
binds every result it scans:

```python
# parent: one bind per result scanned
for result in results:
    f_locals = result.prepare_f_locals(self.model, *args, **kwargs)   # 2.4us, every time
    bound.append(f_locals)
    if result._live_guard_manager().check(f_locals):                   # 1.3us
        return result.fn(self.model, *args, **kwargs)
# a match at the fourth of four inputs pays four binds for one graph
```

Every result `aot_compile_module` produces binds alike: same parameter names,
kinds and default objects, same `co_freevars` and the same closure cells, since
`orig_forward` is read before any `ModelInput` context is entered. So one bind
serves them all. This commit lets a call that reaches a second result reuse the
first result's binding for it and every later one, across the scan and the
re-check, when the results bind alike:

```python
shared: bool | None = None
for result in results:
    if bound and shared is None:                    # decided only once a SECOND result is reached
        shared = self._binds_alike(results)
    f_locals = bound[0] if shared else result.prepare_f_locals(self.model, *args, **kwargs)
    bound.append(f_locals)                          # one entry per result either way, so the re-check zips as before
    if result._live_guard_manager().check(f_locals):
        return result.fn(self.model, *args, **kwargs)
```

Measured in one process on a `ScaleModule` compiled for two and for four
dtypes, the parent's `__call__` and this one exec'd from source into two
subclasses over the same results and timed in alternation, best of 9, min of
two rounds:

| call | parent | this commit |
|---|---|---|
| match at `[1]` of two | 21.0us | 20.5us |
| match at `[3]` of four | 30.3us | 22.7us |
| no match, two results (raises) | 25.3us | 23.2us |
| no match, four results (raises) | 36.2us | 27.5us |
| match at `[0]`, one / two / four results | 15.9 / 16.9 / 16.0us | 15.8 / 16.2 / 16.9us |

A match at `[0]`, which is every call to a single-result model, never reaches
the verdict and costs what it did (machine at load average 6). Behaviour is the
parent's for every call: the same result is served or the same error raised,
and a call still judges the results it began with. What changes is the number
of binds, and that editing `compiled_results` between calls, which the parent's
snapshot already tolerated, is now stated in the class docstring rather than
implied.

Review order: `_binding_key`, then the `_binding_verdict` field and
`_binds_alike`, then the `shared` lines of `__call__`, then the docstring,
then the tests.

## Deciding "binds alike" without `inspect.Signature` equality

```python
def _binding_key(artifacts):
    env, params = artifacts.runtime_env, artifacts.signature.parameters.values()
    return (tuple([(p.name, p.kind, id(p.default)) for p in params]),
            env.bytecode.co_freevars,
            tuple([id(cell) for cell in env.closure or ()]))
```

`_binding_key` compares exactly what `prepare_f_locals` reads, with defaults
and cells by identity, as a tuple of tuples so that a key is what its name
says. It deliberately does not compare `inspect.Signature`s: `Parameter.__eq__`
takes `bool()` of `default == default` as a non-final `and` operand, so a
`forward` with a tensor default made the first call raise for any model with
two or more results, however it was built (`_aot_compile`, `deserialize` or the
public constructor):

```python
class M(torch.nn.Module):
    def forward(self, x, mask=torch.ones(3)):
        return x * mask
# comparing Signatures -> RuntimeError: Boolean value of Tensor with more than one value is ambiguous
```

`test_module_dispatch_shares_a_binding_past_a_tensor_default` pins that, and
the closure half is pinned by
`test_module_dispatch_shares_a_binding_across_closure_cells`, whose
hand-assembled model holds two cells of the same name. A model whose results do
not agree (`deserialize` unpickles each blob on its own and the constructor is
public) binds each result on its own, which
`test_module_dispatch_binds_per_result_when_signatures_differ` pins.
`test_module_dispatch_binds_a_call_once_for_results_sharing_a_signature` counts
`prepare_f_locals` on a four-input model for a call matched at `[3]` and
expects one.

A loaded model whose `forward` has a real default or a closure cell binds per
result for the same reason: each blob unpickles through its own
`AOTCompileUnpickler`, so equal defaults and cells come back as distinct
objects and the identity key reads them as different. That is a false negative
and never a false share, and it is accepted rather than closed with a memo
shared across the per-result pickles, which would turn the artifact from a list
of independent blobs into one stream and thread a shared pickler through
`AOTCompiledFunction.serialize` and `deserialize`; a `forward` with neither,
whose defaults are the `Parameter.empty` singleton, still shares one bind after
a load. Both shared-binding tests round-trip and pin the loaded verdict as
False.

## Decided at the second result, not ahead of the scan

The first result is bound and checked exactly as the parent does, so a call it
serves pays nothing for the sharing and a single-result model never consults
the verdict at all.
`test_module_dispatch_decides_a_shared_binding_past_the_first_result` pins that
on a two-result model: a call `[0]` serves never calls `_binds_alike` and
leaves the verdict at its default, the verdict over no results, and the next
call, which `[0]` refuses, calls it once. Every binding, shared or not, is
appended once per result in the scan, so the re-check zips `results` with
`bound` as the parent does.

## Re-decided whenever the public list changes

`compiled_results` is a public list; the docs teach callers to index into it
and tests assemble models from it by hand. So the verdict is decided again
whenever the list differs by length or identity from the contents it was
reached over:

```python
def _binds_alike(self, results):
    prior, shared = self._binding_verdict
    if len(results) == len(prior) and all(w() is r for w, r in zip(prior, results)):
        return shared                                    # cached: 0.37us at two results, 0.47us at four
    key = _binding_key(results[0]._artifacts) if results else None
    shared = key is not None and all(_binding_key(r._artifacts) == key for r in results[1:])
    self._binding_verdict = (tuple(weakref.ref(r) for r in results), shared)   # ONE store
    return shared
```

A stale True would bind a later result from `compiled_results[0]`'s signature,
and if a `guard_filter_fn` dropped the guard on the parameter the two disagree
about, serve a graph for a call its guards never saw:

```python
model.forward.compiled_results[1] = replaced    # forward(x, mode=0), but compiled for mode=1
model(x)   # stale True: [1] bound from [0]'s default -> serves x * 3, where eager answers x * 2
           # re-decided: [1] bound on its own signature -> raises
```

`test_module_dispatch_rebinds_after_a_result_is_appended` and
`test_module_dispatch_judges_a_replaced_result_on_its_own_binding` pin the
re-decision, the second through that silent shape. The contents are remembered
as weak references, so a result the caller drops from the list is not kept
alive by the model until a later call decides again;
`test_module_dispatch_does_not_keep_a_dropped_result_alive` pops one, collects,
and finds its weakref dead. Deciding costs a `_binding_key` per result, about
1.0us each, and the cached identity check 0.37us for two results and 0.47us
for four, 0.02us and 0.04us of which is dereferencing the weak references.

## One field, published with one store

The verdict and the contents it was reached over are one field,
`_binding_verdict`, so a call reads both with one attribute load and the
re-decision publishes both with one attribute store, and the field's comment
states the premise rather than the conclusion: a single attribute store
publishes the pair indivisibly (an instance-dict store is atomic under the GIL
and locked on free-threaded builds), so a reader sees the old pair or the new
one and never one list's contents beside another's verdict. Two fields cannot
be made consistent by store order:

```python
# contents first, verdict second:
#   T1 stores new contents ... T2 identity-matches them, returns the PREVIOUS verdict (stale True),
#   binds the appended result from [0]'s default
# verdict first, contents second:
#   T1 pops [1], decides True over the shorter list, stores it ... T2, which snapshotted both results
#   before the pop, matches the contents still published, takes that True, binds [1] from [0]'s
#   default and serves x * 3 for a call eager answers x * 2
```

Both interleavings are forced deterministically.
`test_module_dispatch_never_pairs_new_contents_with_a_stale_verdict` holds the
deciding thread inside its first `_binding_key` on a `threading.Event` and
calls the model from another thread in that window.
`test_module_dispatch_never_pairs_old_contents_with_a_new_verdict` holds it
right after its first attribute store (an `AOTCompiledModel` subclass whose
`__setattr__` parks the decider) while a call that snapshotted both results
before the pop decides. A window between the two halves of the publication is
the one thing no test can pin, which is why there is none: whatever the single
store publishes is all a reader can ever see, and that is what the second test
asserts. Both tests register their cleanups once the decider has started,
release before join, so a failed assertion neither joins an unstarted thread
nor leaves a parked one behind, and wait at most 10s for the decider to park,
so a decider that never reaches its parking point fails the test in seconds.
The tests read `_binds_alike(tuple(model.compiled_results))` rather than the
field.

`_binds_alike` takes the tuple `__call__` snapshotted rather than reading the
list itself, so the shared bind and the verdict are about the same contents the
two passes iterate; the snapshot's own test is in the dispatch commit two below
(#197055), where the per-result binds already need it.

> **FAQ: Why not decide the verdict once at construction and call editing
> `compiled_results` afterwards unsupported, dropping the re-decision, the weak
> references and both threading tests?** Because nothing stops the edit and a
> stale True fails silently. Measured by making `_binds_alike` return the stored
> verdict whenever one exists (deciding once), against the 15 tests:
> `test_module_dispatch_judges_a_replaced_result_on_its_own_binding` fails with
> `RuntimeError not raised` -- `[1]`, compiled for `mode=1` and defaulting
> `mode` to 0, is bound from `[0]`'s `mode=1` default and serves `x * 3` for a
> call eager answers `x * 2` -- `test_module_dispatch_rebinds_after_a_result_is_appended`
> errors with `GuardManager check failed`, and both interleaving tests time out
> waiting for a decider that never re-decides. The dispatch commit below
> (#197055) already snapshots the list because it is editable, so stating the
> edit as supported is the position the code was taking; the class docstring
> now says so. What deciding once would save is the cached identity check,
> 0.37us at two results and 0.47us at four, and only on calls that reach a
> second result; `_aot_compile` and `deserialize` construct once either way.

> **FAQ: Why weak references rather than `id()`s for the remembered
> contents?** Ids are reused once an object dies, so a list of ids could match
> a new result that happens to occupy a dead one's address and hand it the old
> verdict. A weak reference dereferences to the object or to None, so the
> identity check is exact, and it costs 0.02us more than comparing the objects
> directly for two results and 0.04us for four while keeping nothing alive.

> **FAQ: Why cache the verdict at all instead of deciding on every call?**
> Deciding costs a `_binding_key` per result, about 1.0us each: 4us at four
> results, most of the 7us the three binds it saves there cost. The cached
> identity check costs 0.37us at two results and 0.47us at four whatever it
> decides, and a call `[0]` serves never pays it.

Test Plan:

```
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_decides_a_shared_binding_past_the_first_result
python test/dynamo/test_aot_compile.py -k test_module_dispatch_binds_per_result_when_signatures_differ
python test/dynamo/test_aot_compile.py -k test_module_dispatch_rebinds_after_a_result_is_appended
python test/dynamo/test_aot_compile.py -k test_module_dispatch_judges_a_replaced_result_on_its_own_binding
python test/dynamo/test_aot_compile.py -k test_module_dispatch_does_not_keep_a_dropped_result_alive
python test/dynamo/test_aot_compile.py -k test_module_dispatch_never_pairs_new_contents_with_a_stale_verdict
python test/dynamo/test_aot_compile.py -k test_module_dispatch_never_pairs_old_contents_with_a_new_verdict
python test/dynamo/test_aot_compile.py -k test_module_dispatch_shares_a_binding_past_a_tensor_default
python test/dynamo/test_aot_compile.py -k test_module_dispatch_shares_a_binding_across_closure_cells
python test/dynamo/test_aot_compile.py
```

This commit adds 10 `test_module_dispatch_*` tests; the full file runs 182
tests and passes (6 skipped). All 10 fail at the parent, i.e. with the parent's
`torch/_dynamo/aot_compile.py` under this commit's test file, on the missing
`_binds_alike` (`AttributeError`); the retention test reaches it through the
precondition that the verdict was decided over both results, since a parent
without the cache has nothing to retain. The parent's five
`test_module_dispatch_*` tests still pass here, and all 15 also pass with
`torch._dynamo.config.use_recursive_dict_tags_for_guards = True` set for the
run.

Mutation controls, each run against the 15 tests at this commit and each
failing only the tests named: making `_binds_alike` return the stored verdict
whenever one exists (deciding once) fails the replaced-result test with
`RuntimeError not raised`, errors the appended-result test with `GuardManager
check failed` and times out both interleaving tests; deciding ahead of the scan
fails the first-result test with `Expected '_binds_alike' to not have been
called. Called 1 times`; never reusing the first binding fails the binds-once
test (four binds counted, not one); keeping only the length check in the
staleness test fails the replaced-result test with `RuntimeError not raised`
(`[1]` served `x * 3` on `[0]`'s binding) and still passes the appended one;
restoring `Signature` equality in `_binding_key` errors the tensor-default test
with `Boolean value of Tensor with more than one value is ambiguous`; dropping
the cells from the key fails the closure test with `True is not false`;
remembering the results by strong reference fails the retention test (`... is
not None`); splitting the field in two and publishing the contents before the
key is computed errors the new-contents interleaving test with `GuardManager
check failed` (the appended result bound from `[0]`'s default), and publishing
the verdict before the contents fails the old-contents test with `RuntimeError
not raised` (both two-field variants also error the first-result test, which
reads the field they split). The `co_freevars` term of the key has no mismatch
test: two results holding the same cell under different names take a
hand-built code object, and the term is one tuple compare of what the bind
reads.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: #197071
Approved by: https://github.com/pytorchgreenlight
ghstack dependencies: #196767, #196817, #196815, #196816, #196818, #196819, #196820, #196821, #196895, #196904, #197055, #196824
pytorchmergebot pushed a commit that referenced this pull request Sep 15, 2026
…e dispatch (#197047)

The parent's `AOTCompiledModel.__call__` scans every compiled result for a
guard match, re-checks every result, and then falls through into
`compiled_results[0]`:

```python
for result, f_locals in zip(results, bound):           # scan
    if result._live_guard_manager().check(f_locals): return result.fn(...)
for result, f_locals in zip(results, bound):           # re-check
    if result._live_guard_manager().check(f_locals): return result.fn(...)
return results[0](self.model, *args, **kwargs)         # fall through: raises, OR runs if [0] opted out
```

The last line does not raise by itself. `AOTCompiledFunction.__call__` skips its
guards when that one result has `disable_guard_check()` set, so what an
unmatched call gets still turns on the POSITION of an opt-out:
`compiled_results[0].disable_guard_check()` makes `[0]` run any call no result
guards, while the same flag on `compiled_results[1]` is inert and the call
raises `GuardManager check failed`. Measured on a two-input `ScaleModule`
(float32 and float64) called with float16, each result's `fn` wrapped to record
which one served:

```
PARENT [enabled, enabled]     : RuntimeError: GuardManager check failed ...
PARENT [enabled, opted_out]   : RuntimeError: GuardManager check failed ...   <- the flag on [1] is inert
PARENT [opted_out, enabled]   : SERVED by [0]
PARENT [opted_out, opted_out] : SERVED by [0]
```

This commit adds a third stage between the re-check and the fall-through that
serves the first opted-out result, from any index, and only after both passes
found no match:

```python
for result in results:                                 # NEW: honour an opt-out from any position
    if not result._guard_check_enabled:
        return result.fn(self.model, *args, **kwargs)
return results[0](self.model, *args, **kwargs)         # only enabled results reach here, so it raises
```

```
HEAD   [enabled, enabled]     : RuntimeError: GuardManager check failed ...
HEAD   [enabled, opted_out]   : SERVED by [1]                                 <- the one change
HEAD   [opted_out, enabled]   : SERVED by [0]
HEAD   [opted_out, opted_out] : SERVED by [0]
```

The fall-through is then reached only when every result has its check enabled,
so its comment now says that `results[0]` raises, not "run one of them".

## What the flag now means on a module

`compiled_results[i].disable_guard_check()` on a module artifact now makes
result `i` the fallback for any call no compiled input guards, from any index.
At the parent only `i == 0` had that effect and an opt-out elsewhere was inert;
the flag was therefore position-dependent, not a contract. The module path
(`_aot_compile`, `ModelInput`) is private and its docstring says Experimental,
so no BC guarantee is owed. Nothing the parent served is refused
(`[opted_out, enabled]` still serves `[0]`); the only change is raise->serve
for `[enabled, opted_out]`, and only after every result's guards were checked
twice and none accepted.

```python
model._aot_compile([ModelInput((x, 0), {}, []), ModelInput((x, 1), {}, [])])   # ModeBranchGlobalModule
model.forward.compiled_results[1].disable_guard_check()
model(x, 2)     # neither input guards mode=2
# parent: RuntimeError: GuardManager check failed ... L['mode'] == 0   ([0] re-entered alone)
# now:    x * AOT_BRANCH_SCALE, [1]'s graph -- deliberately NOT eager's answer for mode=2:
#         serving a graph compiled for a different call is what the opt-out exists to do
```

Why serve rather than raise: on the function path
`AOTCompiledFunction.__call__` short-circuits on the flag and runs the graph
whatever it is called with, and the scan already serves an opted-out result
whose guards pass, which is what an enabled result gets too, so raising on a
no-match would leave `disable_guard_check()` with no effect at all on a model.
It would also have to keep serving `[opted_out, enabled]`, which the parent
serves, so "raise" was never available without a position rule of its own. A
real match is always preferred to the opt-out: the scan and the re-check run
over every result, opted out or not, before this stage is consulted, so the
opted-out graph is served only for a call no compiled input guards.

## Where the stage sits, and the three orderings the tests pin

Ordering matters more than it looks. With this stage ahead of the re-check, an
opted-out result answers first and silently serves a graph compiled for a
different call in exactly the case the re-check exists for: a first `check()`
that refused from the recursive dict-tag fast path without running the tree.
The parent pins that order from the fall-through's side with
`test_module_dispatch_rechecks_before_honouring_an_opt_out` and
`test_module_dispatch_rechecks_an_opted_out_result_whose_tree_accepts`; moving
this stage ahead of the re-check serves `[0]`'s `x * 2` and fails both with
`Mismatched elements: 9 / 9`, and the other twelve stay green.

`test_module_dispatch_serves_an_opted_out_result_from_any_position` pins the
other two orderings in three assertions:

```python
model.forward.compiled_results[1].disable_guard_check()
model(x, 2) == x * AOT_BRANCH_SCALE   # [1] serves from index 1; the parent raised here
model(x, 0) == x * 2                  # [0]'s REAL match still outranks [1]'s opt-out:
                                      #   the stage cannot be hoisted into the scan
model.forward.compiled_results[0].disable_guard_check()
model(x, 2) == x * 2                  # both opted out, nothing matches: index order decides,
                                      #   as it did at the fall-through
```

Moving the stage ahead of the scan as well fails the second assertion, and
reversing the stage's iteration order fails only the third.
`[opted_out, enabled]` with a match at `[1]` is
`test_module_dispatch_rechecks_before_honouring_an_opt_out`.

## To review

The five-line loop in `torch/_dynamo/aot_compile.py` between the re-check and
the fall-through, and the fall-through's reworded comment; the one clause
appended to the dispatch paragraph of the `AOTCompiledModel` docstring; the one
test, three assertions; and the clause added to the `disable_guard_check()`
entry of `docs/source/user_guide/torch_compiler/torch.compiler_aot_compile.md`,
which described the flag only as the function path honours it ("runs whatever
it is called with, without evaluating its guards") and now says that a
module's dispatch still guard-checks an opted-out result and serves it on the
opt-out alone only for a call no result's guards accept.

Test Plan:

```
python test/dynamo/test_aot_compile.py -k test_module_dispatch_serves_an_opted_out_result_from_any_position
python test/dynamo/test_aot_compile.py -k test_module_dispatch_
python test/dynamo/test_aot_compile.py
lintrunner --take RUFF,PYFMT test/dynamo/test_aot_compile.py torch/_dynamo/aot_compile.py
```

The new test fails at the parent with `RuntimeError: GuardManager check
failed` (the fall-through re-enters `compiled_results[0]`, whose guard check is
enabled) and passes here; the other 13 `test_module_dispatch_*` tests pass at
both. The full file runs 182 tests and passes (6 skipped). The table above was
measured by building the model and opting results out per row at the parent
and at this commit. Lint is clean.

> **FAQ: Why does dispatch serve an opted-out result when nothing matched, when
> #196929's description calls the parent's position-dependent serve an
> accident?** Measured against the parent on a two-input `ScaleModule` (float32
> and float64) called with float16: `[opted_out, enabled]` is SERVED at the
> parent and SERVED here, `[enabled, opted_out]` raises at the parent and is
> SERVED here, and `[enabled, enabled]` raises in both. So serving an opted-out
> result on a no-match is pre-existing behaviour, not new -- what is new is that
> it no longer depends on the opt-out sitting at index 0. The defect #196929
> names is that whether you got a report at all turned on list order, since the
> fall-through re-raised only because `compiled_results[0]` happened to have its
> guard check enabled. Raising instead would make `disable_guard_check()` inert
> on the model path, because the scan already serves an opted-out result whose
> guards do pass, so the flag would buy nothing an enabled result does not
> already get; it would also refuse the `[opted_out, enabled]` call the parent
> serves today, and it would red
> `test_module_dispatch_serves_an_opted_out_result_from_any_position`, which
> pins exactly the `[enabled, opted_out]` serve.
>
> There is a third option: keep the fall-through but raise from the first
> *enabled* result rather than `results[0]`,
> `next((r for r in results if r._guard_check_enabled), results[0])`. That fixes
> which result reports without widening what is served. Measured on the same
> model it raises for `[enabled, enabled]`, `[enabled, opted_out]` and
> `[opted_out, enabled]`, and serves only `[opted_out, opted_out]` (by `[0]`):
> it refuses the `[opted_out, enabled]` no-match the parent serves today, and a
> single opt-out next to any enabled result is inert on the no-match path,
> which is the inert reading above unless every result opts out. That is a
> coherent contract too, but a narrower one than the flag has on the function
> path, so it was not taken.
>
> On the blast radius of one opt-out anywhere in the list: a real match is
> always preferred to it. The scan and the re-check run over every result, opted
> out or not, before the last resort is consulted, so the opted-out graph is
> served only for a call no compiled input guards, which is exactly the call the
> flag exists to serve;
> `test_module_dispatch_rechecks_before_honouring_an_opt_out` pins that order,
> and the new test's `model(x, 0)` assertion pins that a match at `[0]`
> outranks an opt-out at `[1]`. Narrowing the flag to "suppress my own report
> but still require a match" is the inert reading above, and is why the flag is
> documented as model-wide on this path.

> **FAQ: `_guard_check_enabled` is not serialized, so is this stage
> in-process only?** Yes, and that is pre-existing on both paths:
> `AOTCompiledFunction.serialize` copies `fn._artifacts.__dict__`, and the flag
> is a field of the function, not of its artifacts, so a loaded result starts
> enabled whether it is called directly or through a module's dispatch. The
> opt-out has always been something the caller sets on the results it holds
> after building or loading them; this commit changes where the module path
> honours it, not whether it is saved.

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: #197047
Approved by: https://github.com/pytorchgreenlight
ghstack dependencies: #196767, #196817, #196815, #196816, #196818, #196819, #196820, #196821, #196895, #196904, #197055, #196824, #197071
bobrenjc93 added a commit that referenced this pull request Sep 15, 2026
… its advice stays

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. Each of the four passes at the
report commit, whose report it pins, and fails below it, at the dispatch commit
049617d (#196929), where the no-match fall-through `results[0](self.model,
*args, **kwargs)` raises the function path's `GuardManager check failed`
message. That message is not empty of the report's text: it 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`, `the module the
compiled function was traced in` and `a guarded global is missing` substrings
the tests also look for are present there. What it lacks is the `[i]` entry
prefix and the `Add a ModelInput` footer, and each of the four asserts on one
of those two: measured with that commit's `aot_compile.py` under this tree's
test file, `stays_neutral`, `advises_an_input` and `resolves_forward_only` each
fail on `"[0] KeyError on G[...]" not found` alone, and
`missing_key_inside_a_present_global` on `'Add a ModelInput' not found` alone.
Every one of them captures in this process, so every one calls
`_hide_leaked_dynamo_globals()` on entry, as the capture-only
`test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` does. What
each catches at this tree, and which of the report commit's own tests would
catch the same edit, was measured by editing the report:

`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, 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. The wording is decided
by the identity compare `resolved is not missing_global._guard_globals`, and
this test is not the only one that pins it: reducing the condition to `resolved
is None` fails it with a report that names `this HermeticModule instance's
forward`, and of the file's 194 tests fails exactly one other, #196818's
`test_aot_compile_module_missing_global_hint_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`. The
report commit's `test_no_match_report_survives_a_forward_resolve_that_raises`
reaches the neutral wording through `resolved is None`, and
`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_missing_key_inside_a_present_global_is_not_a_missing_global` pins which
predicate the report reaches for. A guard on
`G['GLOBAL_POOLING_CONFIG']['pooling']` with the KEY popped reports `KeyError
on G['GLOBAL_POOLING_CONFIG']['pooling']`, asserted in full, as the function
path's `test_aot_compile_fn_missing_nested_key_gets_no_missing_global_hint`
asserts it -- an ordinary mismatch: the report keeps the advice and withholds
the hint, whose "define the global" would be wrong. Replacing
`_names_a_missing_global` with a `"KeyError on G["` substring test fails it on
the hint's presence, and passes every report test in the report commit, each
of whose missing globals is a whole part. The whole-part match itself came in
with the function path's hint and is pinned there.

`test_no_match_message_advises_an_input_for_a_missing_global` pins the shape
the report commit's argument for unconditional advice rests on.
`SelfModeBranchGlobalModule`, the fixture it adds, branches on `self.mode`
rather than an argument: that guard is a `LOCAL_UNSPECIALIZED_NN_MODULE`
source, which sorts after `GLOBAL`, so the root's `G` accessor is installed --
and fails -- before the `self.mode` guard (the `L['x']` `TENSOR_MATCH`, a
`LOCAL`, precedes both), and the one entry names only the missing global.
`check_verbose` quotes the first failing guard and nothing after it, so the
absence of `L['self'].mode` from that report cannot by itself show a mismatch
was hidden; the test then puts the global back and calls again, and the same
call now fails on `[0] L['self'].mode == 1` alone. The two halves run in that
order because a failed `check()` re-sorts the root's children by fail count
(`GuardManager::check_nopybind`, guards.cpp): had `self.mode` failed first, it
would sit ahead of the `G` accessor and the popped-global call would name it
instead of the KeyError. An input captured for the `mode == 2` branch would not
read `AOT_BRANCH_SCALE` at all, so the advice is right and is the only
actionable line. Withholding it when every entry named a missing global --
counting the entries that did and returning before the footer when the count is
the whole report -- fails it on `Add a ModelInput`; two other one-entry reports
on a missing global fail under that edit as well, the report commit's
`test_no_match_report_survives_a_forward_resolve_that_raises` and this commit's
`test_no_match_report_resolves_forward_only_for_a_supplied_scope` (`failures=3`
on the whole file, all on `'Add a ModelInput' not found`), and
`test_no_match_message_keeps_the_advice_for_every_entry`, which pairs the
missing global with a plain mismatch, passes. What this test adds is the hidden
mismatch, which none of those has.

`test_no_match_report_resolves_forward_only_for_a_supplied_scope` is the
CAPTURED half of the pair whose SUPPLIED half,
`test_no_match_report_survives_a_forward_resolve_that_raises`, stays with the
report. It captures a plain `HermeticModule` in-process, pops the global, and
asserts the CAPTURED report arrives with no `forward` named. It wraps
`_resolve_guard_scope` in a `patch(..., wraps=...)` for the call and asserts it
was never invoked, since the wording alone cannot pin the gate: the CAPTURED
hint never names `forward`, so it reads the same whether or not the resolve
ran. Replacing the SUPPLIED gate with `if True:` fails it on the count,
`Expected '_resolve_guard_scope' to not have been called. Called 1 times`, with
the `except Exception` around the resolve kept or removed, and passes every
other SUPPLIED report test -- the report commit's
`test_no_match_report_survives_a_forward_resolve_that_raises` and
`test_no_match_message_hint_covers_a_rebound_forward`, and this commit's
`test_no_match_message_hint_stays_neutral_for_a_supplied_scope`, all of which
resolve either way -- so this is the one test that pins the gate. The count
carries the assertion, so the test no longer rebinds `forward` to a
`functools.partial` over `RaisingReprModule`: on this path a resolve that
raised would be swallowed by that catch and change nothing the test could see,
and the catch itself is `survives_a_forward_resolve_that_raises`'s to pin --
with the catch removed it errors with `ValueError: extra_repr`.

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_missing_key_inside_a_present_global_is_not_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_message_advises_an_input_for_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_report_resolves_forward_only_for_a_supplied_scope
python test/dynamo/test_aot_compile.py
```

The whole file runs 194 tests here, 190 on the parent commit: `Ran 194
tests`, `OK (skipped=6)`.

## FAQ

> **FAQ: The review asked that
> `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` read
> `AOT_HERMETIC_WEIGHT` through a reference captured at import instead of
> asserting it is in `HermeticModule.forward.__globals__`. Why an identity
> assertion instead?**
>
> The membership assertion was standing in for a claim about which dict the
> guards read, so the test states that claim directly:
> `compiled.compiled_results[0]._guard_globals is scope` -- the guards hold the
> supplied dict -- and the read that follows, `scope["AOT_HERMETIC_WEIGHT"] =
> AOT_HERMETIC_WEIGHT` serving the call, is the dict a forward-naming hint would
> have sent the reader away from. An earlier revision also asserted
> `HermeticModule.forward.__globals__ is globals()`; that holds by construction
> for a class defined in this file and observes nothing about the code under
> test, so it is gone. The two bare `AOT_HERMETIC_WEIGHT` reads are pre-existing
> and shared with every test in the file that uses the fixture; a sibling that
> failed to restore the name would break the module, not this test's ordering,
> and a captured alias would only move that dependency to import time.

> **FAQ: The review asked
> `test_no_match_message_advises_an_input_for_a_missing_global` to first show
> the report naming `L['self'].mode` with the global defined, then pop the
> global and show the KeyError replacing it. Why the other order?**
>
> Because the guard tree remembers its failures. `GuardManager::check_nopybind`
> (torch/csrc/dynamo/guards.cpp) bumps a child's fail count when it rejects and,
> unless the failure was on the first child, re-sorts the root's accessors by
> fail count so the next check fails fast. Run the mismatch half first and the
> `self.mode` accessor moves ahead of the `G` accessor; the popped-global call
> then reports `L['self'].mode == 1` rather than the KeyError (measured on a
> scratch copy: both calls name `self.mode`). Popped first, the `G` accessor
> is the one promoted, it resolves once the global is back, and the second call
> fails on `self.mode` alone -- which is the positive witness the review asked
> for, on the same compiled result.

> **FAQ: The review found that
> `test_aot_compile_module_missing_global_hint_names_the_resolved_module`, in
> #196818 below, already fails under the `resolved is None` edit that this
> commit's `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` was
> 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 None`: `Ran 194 tests`, `FAILED (failures=2)`, the two being
> `..._names_the_resolved_module` (`'loaded against; define it there' not
> found`) and this test; every other test passes. So the identity compare is
> fenced at #196818, and the message now says so instead of crediting this
> test. 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. The same pass dropped the static
> `HermeticModule.forward.__globals__ is globals()` assertion, replaced the
> raising-repr scaffolding in `..._resolves_forward_only_for_a_supplied_scope`
> with a plain `HermeticModule()` (the mock's call count carries the
> assertion; a raise on that path would be swallowed by the report's catch),
> and moved the `patch(...)` construction there above `g.pop` so nothing sits
> between the pop and the `try`.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ghstack-source-id: 9cea9f6
Pull-Request: #197001
bobrenjc93 added a commit that referenced this pull request Sep 16, 2026
…and that its advice stays

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. Each of the four passes at the
report commit, whose report it pins, and fails below it, at the dispatch commit
049617d (#196929), where the no-match fall-through `results[0](self.model,
*args, **kwargs)` raises the function path's `GuardManager check failed`
message. That message is not empty of the report's text: it 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`, `the module the
compiled function was traced in` and `a guarded global is missing` substrings
the tests also look for are present there. What it lacks is the `[i]` entry
prefix and the `Add a ModelInput` footer, and each of the four asserts on one
of those two: measured with that commit's `aot_compile.py` under this tree's
test file, `stays_neutral`, `advises_an_input` and `resolves_forward_only` each
fail on `"[0] KeyError on G[...]" not found` alone, and
`missing_key_inside_a_present_global` on `'Add a ModelInput' not found` alone.
Every one of them captures in this process, so every one calls
`_hide_leaked_dynamo_globals()` on entry, as the capture-only
`test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` does. What
each catches at this tree, and which of the report commit's own tests would
catch the same edit, was measured by editing the report:

`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, 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. The wording is decided
by the identity compare `resolved is not missing_global._guard_globals`, and
this test is not the only one that pins it: reducing the condition to `resolved
is None` fails it with a report that names `this HermeticModule instance's
forward`, and of the file's 194 tests fails exactly one other, #196818's
`test_aot_compile_module_missing_global_hint_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`. The
report commit's `test_no_match_report_survives_a_forward_resolve_that_raises`
reaches the neutral wording through `resolved is None`, and
`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_missing_key_inside_a_present_global_is_not_a_missing_global` pins which
predicate the report reaches for. A guard on
`G['GLOBAL_POOLING_CONFIG']['pooling']` with the KEY popped reports `KeyError
on G['GLOBAL_POOLING_CONFIG']['pooling']`, asserted in full, as the function
path's `test_aot_compile_fn_missing_nested_key_gets_no_missing_global_hint`
asserts it -- an ordinary mismatch: the report keeps the advice and withholds
the hint, whose "define the global" would be wrong. Replacing
`_names_a_missing_global` with a `"KeyError on G["` substring test fails it on
the hint's presence, and passes every report test in the report commit, each
of whose missing globals is a whole part. The whole-part match itself came in
with the function path's hint and is pinned there.

`test_no_match_message_advises_an_input_for_a_missing_global` pins the shape
the report commit's argument for unconditional advice rests on.
`SelfModeBranchGlobalModule`, the fixture it adds, branches on `self.mode`
rather than an argument: that guard is a `LOCAL_UNSPECIALIZED_NN_MODULE`
source, which sorts after `GLOBAL`, so the root's `G` accessor is installed --
and fails -- before the `self.mode` guard (the `L['x']` `TENSOR_MATCH`, a
`LOCAL`, precedes both), and the one entry names only the missing global.
`check_verbose` quotes the first failing guard and nothing after it, so the
absence of `L['self'].mode` from that report cannot by itself show a mismatch
was hidden; the test then puts the global back and calls again, and the same
call now fails on `[0] L['self'].mode == 1` alone. The two halves run in that
order because a failed `check()` re-sorts the root's children by fail count
(`GuardManager::check_nopybind`, guards.cpp): had `self.mode` failed first, it
would sit ahead of the `G` accessor and the popped-global call would name it
instead of the KeyError. An input captured for the `mode == 2` branch would not
read `AOT_BRANCH_SCALE` at all, so the advice is right and is the only
actionable line. Withholding it when every entry named a missing global --
counting the entries that did and returning before the footer when the count is
the whole report -- fails it on `Add a ModelInput`; two other one-entry reports
on a missing global fail under that edit as well, the report commit's
`test_no_match_report_survives_a_forward_resolve_that_raises` and this commit's
`test_no_match_report_resolves_forward_only_for_a_supplied_scope` (`failures=3`
on the whole file, all on `'Add a ModelInput' not found`), and
`test_no_match_message_keeps_the_advice_for_every_entry`, which pairs the
missing global with a plain mismatch, passes. What this test adds is the hidden
mismatch, which none of those has.

`test_no_match_report_resolves_forward_only_for_a_supplied_scope` is the
CAPTURED half of the pair whose SUPPLIED half,
`test_no_match_report_survives_a_forward_resolve_that_raises`, stays with the
report. It captures a plain `HermeticModule` in-process, pops the global, and
asserts the CAPTURED report arrives with no `forward` named. It wraps
`_resolve_guard_scope` in a `patch(..., wraps=...)` for the call and asserts it
was never invoked, since the wording alone cannot pin the gate: the CAPTURED
hint never names `forward`, so it reads the same whether or not the resolve
ran. Replacing the SUPPLIED gate with `if True:` fails it on the count,
`Expected '_resolve_guard_scope' to not have been called. Called 1 times`, with
the `except Exception` around the resolve kept or removed, and passes every
other SUPPLIED report test -- the report commit's
`test_no_match_report_survives_a_forward_resolve_that_raises` and
`test_no_match_message_hint_covers_a_rebound_forward`, and this commit's
`test_no_match_message_hint_stays_neutral_for_a_supplied_scope`, all of which
resolve either way -- so this is the one test that pins the gate. The count
carries the assertion, so the test no longer rebinds `forward` to a
`functools.partial` over `RaisingReprModule`: on this path a resolve that
raised would be swallowed by that catch and change nothing the test could see,
and the catch itself is `survives_a_forward_resolve_that_raises`'s to pin --
with the catch removed it errors with `ValueError: extra_repr`.

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_missing_key_inside_a_present_global_is_not_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_message_advises_an_input_for_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_report_resolves_forward_only_for_a_supplied_scope
python test/dynamo/test_aot_compile.py
```

The whole file runs 194 tests here, 190 on the parent commit: `Ran 194
tests`, `OK (skipped=6)`.

## FAQ

> **FAQ: The review asked that
> `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` read
> `AOT_HERMETIC_WEIGHT` through a reference captured at import instead of
> asserting it is in `HermeticModule.forward.__globals__`. Why an identity
> assertion instead?**
>
> The membership assertion was standing in for a claim about which dict the
> guards read, so the test states that claim directly:
> `compiled.compiled_results[0]._guard_globals is scope` -- the guards hold the
> supplied dict -- and the read that follows, `scope["AOT_HERMETIC_WEIGHT"] =
> AOT_HERMETIC_WEIGHT` serving the call, is the dict a forward-naming hint would
> have sent the reader away from. An earlier revision also asserted
> `HermeticModule.forward.__globals__ is globals()`; that holds by construction
> for a class defined in this file and observes nothing about the code under
> test, so it is gone. The two bare `AOT_HERMETIC_WEIGHT` reads are pre-existing
> and shared with every test in the file that uses the fixture; a sibling that
> failed to restore the name would break the module, not this test's ordering,
> and a captured alias would only move that dependency to import time.

> **FAQ: The review asked
> `test_no_match_message_advises_an_input_for_a_missing_global` to first show
> the report naming `L['self'].mode` with the global defined, then pop the
> global and show the KeyError replacing it. Why the other order?**
>
> Because the guard tree remembers its failures. `GuardManager::check_nopybind`
> (torch/csrc/dynamo/guards.cpp) bumps a child's fail count when it rejects and,
> unless the failure was on the first child, re-sorts the root's accessors by
> fail count so the next check fails fast. Run the mismatch half first and the
> `self.mode` accessor moves ahead of the `G` accessor; the popped-global call
> then reports `L['self'].mode == 1` rather than the KeyError (measured on a
> scratch copy: both calls name `self.mode`). Popped first, the `G` accessor
> is the one promoted, it resolves once the global is back, and the second call
> fails on `self.mode` alone -- which is the positive witness the review asked
> for, on the same compiled result.

> **FAQ: The review found that
> `test_aot_compile_module_missing_global_hint_names_the_resolved_module`, in
> #196818 below, already fails under the `resolved is None` edit that this
> commit's `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` was
> 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 None`: `Ran 194 tests`, `FAILED (failures=2)`, the two being
> `..._names_the_resolved_module` (`'loaded against; define it there' not
> found`) and this test; every other test passes. So the identity compare is
> fenced at #196818, and the message now says so instead of crediting this
> test. 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. The same pass dropped the static
> `HermeticModule.forward.__globals__ is globals()` assertion, replaced the
> raising-repr scaffolding in `..._resolves_forward_only_for_a_supplied_scope`
> with a plain `HermeticModule()` (the mock's call count carries the
> assertion; a raise on that path would be swallowed by the report's catch),
> and moved the `patch(...)` construction there above `g.pop` so nothing sits
> between the pop and the `try`.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ghstack-source-id: b077b77
Pull-Request: #197001
bobrenjc93 added a commit that referenced this pull request Sep 16, 2026
…and that its advice stays

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. Each of the four passes at the
report commit, whose report it pins, and fails below it, at the dispatch commit
049617d (#196929), where the no-match fall-through `results[0](self.model,
*args, **kwargs)` raises the function path's `GuardManager check failed`
message. That message is not empty of the report's text: it 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`, `the module the
compiled function was traced in` and `a guarded global is missing` substrings
the tests also look for are present there. What it lacks is the `[i]` entry
prefix and the `Add a ModelInput` footer, and each of the four asserts on one
of those two: measured with that commit's `aot_compile.py` under this tree's
test file, `stays_neutral`, `advises_an_input` and `resolves_forward_only` each
fail on `"[0] KeyError on G[...]" not found` alone, and
`missing_key_inside_a_present_global` on `'Add a ModelInput' not found` alone.
Every one of them captures in this process, so every one calls
`_hide_leaked_dynamo_globals()` on entry, as the capture-only
`test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` does. What
each catches at this tree, and which of the report commit's own tests would
catch the same edit, was measured by editing the report:

`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, 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. The wording is decided
by the identity compare `resolved is not missing_global._guard_globals`, and
this test is not the only one that pins it: reducing the condition to `resolved
is None` fails it with a report that names `this HermeticModule instance's
forward`, and of the file's 194 tests fails exactly one other, #196818's
`test_aot_compile_module_missing_global_hint_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`. The
report commit's `test_no_match_report_survives_a_forward_resolve_that_raises`
reaches the neutral wording through `resolved is None`, and
`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_missing_key_inside_a_present_global_is_not_a_missing_global` pins which
predicate the report reaches for. A guard on
`G['GLOBAL_POOLING_CONFIG']['pooling']` with the KEY popped reports `KeyError
on G['GLOBAL_POOLING_CONFIG']['pooling']`, asserted in full, as the function
path's `test_aot_compile_fn_missing_nested_key_gets_no_missing_global_hint`
asserts it -- an ordinary mismatch: the report keeps the advice and withholds
the hint, whose "define the global" would be wrong. Replacing
`_names_a_missing_global` with a `"KeyError on G["` substring test fails it on
the hint's presence, and passes every report test in the report commit, each
of whose missing globals is a whole part. The whole-part match itself came in
with the function path's hint and is pinned there.

`test_no_match_message_advises_an_input_for_a_missing_global` pins the shape
the report commit's argument for unconditional advice rests on.
`SelfModeBranchGlobalModule`, the fixture it adds, branches on `self.mode`
rather than an argument: that guard is a `LOCAL_UNSPECIALIZED_NN_MODULE`
source, which sorts after `GLOBAL`, so the root's `G` accessor is installed --
and fails -- before the `self.mode` guard (the `L['x']` `TENSOR_MATCH`, a
`LOCAL`, precedes both), and the one entry names only the missing global.
`check_verbose` quotes the first failing guard and nothing after it, so the
absence of `L['self'].mode` from that report cannot by itself show a mismatch
was hidden; the test then puts the global back and calls again, and the same
call now fails on `[0] L['self'].mode == 1` alone. The two halves run in that
order because a failed `check()` re-sorts the root's children by fail count
(`GuardManager::check_nopybind`, guards.cpp): had `self.mode` failed first, it
would sit ahead of the `G` accessor and the popped-global call would name it
instead of the KeyError. An input captured for the `mode == 2` branch would not
read `AOT_BRANCH_SCALE` at all, so the advice is right and is the only
actionable line. Withholding it when every entry named a missing global --
counting the entries that did and returning before the footer when the count is
the whole report -- fails it on `Add a ModelInput`; two other one-entry reports
on a missing global fail under that edit as well, the report commit's
`test_no_match_report_survives_a_forward_resolve_that_raises` and this commit's
`test_no_match_report_resolves_forward_only_for_a_supplied_scope` (`failures=3`
on the whole file, all on `'Add a ModelInput' not found`), and
`test_no_match_message_keeps_the_advice_for_every_entry`, which pairs the
missing global with a plain mismatch, passes. What this test adds is the hidden
mismatch, which none of those has.

`test_no_match_report_resolves_forward_only_for_a_supplied_scope` is the
CAPTURED half of the pair whose SUPPLIED half,
`test_no_match_report_survives_a_forward_resolve_that_raises`, stays with the
report. It captures a plain `HermeticModule` in-process, pops the global, and
asserts the CAPTURED report arrives with no `forward` named. It wraps
`_resolve_guard_scope` in a `patch(..., wraps=...)` for the call and asserts it
was never invoked, since the wording alone cannot pin the gate: the CAPTURED
hint never names `forward`, so it reads the same whether or not the resolve
ran. Replacing the SUPPLIED gate with `if True:` fails it on the count,
`Expected '_resolve_guard_scope' to not have been called. Called 1 times`, with
the `except Exception` around the resolve kept or removed, and passes every
other SUPPLIED report test -- the report commit's
`test_no_match_report_survives_a_forward_resolve_that_raises` and
`test_no_match_message_hint_covers_a_rebound_forward`, and this commit's
`test_no_match_message_hint_stays_neutral_for_a_supplied_scope`, all of which
resolve either way -- so this is the one test that pins the gate. The count
carries the assertion, so the test no longer rebinds `forward` to a
`functools.partial` over `RaisingReprModule`: on this path a resolve that
raised would be swallowed by that catch and change nothing the test could see,
and the catch itself is `survives_a_forward_resolve_that_raises`'s to pin --
with the catch removed it errors with `ValueError: extra_repr`.

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_missing_key_inside_a_present_global_is_not_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_message_advises_an_input_for_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_report_resolves_forward_only_for_a_supplied_scope
python test/dynamo/test_aot_compile.py
```

The whole file runs 194 tests here, 190 on the parent commit: `Ran 194
tests`, `OK (skipped=6)`.

## FAQ

> **FAQ: The review asked that
> `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` read
> `AOT_HERMETIC_WEIGHT` through a reference captured at import instead of
> asserting it is in `HermeticModule.forward.__globals__`. Why an identity
> assertion instead?**
>
> The membership assertion was standing in for a claim about which dict the
> guards read, so the test states that claim directly:
> `compiled.compiled_results[0]._guard_globals is scope` -- the guards hold the
> supplied dict -- and the read that follows, `scope["AOT_HERMETIC_WEIGHT"] =
> AOT_HERMETIC_WEIGHT` serving the call, is the dict a forward-naming hint would
> have sent the reader away from. An earlier revision also asserted
> `HermeticModule.forward.__globals__ is globals()`; that holds by construction
> for a class defined in this file and observes nothing about the code under
> test, so it is gone. The two bare `AOT_HERMETIC_WEIGHT` reads are pre-existing
> and shared with every test in the file that uses the fixture; a sibling that
> failed to restore the name would break the module, not this test's ordering,
> and a captured alias would only move that dependency to import time.

> **FAQ: The review asked
> `test_no_match_message_advises_an_input_for_a_missing_global` to first show
> the report naming `L['self'].mode` with the global defined, then pop the
> global and show the KeyError replacing it. Why the other order?**
>
> Because the guard tree remembers its failures. `GuardManager::check_nopybind`
> (torch/csrc/dynamo/guards.cpp) bumps a child's fail count when it rejects and,
> unless the failure was on the first child, re-sorts the root's accessors by
> fail count so the next check fails fast. Run the mismatch half first and the
> `self.mode` accessor moves ahead of the `G` accessor; the popped-global call
> then reports `L['self'].mode == 1` rather than the KeyError (measured on a
> scratch copy: both calls name `self.mode`). Popped first, the `G` accessor
> is the one promoted, it resolves once the global is back, and the second call
> fails on `self.mode` alone -- which is the positive witness the review asked
> for, on the same compiled result.

> **FAQ: The review found that
> `test_aot_compile_module_missing_global_hint_names_the_resolved_module`, in
> #196818 below, already fails under the `resolved is None` edit that this
> commit's `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` was
> 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 None`: `Ran 194 tests`, `FAILED (failures=2)`, the two being
> `..._names_the_resolved_module` (`'loaded against; define it there' not
> found`) and this test; every other test passes. So the identity compare is
> fenced at #196818, and the message now says so instead of crediting this
> test. 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. The same pass dropped the static
> `HermeticModule.forward.__globals__ is globals()` assertion, replaced the
> raising-repr scaffolding in `..._resolves_forward_only_for_a_supplied_scope`
> with a plain `HermeticModule()` (the mock's call count carries the
> assertion; a raise on that path would be swallowed by the report's catch),
> and moved the `patch(...)` construction there above `g.pop` so nothing sits
> between the pop and the `try`.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ghstack-source-id: 4c20b93
Pull-Request: #197001
bobrenjc93 added a commit that referenced this pull request Sep 16, 2026
… its advice stays

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. Each of the five 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 is not empty of the report's text: it 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`, `the module the
compiled function was traced in` and `a guarded global is missing` substrings
the tests also look for are present there. What it lacks is the `[i]` entry
prefix, the `For [i]:` hint line and the `Add a ModelInput` footer, and every
test asserts on one of those: measured with that tree's `aot_compile.py` under
this tree's test file, `stays_neutral`, `advises_an_input`,
`resolves_forward_only` and `missing_key_inside_a_present_global` each fail on
`"[0] KeyError on G[...]" not found`, and
`names_forward_only_for_the_dict_it_resolves_to` on `Expected
'_resolve_guard_scope' to have been called once. Called 0 times`, the
fall-through resolving nothing. The four that compile in their own body call
`_hide_leaked_dynamo_globals()` on entry, as the capture-only
`test_aot_compile_fn_missing_global_hint_names_the_tracing_scope` does; the
fifth 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.

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. 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 (220 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`, 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_missing_key_inside_a_present_global_is_not_a_missing_global` pins which
predicate the report reaches for. A guard on
`G['GLOBAL_POOLING_CONFIG']['pooling']` with the KEY popped reports `[0]
KeyError on G['GLOBAL_POOLING_CONFIG']['pooling']`, asserted in full with its
entry prefix, as the function path's
`test_aot_compile_fn_missing_nested_key_gets_no_missing_global_hint` asserts
the part -- an ordinary mismatch: the report keeps the advice and withholds
the hint, whose "define the global" would be wrong. Replacing the report's
`_names_a_missing_global` test with a `"KeyError on G[" in part` substring
test fails it on the hint's presence (`'a guarded global is missing'
unexpectedly found`) and nothing else in the file (`failures=1`): every other
report test's missing global is a whole part. The whole-part match itself came
in with the function path's hint and is pinned there. It sits with this
commit's other report tests rather than with the load tests, as the contrast
to the whole-global `KeyError on G['GLOBAL_POOLING_CONFIG']` entries
`hints_each_scope_a_mixed_model_failed_in` and the test before this one assert.

`test_no_match_message_advises_an_input_for_a_missing_global` pins the shape
the case for an unconditional footer rests on. `SelfModeBranchGlobalModule`,
the fixture it adds, branches on `self.mode` rather than an argument: that
guard is a `LOCAL_UNSPECIALIZED_NN_MODULE` source, which sorts after `GLOBAL`,
so the root's `G` accessor is installed -- and fails -- before the `self.mode`
guard (the `L['x']` `TENSOR_MATCH`, a `LOCAL`, precedes both), and the one
entry names only the missing global. Install order is only half of why:
`check_verbose` returns the first failing accessor's parts and nothing after
them (`check_accessors_verbose_nopybind`, torch/csrc/dynamo/guards.cpp), which
is what keeps `L['self'].mode` out of the report, so its absence cannot by
itself show a mismatch was hidden; the fixture's comment names both halves, and
the test then puts the global back and calls again, and the same call now fails
on `[0] L['self'].mode == 1` alone. The two halves run in that order because a failed `check()` re-sorts the
root's children by fail count (`GuardManager::check_nopybind`, guards.cpp): had
`self.mode` failed first, it would sit ahead of the `G` accessor and the
popped-global call would name it instead of the KeyError. An input captured for
the `mode == 2` branch would not read `AOT_BRANCH_SCALE` at all, so the advice
is right and is the only actionable line. Returning before the footer when
every entry was hinted -- `sum(map(len, hinted.values())) == len(results)` --
fails it on `Add a ModelInput`, and fails the file's three other one-entry
reports on a missing global the same way: #196825's
`test_aot_compile_module_absent_global_fails_guard`, #197048's
`test_no_match_report_survives_a_forward_resolve_that_raises` and this commit's
`test_no_match_report_resolves_forward_only_for_a_supplied_scope`
(`failures=4`, all on `'Add a ModelInput' not found`); #197149's
`test_no_match_message_hints_only_the_entry_that_named_a_missing_global`, which
pairs the missing global with a plain mismatch, passes. What this test adds is
the hidden mismatch, which none of those has.

`test_no_match_report_resolves_forward_only_for_a_supplied_scope` is the
CAPTURED half of the pair whose SUPPLIED half, #197048's
`test_no_match_report_survives_a_forward_resolve_that_raises`, stays with the
report. It captures a plain `HermeticModule` in-process, pops the global, and
asserts the CAPTURED report arrives with no `forward` named. It wraps
`_resolve_guard_scope` in a `patch(..., wraps=...)` for the call and asserts it
was never invoked, since the wording alone cannot pin the gate: the CAPTURED
hint never names `forward`, so it reads the same whether or not the resolve
ran. Dropping the SUPPLIED half of the gate, `if not tried_forward:`, fails it
on the count, `Expected '_resolve_guard_scope' to not have been called. Called
1 times`, and nothing else in the file (`failures=1`): the CAPTURED hint
ignores `forward`, and every SUPPLIED report test resolves either way. The
count carries the assertion, so the test does not rebind `forward` to a
`functools.partial` over `RaisingReprModule`: on this path a resolve that
raised would be swallowed by the report's `except Exception` and change nothing
the test could see, and the catch itself is
`survives_a_forward_resolve_that_raises`'s to pin.

`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. 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=3`, the other two #197048's
`covers_a_rebound_forward` and `survives_a_forward_resolve_that_raises`, on
wording: a fresh instance does not carry the `forward` those rebind); under a
bare `assert_called_once()` the same edit passes this test (`failures=2`). Deciding `forward` once, at the first hinted entry, and
applying it to every entry fails it in either order on the second entry's
wording: with the resolved-dict entry first, `[1]` names the forward (`'the
live scope this artifact was loaded against; define it there' not found in
"For [1]: ... this GlobalConfigModule instance's forward resolves to ..."`),
and with it second, `[1]` gets the neutral wording (`"this GlobalConfigModule
instance's forward resolves to" not found in 'For [1]: ... loaded against,
here vars(__main__) ...'`) -- and fails nothing else in the file
(`failures=1`): `..._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.

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_missing_key_inside_a_present_global_is_not_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_message_advises_an_input_for_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_report_resolves_forward_only_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 runs 220 tests here, 215 on the parent commit: `Ran 220
tests`, `OK (skipped=6)`.

## FAQ

> **FAQ: The review asked that
> `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` read
> `AOT_HERMETIC_WEIGHT` through a reference captured at import instead of
> asserting it is in `HermeticModule.forward.__globals__`. Why an identity
> assertion instead?**
>
> The membership assertion was standing in for a claim about which dict the
> guards read, so the test states that claim directly:
> `compiled.compiled_results[0]._guard_globals is scope` -- the guards hold the
> supplied dict -- and the read that follows, `scope["AOT_HERMETIC_WEIGHT"] =
> AOT_HERMETIC_WEIGHT` serving the call, is the dict a forward-naming hint would
> have sent the reader away from. An earlier revision also asserted
> `HermeticModule.forward.__globals__ is globals()`; that holds by construction
> for a class defined in this file and observes nothing about the code under
> test, so it is gone. The two bare `AOT_HERMETIC_WEIGHT` reads are pre-existing
> and shared with every test in the file that uses the fixture; a sibling that
> failed to restore the name would break the module, not this test's ordering,
> and a captured alias would only move that dependency to import time.

> **FAQ: The review asked
> `test_no_match_message_advises_an_input_for_a_missing_global` to first show
> the report naming `L['self'].mode` with the global defined, then pop the
> global and show the KeyError replacing it. Why the other order?**
>
> Because the guard tree remembers its failures. `GuardManager::check_nopybind`
> (torch/csrc/dynamo/guards.cpp) bumps a child's fail count when it rejects and,
> unless the failure was on the first child, re-sorts the root's accessors by
> fail count so the next check fails fast. Run the mismatch half first and the
> `self.mode` accessor moves ahead of the `G` accessor; the popped-global call
> then reports `L['self'].mode == 1` rather than the KeyError (measured on a
> scratch copy: both calls name `self.mode`). Popped first, the `G` accessor
> is the one promoted, it resolves once the global is back, and the second call
> fails on `self.mode` alone -- which is the positive witness the review asked
> for, on the same compiled result.

> **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 220 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. The same pass dropped the static
> `HermeticModule.forward.__globals__ is globals()` assertion, replaced the
> raising-repr scaffolding in `..._resolves_forward_only_for_a_supplied_scope`
> with a plain `HermeticModule()` (the mock's call count carries the
> assertion; a raise on that path would be swallowed by the report's catch),
> and moved the `patch(...)` construction there above `g.pop` so nothing sits
> between the pop and the `try`.

> **FAQ: `test_missing_key_inside_a_present_global_is_not_a_missing_global`
> asserts the same `KeyError on G['GLOBAL_POOLING_CONFIG']['pooling']` string
> as the function path's
> `test_aot_compile_fn_missing_nested_key_gets_no_missing_global_hint`, some
> 2200 lines below it. Why not put them side by side?**
>
> Because the file clusters tests by the path under test, not by the string
> they assert: the module dispatch's report tests sit together (this one
> follows `names_forward_only_for_the_dict_it_resolves_to` and precedes
> `resolves_forward_only_for_a_supplied_scope`, all on `_no_match_report`), and
> the `aot_compile_fn_*` tests sit together on the function path's
> `GuardManager check failed` message, which has no report. Moving either one
> next to the other would take it out of the cluster whose contrast it is read
> against -- the whole-global `KeyError on G['GLOBAL_POOLING_CONFIG']` entries
> its neighbours assert -- to sit with a test of a different code path, and the
> review that raised it judged the move not worth another diff.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
ghstack-source-id: 6574151
Pull-Request: #197001
bobrenjc93 added a commit that referenced this pull request Sep 16, 2026
…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
pytorchmergebot pushed a commit that referenced this pull request Sep 17, 2026
…h matches (#196823)

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.

```python
model._aot_compile([ModelInput((x, 0), {}, []), ModelInput((x, 1), {}, [])])
model(x, 2)
# parent:  RuntimeError: GuardManager check failed, reason: ... L['mode'] == 0
#          (one guard from [0]; nothing says a second graph exists or what IT wanted)
```

The previous commit made the dispatch itself scan every result, re-check every
result and honour an opt-out from any position, and kept that fall-through as
its raise. This commit replaces it with a report that names every compiled
input, built from the binding the dispatch already judged:

```
RuntimeError: No AOT compiled graph matched this call. Tried 2 compiled input(s):
  [0] L['mode'] == 0
  [1] L['mode'] == 1
Add a ModelInput covering this call, or check whether guard_filter_fn kept a guard this call
cannot satisfy -- both belong to the process that compiles the artifacts, which need not be
the one that loaded them.
```

## The footer, and its wording

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.

## A missing global gets the function path's own hint, named for the right dict

When a guard died on a global the process does not have, the report adds a
`For [i]:` line built from the function path's `_missing_global_hint`, worded
for the scope that result's guards actually resolve against:

```
  [0] L['mode'] == 0
  [1] KeyError on G['AOT_BRANCH_SCALE']
For [1]: a guarded global is missing from the globals of the function this ModeBranchGlobalModule
instance's forward resolves to, since that is the one the load resolved, here vars(mypkg.model);
define it there so the guard can resolve it.
Add a ModelInput covering this call, or check whether guard_filter_fn kept a guard ...
```

The hint names the instance's `forward` only when the guards really hold the
dict that attribute resolves to. `deserialize` skips `_resolve_guard_scope`
entirely for a caller-supplied `guard_globals=`, so a result loaded that way
holds a dict no forward resolves to and gets the scope-neutral wording instead;
naming the class's forward there sends the reader to a dict where the name is
already defined and dispatch still fails. The report decides that by comparing
the dict the guards hold against a fresh resolution rather than a bit recorded
at load, which costs a `get_traced_fn` on the raise path only and also covers a
rebind made after the load:

```python
resolved = None
if missing_global._guard_scope is _GuardScope.SUPPLIED:
    try:
        resolved, _ = _resolve_guard_scope(self.model)
    except Exception:
        pass                                   # the report must still arrive
if resolved is None or resolved is not missing_global._guard_globals:
    forward = None                             # scope-neutral wording
```

It asks only of a result whose scope is SUPPLIED: the CAPTURED and
RECONSTRUCTED wordings never name `forward`, and resolving it runs user code.
`get_traced_fn` formats a forward it refuses into its error before raising, and
for a `functools.partial` over the module that repr reaches the user's
`extra_repr`, outside the `(RuntimeError, AttributeError)` the helper catches.
Dispatch calls `result.fn(self.model, ...)` and never the instance's `forward`,
so a rebind after the load reaches only the report, and on a SUPPLIED result the
report does resolve it, so that resolve is wrapped: any exception it raises
degrades the wording to the scope-neutral one rather than replacing the report
with itself. The gate narrows the window; the catch closes it.

The printed name is `this <Type> instance's forward`, the attribute the load
resolved the scope from, and not the class's `<Type>.forward`: the two are one
lookup until an instance rebinds `forward`, after which the guards read that
other function object's globals, so naming the class attribute would need a
second clause hedging for the rebind, one that points at a dict where defining
the name does not restore dispatch:

```python
m = ModeBranchGlobalModule()
m.forward = types.MethodType(forward_from_other_module, m)   # a function whose globals are elsewhere
loaded = AOTCompiledModel.deserialize(m, data)               # scope resolved from m.forward: vars(other_module)
loaded(x, 1)
# For [1]: ... the globals of the function this ModeBranchGlobalModule instance's forward resolves to ...
other_module.AOT_BRANCH_SCALE = 3.0    # defining it HERE restores dispatch: the guards hold this dict by reference
mypkg.model.AOT_BRANCH_SCALE = 3.0     # defining it beside the class does not
```

Defining the absent name in that dict is what restores dispatch, since the
guards hold the dict by reference, so a name defined after the load resolves,
while the graph goes on reading the value serialized at capture, because the
bytecode globals are built once at load and a live value is substituted only
for a name the scope had then.
`test_no_match_message_hint_covers_a_rebound_forward` asserts both ways round
for a rebind over foreign globals.

Sharing the one helper is what keeps the two paths saying the same thing about
the same scope; it now returns a bare sentence, and each caller adds its own
lead-in: the function path, which continues a line of its own, adds ` -- `, and
the report prefixes `For [i]: ` with the index of the entry the hint is about,
so the line is self-locating rather than an unindented fragment between the
entries and the footer. The hint is read off the entry that failed on the
missing global; every entry on a model shares that scope today, since
`deserialize` hands them all one `guard_globals`.

## The advice stays even when every entry named a missing global

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:

```python
class ModeBranchGlobalModule(torch.nn.Module):
    def forward(self, x, mode):
        if mode == 1:
            return x * AOT_BRANCH_SCALE    # only this branch's guards read the global
        return x * 2
# with AOT_BRANCH_SCALE undefined, an input for mode=0 is captured and served fine;
# so "add a ModelInput" is real advice even when every listed entry died on the KeyError
```

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.

## What an entry's line quotes, and two answers that name nothing

An entry's line quotes the guards `check_verbose` named, and two of its answers
name none:

```python
reason = result._live_guard_manager().check_verbose(bound[i])
if reason.result:            # the tree ACCEPTS the call it rejected twice
    "  [i] <guards rejected this call twice and then accepted it here: a guard that does not answer consistently, or a tag-safe fast path that refused without running the tree>"
elif not reason.verbose_code_parts:
    "  [i] <guard check failed without naming a guard>"
else:
    "  [i] " + " ".join("; ".join(reason.verbose_code_parts).splitlines())
```

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, and
reading an empty list as "passed" would serve that call a graph compiled for a
set of another size, so `GuardDebugInfo.result` is what decides. The other is a
tree that ACCEPTS the call: both dispatch passes rejected it and
`check_verbose`, which never takes the dict-tag fast path, accepts it, so either
a guard here does not answer consistently between evaluations or a still-armed
tag-safe root neither rejection reached refused from its own fast path. Neither
is a match to serve, and quoting the guards it just passed as a reason the call
failed would name the wrong thing. `GuardDebugInfo.user_stack` is dropped on
purpose: the verbose part usually embeds `# <source> # file:line in forward`
already, it is `None` for the `KeyError on G[...]` case this report exists to
explain, and one line per input is the point.

That one line per input is a format read back with `splitlines()`, by a
reader's eye and by the test, 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 `
` sitting in a comment on that line arrives in the part
intact:

```python
def forward(self, x):
    return x * 2  # page break \x0c rec sep \x1e
# .replace("\n", " ") left both separators in, and a one-entry report printed as four lines,
# three of them fragments of a single guard; " ".join(part.splitlines()) collapses exactly the
# set the format is read back on
```

## Built from the dispatch's own binding and the dispatch's own list

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
the commit below 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 expects one; the
fall-through fails that with `Absolute difference: 2`, and the commit below's
dispatch binding per result fails it with `Absolute difference: 3`. 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 against the dispatch before these two commits, 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 the commit below's
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 mid-call and asserts the report
counts one input, with the second the next call's to judge.

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. The rebound load is pinned
here, since the sentence is this commit's and showing that it names the right
dict takes a load whose resolved scope is not the class's module: an un-rebound
load prints the identical hint line, and defining the name beside the class
definition serves it, so nothing there tells the instance attribute from the
class's. 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.

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_report_keeps_an_entry_on_one_line_past_odd_separators
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_message_when_a_guard_answers_inconsistently
python test/dynamo/test_aot_compile.py -k test_no_match_message_advises_an_input_for_a_missing_global
python test/dynamo/test_aot_compile.py -k test_no_match_message_hint_covers_a_rebound_forward
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_report_resolves_forward_only_for_a_supplied_scope
python test/dynamo/test_aot_compile.py -k test_no_match_report_survives_a_forward_resolve_that_raises
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_no_match_message_when_a_failure_names_no_guard
python test/dynamo/test_aot_compile.py -k test_missing_key_inside_a_present_global_is_not_a_missing_global
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
```

Every test above fails at the previous commit: each asserts on report text
(`No AOT compiled graph matched this call`, `[0] ...`, `Add a ModelInput`) that
the fall-through's `GuardManager check failed` message does not carry, and the
binding test's no-match half counts 3 binds there.

`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: reporting
an entry as `str(GuardDebugInfo)` instead of the joined one-line reason makes
line 2 read `result=...` and fails it, while an advice line a later commit
appends does not.

`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. Restoring
`.replace("\n", " ")` fails it with `Expected 3 but got 6`, and adding only the
form feed to that replace is red as well, with `Expected 3 but got 5`.

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`.

`test_no_match_message_hint_stays_neutral_for_a_supplied_scope` loads through
`AOTCompiledModel.deserialize(..., guard_globals=...)` with a dict that lacks
the guarded name, so the guards hold a dict no `forward` resolves to. Naming
`forward` unconditionally fails it at the assertion on the scope-neutral
wording, with a report that names `this HermeticModule instance's forward`, and
the assertions after it are the point: the guards hold the supplied dict, not
the module dict the class's `forward` owns and `AOT_HERMETIC_WEIGHT` is defined
in, so the call still raises, while defining it in the supplied scope serves
it.

`test_no_match_report_resolves_forward_only_for_a_supplied_scope` captures
in-process, rebinds the instance's `forward` to a `functools.partial` over a
module whose `extra_repr` raises `ValueError`, and asserts the CAPTURED report
still arrives. Resolving the scope unconditionally fails it with that
`ValueError` escaping in place of the report.
`test_no_match_report_survives_a_forward_resolve_that_raises` is the SUPPLIED
half: it loads through `AOTCompiledModel.deserialize(inst, data)` with no
`guard_globals=`, so the report does resolve `forward`, then makes the same
rebind. Removing the `except Exception` around that resolve fails it with the
same `ValueError` -- `get_traced_fn` formats the refused forward into its error
before raising -- and the report it asserts on is worded for `the live scope
this artifact was loaded against`, since the rebound forward resolves to no
dict the guards hold.

Withholding the advice when an entry named a missing global fails both
`test_no_match_message_keeps_the_advice_for_every_entry` and
`test_no_match_message_advises_an_input_for_a_missing_global` on `Add a
ModelInput`; dropping the no-guard branch prints an entry with nothing after
`[0]` and fails `test_no_match_message_when_a_failure_names_no_guard`.

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.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

## FAQ

> **FAQ: Why aren't the tests for every branch this commit adds in this
> commit?** The dispatch this report sits on -- the scan of every result, the
> second `check()` pass and the last-resort loop for a result that opted out --
> is the commit below, and its last-resort stage is pinned by #196824
> (`test_aot_compile_module_disable_guard_check`,
> `test_aot_compile_module_opted_out_result_is_the_last_resort`,
> `test_aot_compile_module_opted_out_result_keeps_its_place_in_the_scan`). Of
> the report's own branches, the supplied-scope hint on an un-rebound load is
> pinned by #196825, which also pins that the "Add a `ModelInput`" advice still
> reaches a report whose only failure is a missing global. What is pinned here,
> by `test_no_match_message_hint_covers_a_rebound_forward`, is that the hint
> names the INSTANCE attribute the load resolved the scope from: for an instance
> that rebound `forward` before the load the guards read another function
> object's globals, and that is where the absent name has to be defined. Showing
> that takes a load whose resolved scope is not the class's module -- an
> un-rebound load prints the identical hint line, and defining the name beside
> the class definition serves it, so nothing there tells the instance attribute
> from the class's. Folding #196825's test lines down here would put two
> unrelated behaviours -- this report and a guarded global the loading process
> does not have -- in one commit, which is the split this re-slice exists to
> make; they land together in any case.

> **FAQ: The closing advice lands directly under the "rejected this call twice
> and then accepted it here" entry, where it reads as a diagnosis of it. Why
> leave it there?**
>
> The line is deliberately the report's footer, not per-entry commentary, and
> that is why it is emitted after the loop rather than inside it. Adding a
> `ModelInput` is a real mitigation for that entry too -- an input captured for
> this call gets a tree that matches it on the first evaluation, so the
> inconsistent entry stops being consulted. Moving the advice above the entries,
> or suppressing it when any entry took that branch, would make the only
> actionable line in the report depend on which branch some unrelated entry hit,
> which is the same masking the paragraph above it argues against. The entry's
> own text already says what happened in its own words, so the reader is not
> being told the footer explains it.

> **FAQ: The review asked that
> `test_no_match_message_hint_stays_neutral_for_a_supplied_scope` read
> `AOT_HERMETIC_WEIGHT` through a reference captured at import instead of
> asserting it is in `HermeticModule.forward.__globals__`. Why identity
> assertions instead?**
>
> The membership assertion was standing in for a claim about which dict the
> guards read, so the test now states that claim directly:
> `compiled.compiled_results[0]._guard_globals is scope` and
> `HermeticModule.forward.__globals__ is globals()` -- the guards hold the
> supplied dict, and the dict a forward-naming hint would have sent the reader
> to is this module's. Neither depends on what a sibling left in the module
> dict. The two bare `AOT_HERMETIC_WEIGHT` reads that follow are pre-existing
> and shared with every test in the file that uses the fixture; a sibling that
> failed to restore the name would break the module, not this test's ordering,
> and a captured alias would only move that dependency to import time.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: #196823
Approved by: https://github.com/pytorchgreenlight
ghstack dependencies: #197049
pytorchmergebot pushed a commit that referenced this pull request Sep 17, 2026
#196825)

**Summary.** Tests only, end to end: a module artifact guards a module-level
global, the loading process does not define it, and the call has to fail loudly
with a report that names the failing input (`[0] KeyError on
G['AOT_HERMETIC_WEIGHT']`) and the scope its guards were rooted at, the globals
of the module where `HermeticModule.forward` is defined. The alternative,
falling back to the serialized scope, would make the guard a no-op checked
against capture-time state, which is the silent failure mode; loud is
recoverable on the serving machine. The test then takes the report's advice and
pins how far that goes at this commit: defining the name resolves the guard and
the call is served, but with the tensor serialized in the artifact rather than
the one just defined, because the bytecode's globals are built once at load and
a live value is substituted only for a name the scope had then. That
`x @ saved` assertion is recorded as the limitation it is, not the intended end
state: #196897, two commits up, makes a loaded module artifact re-read the live
value on every call and flips it to `x @ (saved * 2)`, using this test as its
witness. It is a separate commit because a guarded global the loading process
lacks is a failure mode of its own, independent of where an opted-out result
sits in dispatch and of what the report says when a tree raised.

## The scenario

```python
# capture process: HermeticModule.forward reads the module-level AOT_HERMETIC_WEIGHT
model = torch.compile(HermeticModule(), fullgraph=True, backend="eager",
                      options={"guard_filter_fn": keep_global_guards})
model._aot_compile([ModelInput(args=(x,), kwargs={}, contexts=[])])
data = model._save_aot_compiled_module()

# loading process: the global is absent
torch._dynamo.reset()
saved = globals().pop("AOT_HERMETIC_WEIGHT")
reloaded = torch.compile(HermeticModule(), fullgraph=True, backend="eager")   # no guard_filter_fn: inert on a load
reloaded._load_aot_compiled_module(data)                                       # a module load takes no f_globals=
reloaded(x)
# RuntimeError: No AOT compiled graph matched this call. Tried 1 compiled input(s):
#   [0] KeyError on G['AOT_HERMETIC_WEIGHT']
# For [0]: a guarded global is missing from the globals of the function this HermeticModule instance's
#          forward resolves to, since that is the one the load resolved, here vars(test_aot_compile); ...
# Add a ModelInput covering this call, or check whether guard_filter_fn kept a guard ...
```

The reloading wrapper takes no `guard_filter_fn`: the load installs the
artifact's own guards and captures nothing, so the loading process's filter has
no say in what a loaded artifact checks. The sibling
`test_aot_compile_module_reload_reads_the_live_global` does pass a filter on
its reload, where it is equally inert.

## Taking the advice, and what the recovery arm pins

```python
globals()["AOT_HERMETIC_WEIGHT"] = saved * 2      # define it in the named scope, with a DIFFERENT value
reloaded(x) == x @ saved                          # served -- but with the tensor serialized in the artifact
```

The guards read the live scope by reference, so the new binding passes the kept
`TENSOR_MATCH`, which checks metadata and not values. The bytecode's globals
were built once, at load, and substitute a live value only for a name the scope
has then, so the value serialized with the artifact was never overwritten.
Binding `saved * 2` and asserting `x @ saved` is what pins that, and it is what
makes the recovery assertion say which dict the dispatch READ rather than only
that it stopped raising: asserting `x @ (saved * 2)` instead fails
(`Tensor-likes are not close! Mismatched elements: 9 / 9`), and rooting the
guards at a copy of the live scope rather than the dict itself is caught first
by the hint assertion (the report drops the forward clause when the resolved
dict is not the one the guards hold), with the recovery arm as the second line
of defence.

That `x @ saved` value is the parent's load-time snapshot, recorded here as the
limitation it is and not as the intended end state: #196897, two commits up
this stack, makes a loaded module artifact re-read the live value on every call
and flips this very assertion to `x @ (saved * 2)`, using this test as the
witness that its recorded name set is not intersected with the scope at load.
The pin stays in this commit so that flip lands as a measured behaviour change
rather than a silent one; the test comment says the same in one sentence,
without the PR number, so it reads correctly both before and after that commit.
Binding `saved` instead, which would make the arm invariant under #196897, was
considered and declined: it would leave this test unable to tell the live dict
from the serialized copy, and #196897 would have to re-add `saved * 2` to use
it as a witness.

## Both lines of the report, and which sibling pins what

The report is also asserted to carry the generic mismatch advice next to the
hint: a missing global counts as the mismatch it is, because the report cannot
tell whether a new `ModelInput` would read the absent global (one captured for
a branch that does not read it is served with the name still undefined), so
both lines are emitted, and for `HermeticModule`, which reads the global on its
only path, the hint is the actionable half.

The forward clause the test asserts is emitted when the scope `model.forward`
resolves to is the dict the guards hold (`resolved is not None and resolved is
missing_global._guard_globals`), which is the case for a load that passed no
`guard_globals=`, resolved forward, and is not rebound after the load:

```
this test (un-rebound load)                       -> clause present, "here vars(test_aot_compile)" suffix
..._hint_covers_a_rebound_forward (rebinds BEFORE loading) -> clause present, no suffix (foreign dict)
..._survives_a_forward_resolve_that_raises (rebinds AFTER)  -> clause absent
```

What tells this test from the rebound sibling is the recovery arm: defining the
name in `globals()` serves the call here, where the same binding in that
sibling still raises.

## Why its own test, and the fixture

Most of the load-bearing assertions are on #196823's no-match report and its
forward-naming hint, and the recovery assertion is on #196818's live-scope
rooting, so this could equally have been folded into #196823; it stays separate
because a guarded global the loading process does not have is a failure mode of
its own, and each of those gets the commit that pins it. The fixture is the
same `HermeticModule` and module-level weight
`test_aot_compile_module_reload_reads_the_live_global` uses, the test for the
opposite direction, rather than a second copy that differed only in an
unchecked scale factor. Like that sibling it hides the module dict's leaked
generated globals through the shared helper before capturing, since the scope
resolved from `model.forward` is this module's dict and the capture leaks
Dynamo's generated names into it. The load seeds nothing here, for the reason
that sibling's comment gives: the only kept global guard is rooted at
`AOT_HERMETIC_WEIGHT`, not at an import alias or the builtins-dict key.

No behaviour change vs the parent: the diff is one 66-line test, nothing under
torch/ moves.

Test Plan:

```
python test/dynamo/test_aot_compile.py -k test_aot_compile_module_absent_global_fails_guard
```

Run in one process with the tests that share the fixture and the report, which
unittest orders after this one, to show they still pass with it running first
(5 tests, OK):

```
python test/dynamo/test_aot_compile.py -k test_aot_compile_module_absent_global_fails_guard -k test_aot_compile_module_reload_reads_the_live_global -k test_missing_key_inside_a_present_global_is_not_a_missing_global -k test_no_match_message_keeps_the_advice_for_every_entry -k test_no_match_message_hint_covers_a_rebound_forward
```

The whole file was run at this commit:

```
python test/dynamo/test_aot_compile.py
```

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>

## FAQ

> FAQ: why not rename `AOT_HERMETIC_WEIGHT`/`HermeticModule` to something that
> says what the fixture is for? The fixture is not this commit's: `git log -S`
> puts `class HermeticModule` and the module-level `AOT_HERMETIC_WEIGHT` in
> #196820, which introduces them along with its test that a reloaded module
> artifact reads the live global. #196825 reuses them rather than adding a
> near-duplicate module and weight. A rename therefore has to rewrite the fixture
> definition in #196820 together with every test body that uses it, which by this
> commit is spread across several of the stack's commits, in a stack whose whole
> point is one reviewable behaviour per commit -- for a naming preference, with no
> change in what is covered. The name is a poor one and #196820 says so: what
> these tests pin is that a load reads the LIVE global rather than a sealed
> capture-time copy, which is the opposite of hermetic. The rename is a mechanical
> follow-up once the stack lands, touching the definition and every commit's uses
> together.

> **FAQ: the test pops `AOT_HERMETIC_WEIGHT` after `_hide_leaked_dynamo_globals()`,
> and that order is what keeps cleanup from deleting the module-level fixture --
> why is the dependency not spelled out here?** It is real: the helper snapshots
> `preexisting = frozenset(g)` over `g = globals()` and its cleanup deletes every
> name not in that snapshot, so a pop moved above the helper drops the name from
> the snapshot and the cleanup deletes the module-level global for the rest of the
> process. Measured by mutation -- with the helper call moved below the pop (after
> the capture) this test still passes and the next test that reads the fixture dies
> with `NameError: name 'AOT_HERMETIC_WEIGHT' is not defined` at its `x @
> AOT_HERMETIC_WEIGHT`. The note is not added at this call site because the
> dependency is a property of the shared helper, not of this test: six tests pop a
> global around it, five of them in earlier commits of this stack (#196816,
> #196823, #196824), and a note on one call site documents the helper's contract in
> the one place that does not own it while leaving the other five bare. It belongs
> in `_hide_leaked_dynamo_globals`'s own comment, which already explains the
> snapshot-and-restore and reaches all six call sites at once; that is a one-commit
> change to the commit that introduces the helper, not to this test-only commit.

> **FAQ: why does this test not also assert `Tried 1 compiled input(s)` alongside
> `No AOT compiled graph matched`?** Because the tried-count line is the report's
> shape, which is pinned where the report is introduced: that commit asserts `Tried
> 2 compiled input(s)` together with the `[0]`/`[1]` entries and their line
> positions, and pins the exact line count for a one-input report in its
> odd-separators test. This test pins a different thing -- that a guarded global
> the loading process lacks fails the guard and is reported as `[0] KeyError on
> G['AOT_HERMETIC_WEIGHT']` -- and its `[0] ...` assertion already fails if the
> entry for the single compiled input stops being emitted. Re-asserting the count
> here would add a second place to update when the report's wording changes, for
> coverage the report's own test already has.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull Request resolved: #196825
Approved by: https://github.com/pytorchgreenlight
ghstack dependencies: #197049, #196823, #197149, #197048
pytorchmergebot pushed a commit that referenced this pull request Sep 19, 2026
…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
@github-actions
github-actions Bot deleted the gh/bobrenjc93/1173/head branch November 20, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants