Repository navigation
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - Ready for human review:
Findings (15): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/203284
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 Pending, 1 Unclassified FailureAs of commit 63042d5 with merge base 836c141 ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 464193091 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 464255156 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 464330524 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 464475902 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 469352089 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 469380747 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 469402204 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
Withdrawn: the automated review of 46bee2c found nothing blocking.
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 469402204 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 469402204 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 469402204 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 476467819 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
There was a problem hiding this comment.
Automated review of 79b6e11: nothing blocking; ready for human review.
The PR stops Inductor's compile-time TunableOp "tune" and "reuse" passes from silently doing nothing. It adds a caching warning, a routing breaker, inline-fallback tuning gates, and C++ borrow-validation fallback and logging changes, and it turns pipelined autotuning off while a mode is set. Recommendation: Approve. Every point is non-blocking, but before landing the review asks to fix the config.py comment, the title and the description, and to add ciflow/trunk.
⚪ 15 non-blocking findings
pytorch/torch/_inductor/config.py
Line 3124 in 79b6e11
Non-blocking: the title, the first two description bullets and the "routes_to_worker mirrors the gate" paragraph describe an FxGraphCache/AOTAutogradCache bypass, an autotune local-cache bypass and a routes_to_worker helper. None of these exist at HEAD: routes_to_worker is not defined anywhere, and codecache.py, compile_fx.py and torch/_functorch never mention tunableop. This comment ("a graph that routes a CUDA GEMM skips the FX and autotune caches while a mode is set") says the same thing and contradicts the _warn_if_caching_enabled docstring ("the caches are left alone deliberately"). Only the pipelined-autotuning clause is accurate. The description becomes the commit message, yet it leaves out what the PR actually adds: the routing breaker, the metas/VERIFY inline gates, rejecting bool results in submit(), and the C++ change. Fix the comment, the title and the description before landing.
Non-blocking: this C++ behaviour change is undocumented. A failed borrow validation now returns Default where it used to return the wildcard fallback. Direct users of _nearest_match_enable(True) see the change, and the description doesn't mention it. The new comment "a donor that was not measured is never served" also doesn't hold for the worker's measured call, which still dispatches the unvalidated wildcard through the tail.
Line 12174 in 79b6e11
Non-blocking: with the current labels, CI runs neither the new C++ FakeOp tests (cuda_tunable_nearest_test.cpp, reached only through test_aten) nor the new TestLinalgCudaOnly tests. ciflow/inductor and ciflow/torchtitan don't run them either. Adding ciflow/trunk would run both on CUDA and ROCm. Without it, nothing shows that the dropped #ifdef and the new TORCH_CUDA_CPP_API exports link and pass on either GPU build. ciflow/inductor also runs the changed test/inductor/test_tunableop_*.py files on CUDA only, although hipBLASLt is the main target of the routing work. Add ciflow/trunk before landing.
Line 12174 in 79b6e11
Non-blocking: test_unusable_donor_is_never_benchmarked_tunableop only asserts that two strings are absent, so it still passes if the child never reaches the borrow path. The child already runs at VERBOSE=3, so add a positive check on the LOG3 nearest match for ... -> line.
Non-blocking leftovers: _gemm_gm (:936) is never called. @ instantiate_parametrized_tests on TunableOpPretuneRealGpuTest (:1009) does nothing, because the class has no @ parametrize. tunableop._env_warned.clear() at :978 and :996 has no cleanup, so caching:* entries leak into later tests. Use self.addCleanup(tunableop._env_warned.clear), as test_tunableop_worker.py:669 does.
Non-blocking: the test name claims more than the test checks. test_the_caching_warning_is_emitted_once_per_mode only patches mode "tune". It would still pass if the memo key at tunableop.py:131 dropped the mode, which would let a tune warning silence the reuse warning. Exercise both modes in one process.
Line 12237 in 79b6e11
Non-blocking: the env.pop("PYTHONPATH") / env.pop("PYTHONHOME") additions copy an existing pattern, but the reasoning is backwards. The child is the same sys.executable, and the parent imported torch with that same PYTHONPATH. Removing it breaks setups where torch is importable only through PYTHONPATH, and check=True then raises.
pytorch/torch/_inductor/tunableop.py
Line 698 in 79b6e11
Non-blocking: the routing breaker's scope and accounting don't match their comments. Scope: this warning says routing is off "for the rest of this compile". The breaker is reset only by a routed success or by clear_caches()/fresh_cache(), and no routed success can happen once it trips. So in-process it stays tripped for the rest of the process, while compile_fx_subproc resets it every compile. Accounting: note_routing_outcome counts every non-ok status, including submit() "error" returns that never kill the worker (:571-576, :620-622, :626-635). That contradicts "each fault costs a forced worker kill" at :659-660. Fix: reset the breaker per compile or reword the warning, and count only faults that killed the worker.
pytorch/torch/_inductor/tunableop.py
Line 119 in 79b6e11
Non-blocking: the caching warning can't fire on the run it exists for. _warn_if_caching_enabled is reached only through is_tune_mode/is_reuse_mode, during lowering or autotuning. An AOTAutogradCache hit, or by default an FxGraphCache hit, never lowers, so a tune pass over a fully warm cache records nothing and logs nothing. The exception is pipeline_max_autotune_gemm=1, where compile_fx.py:1144 runs it before the FxGraphCache lookup. Check once at compile entry, before the AOTAutograd cache lookup, whenever a mode is set.
pytorch/torch/_inductor/tunableop.py
Line 129 in 79b6e11
Non-blocking: the caching warning checks too little and is worded for tune only. :129-130 checks only force_disable_caches, so a user who turned off the FX, AOTAutograd and autotune caches one by one is still told to set TORCHINDUCTOR_FORCE_DISABLE_CACHES=1. The shared message at :134-138 says "for a tuning run" even when it fires from reuse mode.
pytorch/torch/_inductor/select_algorithm.py
Line 3973 in 79b6e11
Non-blocking: the ExternKernelCaller.benchmark docstring overstates what the fast path does. It says "every other path times inline with tuning off", but the first early return (:3997-4002: mode off, non-CUDA output, or a non-GEMM choice) calls _benchmark_inline without touching the tuning flags. Only the routable-GEMM fallback (:4051-4060) turns tuning off.
pytorch/aten/src/ATen/cuda/tunable/README.md
Line 135 in 79b6e11
Non-blocking: the docs list only one cache. This section gives only an autotune-cache hit as the reason reuse does nothing. It leaves out FxGraphCache and AOTAutogradCache hits, which skip lowering entirely, and it doesn't give the force-disable advice the warning gives. config.py:3128-3130 and the is_reuse_mode docstring (tunableop.py:155-157) leave out the same two caches.
Non-blocking stale comment: cuda_tunable_nearest_test.cpp:41-45 still says the friend operator<< "is not exported and the test fails to link". Tunable.h:50 now exports it, and lines 168-172 of the test file say so. Update the test comment.
Non-blocking: the comment at :237-247 is wrong. It says that without the override, the unusable-donor test "passes for the wrong reason". In fact AnUnregisteredDonorIsNeverBenchmarked takes the same !RegisterOpForResult early return either way, so it can't detect a broken override. The GetOp(...) != nullptr check at TunableOp.h:204 never decides anything on CUDA.
Non-blocking: the comment is wrong and the assertion is weak. :301-302 says a trusted-borrow mutant would call "neither candidate", but operator() still dispatches the donor once, so EXPECT_GT(op.donor_op()->calls(), 0) at :318 passes in that mutant. Fix the comment, or tighten the check to > 1 as the test at :377 already does.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 477482144 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 477482144 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
… work Pull Request resolved: #203284 Inductor caches a compile at three levels, and all three can skip the work the "tune" and "reuse" passes exist to do. Tuning and borrow validation happen inside benchmark(), so a cache hit does neither and the pass silently records nothing. - FxGraphCache and AOTAutogradCache: bypassed while a mode is set, but only for a graph that actually routes a CUDA GEMM. Bypassing on the mode alone recompiles CPU-only and GEMM-free graphs every time for no benefit. - The local autotune cache: neither read nor written for a routed GEMM. An empty cache rather than an early return, so the missing-choices assertion still runs and the precompile lookup misses too -- otherwise its choices are skipped and then compiled one at a time. Not written either: the timing is of a tuned kernel a plain run would not get, and update_local_cache rewrites the whole file, so a partial dict would discard the machine's cache. - Pipelined autotuning: turned off, because that path benchmarks the bmreq directly and never reaches ExternKernelCaller.benchmark where routing lives. Routing into that pool is not an option -- TunableOp's flags are process-global and the pool is shared. routes_to_worker mirrors the gate in ExternKernelCaller.benchmark, device included: a CPU extern candidate is timed inline and keeps its cache entry. Also folds in the non-OK logging previously sent separately: a tuned solution that fails at runtime returns non-OK and every caller falls back silently, so the failing candidate is never named. ghstack-source-id: 486905202 @exported-using-ghexport Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
…e the pass Pull Request resolved: #203284 Follow-up fixes for the compile-time TunableOp stack. Each of the four PRs below is at GitHub's limit on lines added per PR, so fixes found later sit in this diff on top. Some of them fix code those diffs own; they are listed by owner at the end. An earlier version bypassed FxGraphCache, AOTAutogradCache and the local autotune cache. That was replaced by a warning (item 1), and this summary now describes the code as it is. Suggested review order: 1. Caches and pipelining (tunableop.py, autotune_process.py, config.py). Both passes work during lowering and autotune, so a cache hit skips them. The caches are not bypassed, because suppressing them costs every graph the entry that standalone_compile and precompile build their artifact from. Instead, `_warn_if_caching_enabled` warns once per mode unless `force_disable_caches` is set. For aot_compile and precompile, which reject that flag, it suggests a fresh `TORCHINDUCTOR_CACHE_DIR`. Known gap: the warning is emitted from lowering/autotune, so a run where every graph is a cache hit gets no warning. Pipelined autotuning is turned off while a mode is set: that path benchmarks the bmreq directly and never reaches the routing. 2. Routing hardening in `ExternKernelCaller.benchmark` (select_algorithm.py, tunableop.py). Once a mode is set and the candidate is a GEMM TunableOp tunes, every exit that times inline does so with tuning off, not only the post-fault one. Three gates keep candidates the worker cannot benchmark out of it: a circuit breaker (`routing_is_open`, after 3 consecutive faults), metas that failed to build (`output_tensor_meta`), and `VERIFY`. The breaker is one process-wide counter shared by every device's worker and resets only on a fresh cache, so with default caching it lasts for the rest of the process. `submit()` also treats a bool result as a fault, since bool is an int and True would pass as a 1 ms timing. 3. Behaviour change in borrow validation (TunableOp.h). When validating a borrow throws `c10::Error`, `ResolveWithoutExactHit` used to return the wildcard (or Null). It now reports the shape untuned and returns Default, the same answer as the no-donor and stream-capture exits. `AcceleratorError` and `OutOfMemoryError` are reported untuned and rethrown, so the worker is torn down. This changes code added in D116493590. 4. Non-OK logging (TunableOp.h). A tuned solution that fails at runtime returns non-OK and every caller falls back silently; the failing solution is now named at `TUNABLE_LOG2`. Previously reviewed as D128384389. 5. Linking. `StreamTimer`, `StreamTimerNoSync` and `ResultEntry`'s `operator<<` are exported with `TORCH_CUDA_CPP_API`, which the TunableOp.h templates need to link from the new gtests outside libtorch_cuda. Fixes to earlier diffs in the stack: - D116493593: `FlagGuard` in cuda_tunable_nearest_test.cpp snapshotted `IsNearestMatchEnabled()`, which folds in recording, so its restore could clear the raw setting. The kill-switch test in test_linalg.py now also checks the pristine defaults. - D116493592: `_warn_fault_once` attached `exc_info` even outside an except block. - D116493595: the rotating-buffer restore in test cleanup (the getter returns bytes, the setter takes MiB) and the `_Job.measure` test stub. - D116493590: the `ResolveWithoutExactHit` exits in item 3 and the `ExternKernelCaller.benchmark` inline fallback in item 2. Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/) ghstack-source-id: 487448143
…e the pass Pull Request resolved: #203284 Follow-up fixes for the compile-time TunableOp stack. Each of the four PRs below is at GitHub's limit on lines added per PR, so fixes found later sit in this diff on top. Some of them fix code those diffs own; they are listed by owner at the end. An earlier version bypassed FxGraphCache, AOTAutogradCache and the local autotune cache. That was replaced by a warning (item 1), and this summary now describes the code as it is. Suggested review order: 1. Caches and pipelining (tunableop.py, autotune_process.py, config.py). Both passes work during lowering and autotune, so a cache hit skips them. The caches are not bypassed, because suppressing them costs every graph the entry that standalone_compile and precompile build their artifact from. Instead, `_warn_if_caching_enabled` warns once per mode unless `force_disable_caches` is set. For aot_compile and precompile, which reject that flag, it suggests a fresh `TORCHINDUCTOR_CACHE_DIR`. Known gap: the warning is emitted from lowering/autotune, so a run where every graph is a cache hit gets no warning. Pipelined autotuning is turned off while a mode is set: that path benchmarks the bmreq directly and never reaches the routing. 2. Routing hardening in `ExternKernelCaller.benchmark` (select_algorithm.py, tunableop.py). Once a mode is set and the candidate is a GEMM TunableOp tunes, every exit that times inline does so with tuning off, not only the post-fault one. Three gates keep candidates the worker cannot benchmark out of it: a circuit breaker (`routing_is_open`, after 3 consecutive faults), metas that failed to build (`output_tensor_meta`), and `VERIFY`. The breaker is one process-wide counter shared by every device's worker and resets only on a fresh cache, so with default caching it lasts for the rest of the process. `submit()` also treats a bool result as a fault, since bool is an int and True would pass as a 1 ms timing. 3. Behaviour change in borrow validation (TunableOp.h). When validating a borrow throws `c10::Error`, `ResolveWithoutExactHit` used to return the wildcard (or Null). It now reports the shape untuned and returns Default, the same answer as the no-donor and stream-capture exits. `AcceleratorError` and `OutOfMemoryError` are reported untuned and rethrown, so the worker is torn down. This changes code added in D116493590. 4. Non-OK logging (TunableOp.h). A tuned solution that fails at runtime returns non-OK and every caller falls back silently; the failing solution is now named at `TUNABLE_LOG2`. Previously reviewed as D128384389. 5. Linking. `StreamTimer`, `StreamTimerNoSync` and `ResultEntry`'s `operator<<` are exported with `TORCH_CUDA_CPP_API`, which the TunableOp.h templates need to link from the new gtests outside libtorch_cuda. Fixes to earlier diffs in the stack: - D116493593: `FlagGuard` in cuda_tunable_nearest_test.cpp snapshotted `IsNearestMatchEnabled()`, which folds in recording, so its restore could clear the raw setting. The kill-switch test in test_linalg.py now also checks the pristine defaults. - D116493592: `_warn_fault_once` attached `exc_info` even outside an except block. - D116493595: the rotating-buffer restore in test cleanup (the getter returns bytes, the setter takes MiB) and the `_Job.measure` test stub. - D116493590: the `ResolveWithoutExactHit` exits in item 3 and the `ExternKernelCaller.benchmark` inline fallback in item 2. ghstack-source-id: 487448143 Differential Revision: [D129441755](https://our.internmc.facebook.com/intern/diff/D129441755/)
Stack from ghstack (oldest at bottom):
Follow-up fixes for the compile-time TunableOp stack. Each of the four PRs
below is at GitHub's limit on lines added per PR, so fixes found later sit in
this diff on top. Some of them fix code those diffs own; they are listed by
owner at the end.
An earlier version bypassed FxGraphCache, AOTAutogradCache and the local
autotune cache. That was replaced by a warning (item 1), and this summary now
describes the code as it is.
Suggested review order:
Caches and pipelining (tunableop.py, autotune_process.py, config.py).
Both passes work during lowering and autotune, so a cache hit skips them. The
caches are not bypassed, because suppressing them costs every graph the entry
that standalone_compile and precompile build their artifact from. Instead,
_warn_if_caching_enabledwarns once per mode unlessforce_disable_cachesis set. For aot_compile and precompile, which reject that flag, it suggests a
fresh
TORCHINDUCTOR_CACHE_DIR. Known gap: the warning is emitted fromlowering/autotune, so a run where every graph is a cache hit gets no warning.
Pipelined autotuning is turned off while a mode is set: that path benchmarks
the bmreq directly and never reaches the routing.
Routing hardening in
ExternKernelCaller.benchmark(select_algorithm.py,tunableop.py). Once a mode is set and the candidate is a GEMM TunableOp tunes,
every exit that times inline does so with tuning off, not only the
post-fault one. Three gates keep candidates the worker cannot benchmark out
of it: a circuit breaker (
routing_is_open, after 3 consecutive faults),metas that failed to build (
output_tensor_meta), andVERIFY. The breakeris one process-wide counter shared by every device's worker and resets only
on a fresh cache, so with default caching it lasts for the rest of the
process.
submit()also treats a bool result as a fault, since bool is anint and True would pass as a 1 ms timing.
Behaviour change in borrow validation (TunableOp.h). When validating a
borrow throws
c10::Error,ResolveWithoutExactHitused to return thewildcard (or Null). It now reports the shape untuned and returns Default,
the same answer as the no-donor and stream-capture exits.
AcceleratorErrorandOutOfMemoryErrorare reported untuned andrethrown, so the worker is torn down. This changes code added in
D116493590.
Non-OK logging (TunableOp.h). A tuned solution that fails at runtime
returns non-OK and every caller falls back silently; the failing solution is
now named at
TUNABLE_LOG2. Previously reviewed as D128384389.Linking.
StreamTimer,StreamTimerNoSyncandResultEntry'soperator<<are exported withTORCH_CUDA_CPP_API, which the TunableOp.htemplates need to link from the new gtests outside libtorch_cuda.
Fixes to earlier diffs in the stack:
FlagGuardin cuda_tunable_nearest_test.cpp snapshottedIsNearestMatchEnabled(), which folds in recording, so its restore couldclear the raw setting. The kill-switch test in test_linalg.py now also
checks the pristine defaults.
_warn_fault_onceattachedexc_infoeven outside an exceptblock.
bytes, the setter takes MiB) and the
_Job.measuretest stub.ResolveWithoutExactHitexits in item 3 and theExternKernelCaller.benchmarkinline fallback in item 2.Differential Revision: D129441755
Differential Revision: D129441755