Repository navigation
[aot_compile] Honour disable_guard_check() from any position in module dispatch - #197047
bobrenjc93 wants to merge 5 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/197047
Note: Links to docs will display an error until the docs builds have been completed. ⏳ 2 Pending, 2 Unrelated FailuresAs of commit 3b93289 with merge base b8bd7cf ( GREEN LIGHT - PR approved to be merged without human review:
reason: 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. |
|
Claude finished @bobrenjc93's task in 6m 56s —— View job Review of #197047Mechanically the change is correct, minimal, and consistent with the surrounding dispatch stages — the ordering claim in the description holds against the existing Full reviewWhat I checked
I could not run the tests: this checkout has no built CorrectnessThe new stage at
The second-half row above is the one that would have been easy to break, and it survives only because the new loop iterates in index order — same tie-break the fall-through had. Worth keeping in mind if anyone ever "simplifies" it to One pleasant side effect the code does not say out loud: the fall-through at
Design: is "serve" the right answer, and is model-wide the right scope?The description makes a solid case that raising would leave
That defect is about which result reports, not about what gets served. It can be fixed by making the fall-through raise from the first enabled result instead of from # All guards failed; report from the first result that asked to be checked.
report = next((r for r in results if r._guard_check_enabled), results[0])
return report(self.model, *args, **kwargs)That is position-independent in exactly the sense #196929 complains about, and it does not widen the set of calls that get served. The tradeoff, which the description is right about, is that it would refuse the The scope question is the part I would want a second opinion on before this lands. After this PR, Test
Two gaps:
Nits
VerdictNo correctness bug found; the stage is well placed and the existing tests genuinely pin the ordering. I would like the description to name the "raise from the first enabled result" alternative rather than presenting raise-vs-serve as exhaustive, the public doc to note the model-wide scope, and the new test to add the |
[ghstack-poisoned]
|
Claude finished @bobrenjc93's task in 6m 21s —— View job Review of #197047The diff does not contain the change this PR describes. Against the stated base Full reviewWhat the diff actually isNo How this happenedTwo commits, the second a merge:
That base update adds a byte-identical opt-out loop and a byte-identical The merge HEAD's tree is bit-identical to the pre-merge commit, i.e. everything the base update contributed to these files was discarded in favour of the head side. For the loop and the test that is harmless (both sides were identical). For the docs it is a straight revert of the base's work. The consequence I'd actually fixThe base added, and this PR removes, 17 lines of -(aot-compile-developer-notes)=
-
-## Developer notes
-
-**Private, unstable -- may change or disappear without notice.** A module can
-also be compiled for several calls at once: ...and reverts the bullet that pointed at it back to the unqualified wording (now That reintroduces a statement this very stack establishes as wrong for the module path — dispatch does evaluate an opted-out result's guards ( If the doc revert is intentional — e.g. the "Developer notes" section is meant to live in a different stack entry — the description should say so, because as written it claims the docs are untouched. The docstring restorationThe other half of the diff re-adds the Claims in the description that no longer hold
The measured table and the FAQ are still a good record of why the loop is shaped this way — they just belong on whichever PR actually introduces it. On the code itselfSince the description asks for review of the loop, for what it is worth I read it as it stands at Verification I could not doI could not run the test plan. This checkout has no built extension ( Also outstandingDr. CI still wants a VerdictI'd hold this one. The diff as it stands is not the change described, and its one substantive effect on the base is a documentation regression. Either rebase so the loop and test are genuinely new here and the docs survive the merge, or — if the sibling below now owns that change — retarget this PR to whatever is actually left (the docstring), and say so in the description. |
[ghstack-poisoned]
|
Claude finished @bobrenjc93's task in 7m 12s —— View job Review of #197047The diff is now the change the description says it is — the base moved from Full reviewBase moved; the previous objection is goneThe base's dispatch ends at the re-check and falls straight through to The new stage
Neither surviving opt-out test flips, and for the right reason — both are rescued by the re-check, which still runs first:
Both would go red if the stage were hoisted ahead of the re-check (they'd get One thing the code does not say out loud: the fall-through at Test coverage gap
Two things I'd add:
Public doc is now inaccurate for the module path
Both halves are false on the module path after this PR: dispatch does evaluate an opted-out result's guards ( On the scope question (repeating myself briefly, not blocking)After this PR, report = next((r for r in results if r._guard_check_enabled), results[0])
return report(self.model, *args, **kwargs)That is position-independent in exactly the sense #196929 complains about (it fixes which result reports) without widening what gets served, and the FAQ's "the flag becomes inert" argument does not apply to it. Its real cost is the one the description identifies: it would refuse the Nits
Verification I could not doI could not run the test plan. This checkout has no built extension ( VerdictThe blocking objection from my previous review no longer applies — the diff, the description, and the base now agree, and the stage is correctly placed. Remaining asks are all non-blocking: add the |
[ghstack-poisoned]
|
Claude finished @bobrenjc93's task in 9m 1s —— View job Review of #197047The diff is now the change the description says it is (base Full reviewPR Review: #197047SummaryAdds a third dispatch stage to Verified first that my previous blocking objection is gone — the base moved and no longer carries this work: Also correcting an error in my previous review: I claimed this base had dropped Code Quality
Testing
API Design
RecommendationApprove once the four items above are addressed — the comment at Verification I could not doI could not run the test plan: this checkout has no built extension ( |
[ghstack-poisoned]
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 2 checks: inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 2, 2, mt-l-x86iamx-8-64, unstable), inductor / unit-test / inductor-cpu-test / test (inductor_aoti_fallback, 1, 2, mt-l-x86iamx-8-64, unstable) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Stack from ghstack (oldest at bottom):
The parent's
AOTCompiledModel.__call__scans every compiled result for aguard match, re-checks every result, and then falls through into
compiled_results[0]:The last line does not raise by itself.
AOTCompiledFunction.__call__skips itsguards when that one result has
disable_guard_check()set, so what anunmatched call gets still turns on the POSITION of an opt-out:
compiled_results[0].disable_guard_check()makes[0]run any call no resultguards, while the same flag on
compiled_results[1]is inert and the callraises
GuardManager check failed. Measured on a two-inputScaleModule(float32 and float64) called with float16, each result's
fnwrapped to recordwhich one served:
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:
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 makesresult
ithe fallback for any call no compiled input guards, from any index.At the parent only
i == 0had 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->servefor
[enabled, opted_out], and only after every result's guards were checkedtwice and none accepted.
Why serve rather than raise: on the function path
AOTCompiledFunction.__call__short-circuits on the flag and runs the graphwhatever 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 parentserves, 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_outandtest_module_dispatch_rechecks_an_opted_out_result_whose_tree_accepts; movingthis stage ahead of the re-check serves
[0]'sx * 2and fails both withMismatched elements: 9 / 9, and the other twelve stay green.test_module_dispatch_serves_an_opted_out_result_from_any_positionpins theother two orderings in three assertions:
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]istest_module_dispatch_rechecks_before_honouring_an_opt_out.To review
The five-line loop in
torch/_dynamo/aot_compile.pybetween the re-check andthe fall-through, and the fall-through's reworded comment; the one clause
appended to the dispatch paragraph of the
AOTCompiledModeldocstring; the onetest, 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:
The new test fails at the parent with
RuntimeError: GuardManager check failed(the fall-through re-enterscompiled_results[0], whose guard check isenabled) and passes here; the other 13
test_module_dispatch_*tests pass atboth. 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.
Authored with the assistance of Claude Code.
Co-Authored-By: Claude Fable 5.1 [email protected]
🤖 Generated with Claude Code
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98