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 (18): Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201769
Note: Links to docs will display an error until the docs builds have been completed. ❌ 4 Pending, 1 Unclassified FailureAs of commit bbd1c80 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. |
|
|
Pull Request resolved: #201769 Completes the reuse pass. A shape with no tuned entry of its own can borrow the solution of a neighbouring shape, but a borrow is a guess: it was measured for a different size. This decides whether the guess is actually better than the default kernel, and records the answer so the question is never asked again. The decision is made by the code that already makes it. `FindFastest` benchmarks a candidate set and returns the winner, starting from `Default` as the incumbent, and `Default` is registered as candidate 0 for every GEMM op. So checking a borrow is just `FindFastest` with the candidate set narrowed from every solution the backend offers to the single borrowed one. It inherits the screening passes, the timer, the numerics check and the write path that a tuning run already goes through, rather than standing up a second winner-selection mechanism beside it. The winner is persisted either way, including `Default` when the borrow loses or when there is no neighbour to borrow from. The shape then becomes an ordinary exact hit, so neither the nearest search nor this comparison is repeated on a later pass, and execution never has to borrow at all. On the Inductor side, an aten candidate is benchmarked in the TunableOp worker rather than inline. Extern kernels are otherwise benchmarked in the current process on the explicit assumption that they do not crash; hipBLASLt tuning breaks that assumption, and a fault there takes the compile with it. **Warm, then measure.** The first call to a GEMM in the worker is where TunableOp does its compile-time-only work -- the full solution search in tune mode, the nearest-match scan and borrow validation in reuse mode. Benchmarking straight away folds that work into the average and reports it as the kernel's cost, which is wrong twice over: serving never repeats it, and the inflated number loses the autotune race to a slower triton template that was measured honestly. So the job now pays that cost in a discarded call, then measures with tuning off, which is exactly the configuration serving runs. That bug was worth roughly the whole regression it caused. On one model an addmm of 3072x1894x242432 went from a 3.5 ms aten candidate to over 7.45 ms, lost to a 4.71 ms triton kernel, and never appeared in the autotune ranking at all -- while the solution TunableOp had just recorded for that shape ran in 2.9 ms. Measured end to end, that model went from -56% against baseline to +1.4%. **A reply is not a measurement.** `submit()` previously reported any value the worker returned as "ok", including `inf`, which `select_algorithm` drops silently rather than ranking. A non-finite or non-positive time is now reported as a fault, which makes the existing inline fallback reachable: the candidate is timed against the default kernel instead of vanishing. A failed warm-up is tolerated the same way -- it logs and still measures -- so aten always carries a real kernel time into the race. ghstack-source-id: 454857429 @exported-using-ghexport Differential Revision: [D116493590](https://our.internmc.facebook.com/intern/diff/D116493590/)
Pull Request resolved: #201769 Completes the reuse pass. A shape with no tuned entry of its own can borrow the solution of a neighbouring shape, but a borrow is a guess: it was measured for a different size. This decides whether the guess is actually better than the default kernel, and records the answer so the question is never asked again. The decision is made by the code that already makes it. `FindFastest` benchmarks a candidate set and returns the winner, starting from `Default` as the incumbent, and `Default` is registered as candidate 0 for every GEMM op. So checking a borrow is just `FindFastest` with the candidate set narrowed from every solution the backend offers to the single borrowed one. It inherits the screening passes, the timer, the numerics check and the write path that a tuning run already goes through, rather than standing up a second winner-selection mechanism beside it. The winner is persisted either way, including `Default` when the borrow loses or when there is no neighbour to borrow from. The shape then becomes an ordinary exact hit, so neither the nearest search nor this comparison is repeated on a later pass, and execution never has to borrow at all. On the Inductor side, an aten candidate is benchmarked in the TunableOp worker rather than inline. Extern kernels are otherwise benchmarked in the current process on the explicit assumption that they do not crash; hipBLASLt tuning breaks that assumption, and a fault there takes the compile with it. **Warm, then measure.** The first call to a GEMM in the worker is where TunableOp does its compile-time-only work -- the full solution search in tune mode, the nearest-match scan and borrow validation in reuse mode. Benchmarking straight away folds that work into the average and reports it as the kernel's cost, which is wrong twice over: serving never repeats it, and the inflated number loses the autotune race to a slower triton template that was measured honestly. So the job now pays that cost in a discarded call, then measures with tuning off, which is exactly the configuration serving runs. That bug was worth roughly the whole regression it caused. On one model an addmm of 3072x1894x242432 went from a 3.5 ms aten candidate to over 7.45 ms, lost to a 4.71 ms triton kernel, and never appeared in the autotune ranking at all -- while the solution TunableOp had just recorded for that shape ran in 2.9 ms. Measured end to end, that model went from -56% against baseline to +1.4%. **A reply is not a measurement.** `submit()` previously reported any value the worker returned as "ok", including `inf`, which `select_algorithm` drops silently rather than ranking. A non-finite or non-positive time is now reported as a fault, which makes the existing inline fallback reachable: the candidate is timed against the default kernel instead of vanishing. A failed warm-up is tolerated the same way -- it logs and still measures -- so aten always carries a real kernel time into the race. ghstack-source-id: 455211844 @exported-using-ghexport Differential Revision: [D116493590](https://our.internmc.facebook.com/intern/diff/D116493590/)
Pull Request resolved: #201769 Completes the reuse pass. A shape with no tuned entry of its own can borrow the solution of a neighbouring shape, but a borrow is a guess: it was measured for a different size. This decides whether the guess is actually better than the default kernel, and records the answer so the question is never asked again. The decision is made by the code that already makes it. `FindFastest` benchmarks a candidate set and returns the winner, starting from `Default` as the incumbent, and `Default` is registered as candidate 0 for every GEMM op. So checking a borrow is just `FindFastest` with the candidate set narrowed from every solution the backend offers to the single borrowed one. It inherits the screening passes, the timer, the numerics check and the write path that a tuning run already goes through, rather than standing up a second winner-selection mechanism beside it. The winner is persisted either way, including `Default` when the borrow loses or when there is no neighbour to borrow from. The shape then becomes an ordinary exact hit, so neither the nearest search nor this comparison is repeated on a later pass, and execution never has to borrow at all. On the Inductor side, an aten candidate is benchmarked in the TunableOp worker rather than inline. Extern kernels are otherwise benchmarked in the current process on the explicit assumption that they do not crash; hipBLASLt tuning breaks that assumption, and a fault there takes the compile with it. **Warm, then measure.** The first call to a GEMM in the worker is where TunableOp does its compile-time-only work -- the full solution search in tune mode, the nearest-match scan and borrow validation in reuse mode. Benchmarking straight away folds that work into the average and reports it as the kernel's cost, which is wrong twice over: serving never repeats it, and the inflated number loses the autotune race to a slower triton template that was measured honestly. So the job now pays that cost in a discarded call, then measures with tuning off, which is exactly the configuration serving runs. That bug was worth roughly the whole regression it caused. On one model an addmm of 3072x1894x242432 went from a 3.5 ms aten candidate to over 7.45 ms, lost to a 4.71 ms triton kernel, and never appeared in the autotune ranking at all -- while the solution TunableOp had just recorded for that shape ran in 2.9 ms. Measured end to end, that model went from -56% against baseline to +1.4%. **A reply is not a measurement.** `submit()` previously reported any value the worker returned as "ok", including `inf`, which `select_algorithm` drops silently rather than ranking. A non-finite or non-positive time is now reported as a fault, which makes the existing inline fallback reachable: the candidate is timed against the default kernel instead of vanishing. A failed warm-up is tolerated the same way -- it logs and still measures -- so aten always carries a real kernel time into the race. ghstack-source-id: 455575662 @exported-using-ghexport Differential Revision: [D116493590](https://our.internmc.facebook.com/intern/diff/D116493590/)
Pull Request resolved: #201769 Completes the reuse pass. A shape with no tuned entry of its own can borrow the solution of a neighbouring shape, but a borrow is a guess: it was measured for a different size. This decides whether the guess is actually better than the default kernel, and records the answer so the question is never asked again. The decision is made by the code that already makes it. `FindFastest` benchmarks a candidate set and returns the winner, starting from `Default` as the incumbent, and `Default` is registered as candidate 0 for every GEMM op. So checking a borrow is just `FindFastest` with the candidate set narrowed from every solution the backend offers to the single borrowed one. It inherits the screening passes, the timer, the numerics check and the write path that a tuning run already goes through, rather than standing up a second winner-selection mechanism beside it. The winner is persisted either way, including `Default` when the borrow loses or when there is no neighbour to borrow from. The shape then becomes an ordinary exact hit, so neither the nearest search nor this comparison is repeated on a later pass, and execution never has to borrow at all. On the Inductor side, an aten candidate is benchmarked in the TunableOp worker rather than inline. Extern kernels are otherwise benchmarked in the current process on the explicit assumption that they do not crash; hipBLASLt tuning breaks that assumption, and a fault there takes the compile with it. **Warm, then measure.** The first call to a GEMM in the worker is where TunableOp does its compile-time-only work -- the full solution search in tune mode, the nearest-match scan and borrow validation in reuse mode. Benchmarking straight away folds that work into the average and reports it as the kernel's cost, which is wrong twice over: serving never repeats it, and the inflated number loses the autotune race to a slower triton template that was measured honestly. So the job now pays that cost in a discarded call, then measures with tuning off, which is exactly the configuration serving runs. That bug was worth roughly the whole regression it caused. On one model an addmm of 3072x1894x242432 went from a 3.5 ms aten candidate to over 7.45 ms, lost to a 4.71 ms triton kernel, and never appeared in the autotune ranking at all -- while the solution TunableOp had just recorded for that shape ran in 2.9 ms. Measured end to end, that model went from -56% against baseline to +1.4%. **A reply is not a measurement.** `submit()` previously reported any value the worker returned as "ok", including `inf`, which `select_algorithm` drops silently rather than ranking. A non-finite or non-positive time is now reported as a fault, which makes the existing inline fallback reachable: the candidate is timed against the default kernel instead of vanishing. A failed warm-up is tolerated the same way -- it logs and still measures -- so aten always carries a real kernel time into the race. ghstack-source-id: 455766225 @exported-using-ghexport Differential Revision: [D116493590](https://our.internmc.facebook.com/intern/diff/D116493590/)
There was a problem hiding this comment.
Automated review of 6431f6b: nothing blocking; ready for human review.
The PR makes TunableOp, with tuning off, benchmark a borrowed nearest-match or wildcard donor against Default and record the winner, sends Inductor's extern GEMM candidates through the TunableOp worker with a warm-up before measuring, and runs the pretune ladder after finalize(). Recommendation: Approve. Every point raised is non-blocking, and the approval assumes stacked PR # 203284 (where the earlier blocking findings were fixed) lands together with this one.
⚪ 18 non-blocking findings
Capture check compiled out on ROCm (non-blocking, carried over). can_validate is only computed under #ifndef USE_ROCM. On ROCm, the feature's main target, FindFastestAmong can therefore run during hipGraph capture, which the comment just above says invalidates the capture. GemmHipblaslt.h:731 already calls c10::cuda::currentStreamCaptureStatusMayInitCtx() on ROCm, so the guard (and the include guard at :17-18) can go.
Redundant flag checks (non-blocking, carried over). The IsRecordBorrowedEnabled() checks at :228 and :246 add nothing. will_validate can only be true when IsNearestMatchEnabled() is, and that already requires recording. Dropping them makes the record-untuned rule easier to read.
pytorch/torch/_inductor/tunableop.py
Line 591 in 6431f6b
New warnings bypass _warn_fault_once (non-blocking). _warn_fault_once exists at :91-96 and every other fault path in submit() uses it (:540, :564, :568, :572, :586). Three new warnings don't: log.warning("TunableOp benchmark returned %r; treating as a fault") here at :591; "TunableOp benchmark of %s hit %s; timing it inline instead." at select_algorithm.py:3936-3940; and the worker-side log.warning("TunableOp warm-up failed", exc_info=True) at :198. With a broken worker, the select_algorithm line then warns once per candidate for the rest of the compile, after submit() has already dropped to debug. Route :591 through _warn_fault_once, and make :3936 debug-level or warn once.
pytorch/torch/_inductor/tunableop.py
Line 590 in 6431f6b
submit()'s value check changes ladder behaviour (non-blocking, carried over). The value check here also applies to measure=False ladder jobs. A rung that times inf or 0 now counts as failed and is retried up to _TUNABLEOP_MAX_BUCKET_ATTEMPTS. Two comments are now stale: the Outcome docstring (:257, "the job raised"), and the ladder comment "the worker restarts on the next submission" (:1096-1097), which is wrong because this path does not call _shutdown_locked.
pytorch/torch/_inductor/select_algorithm.py
Line 3923 in 6431f6b
VERIFY debug path breaks for routed GEMMs (non-blocking, debug-only). select_algorithm.py:5626-5627 uses choices\[0\].benchmark(..., out=out_extern) as the reference output. A routed extern GEMM returns outcome.time (:3911-3924) without writing out, so expected is whatever was in the buffer, and the check at :5674-5675 fails. This only happens when someone sets VERIFY. Fix: skip routing when VERIFY is set.
Line 9378 in 6431f6b
Default-off tests can no longer fail (non-blocking). :9378-9379 makes _set_tunableop_defaults, which every _tunableop_ctx() runs on entry (:9326), force _nearest_match_enable(False) and _record_borrowed_enable(False). That turns two sets of asserts into checks of the test fixture rather than of the C++ defaults at Tunable.cpp:724-725: the default-off asserts and the behaviour half of the new test_nearest_match_off_by_default_tunableop (:12064-12083), and the older asserts at :11178-11179. Flipping those C++ defaults to true passes both tests. Check the defaults in a fresh subprocess, or read them before the fixture resets them.
Line 12172 in 6431f6b
test_nearest_match_precedes_wildcard_fallback_tunableop can't detect a reversed order (non-blocking). It tunes the donor without dynamic_dims_mask. Wildcard rows only come from masked tuning (TunableOp.h:83-92), so none exists here. Swapping the nearest and wildcard lookups at TunableOp.h:203-219 still passes, and the test only repeats test_nearest_match_borrow_tunableop. Tune under a mask, as test_wildcard_donor_validated_and_persisted_tunableop does.
Reuse-mode routing flags are never checked (non-blocking). :927-949 patches only is_reuse_mode=False. No test checks that a routed reuse-mode job carries nearest_match=True, record_borrowed=True (select_algorithm.py:3915-3916). Hard-coding record_borrowed=False there would turn off all borrowing in reuse mode and nothing would fail. Add a reuse-mode case.
Fallback test doesn't check ordering (non-blocking). test_non_ok_falls_through_with_tunableop_off (:974-997) checks only the enable/tuning_enable call lists. It would pass if the restore ran before _benchmark_inline. Record the order relative to bmreq.benchmark, as test_measured_call_runs_with_both_flags_off does.
test_nonfinite_worker_time_is_error can't tell its guard apart from other errors (non-blocking, carried over). submit() returns Outcome(None, "error") from four other places, so the test still passes with the value guard removed. Assert that proc.sent is non-empty, or check for the "treating as a fault" log. Also, tunableop._worker and _worker_key are reset inline rather than via addCleanup, so a failed assert leaves the fake worker installed.
pytorch/torch/_inductor/tunableop.py
Line 179 in 6431f6b
Dynamic-dims-mask test checks only the first benchmark (non-blocking, carried over). test_tunableop_worker.py:614-615 uses kinds.index("benchmark"). Since _warm_then_measure, a job runs two benchmarks, and the second one is not checked against the mask scope.
Replacement selector-hook test no longer checks the returned choice (non-blocking, carried over). The removed test asserted assertIs(chosen, winner). test_algorithm_selector_hook_fires_on_every_exit (:841 area) only checks hook.assert_called_once_with(chosen). Under test/REVIEW.md this is a coverage reduction the PR does not explain; assert an expected choice for each exit_path.
Line 11948 in 6431f6b
Subprocess test inherits PYTORCH_TUNABLEOP_* (non-blocking, carried over, corrected). In test_borrow_verdict_not_revalidated_tunableop (:12022 area), an inherited PYTORCH_TUNABLEOP_RECORD_UNTUNED=1 overrides the child's record_untuned_enable(False) (Tunable.cpp:817-822). The record_borrowed=False subtest then writes a stray tunableop_untuned<dev>.csv into test/. Using cwd=os.path.dirname(__file__) matches other tests in this file. The fix is to strip PYTORCH_TUNABLEOP_* and run in a tmpdir, as the test at :10886-10894 does. Popping PYTHONPATH/PYTHONHOME is unique to this test and can break a dev setup where torch is found through PYTHONPATH.
Docstring caveat removed while still true (non-blocking, carried over). The TunableOpPretuneRealGpuTest docstring dropped the note that a warm cache is not covered. It still isn't: the test compiles once under fresh_cache().
pytorch/aten/src/ATen/cuda/tunable/README.md
Line 135 in 6431f6b
README overstates the wildcard behaviour (non-blocking, carried over). It says "a non-Default wildcard entry is validated and persisted the same way". That holds only when wildcard fallback is enabled, which reuse mode does not do, and no nearest donor is usable (TunableOp.h:212). The section also sits under "Offline Tuning" but describes an Inductor compile-time mode.
Line 300 in 6431f6b
wildcard_fallback_enable docstring is incomplete (non-blocking). torch/cuda/tunable.py:276-284 doesn't say that when nearest match is also on, a wildcard hit is benchmarked against Default and the result is written to the results file. That combination is only reachable through the private setters.
pytorch/torch/_inductor/tunableop.py
Line 189 in 6431f6b
Warm-up runs a second full benchmark (non-blocking). BenchmarkJob._warm_then_measure (:189, :212) calls bmreq.benchmark() twice for every routed autotune candidate (measure=True). Each call rebuilds the inputs and runs the whole benchmarker.benchmark loop (autotune_process.py:708-760). In reuse mode, most candidates are exact hits or have no donor, so the warm-up does no TunableOp work at all. A cheaper warm: build the inputs once, call bmreq.make_run_fn(*inputs, out=out)() once untimed, then time it on the same tensors.
pytorch/torch/_inductor/graph.py
Line 3090 in 6431f6b
Ladder time is now counted as codegen (non-blocking). run_queued_pretunes here runs inside dynamo_timed("GraphLowering.codegen") and "GraphLowering.codegen_subgraph". tunableop.py has no timing span of its own, so up to autotune_tunableop_timeout per GEMM shows up in compile metrics and tlparse as codegen. Wrap the drain in its own dynamo_timed span.
This review is AI-generated and advisory. Each new automated review replaces the previous one. Report a bad review
Stack from ghstack (oldest at bottom):
Completes the reuse pass. A shape with no tuned entry of its own can borrow the
solution of a neighbouring shape, but a borrow is a guess: it was measured for a
different size. This decides whether the guess is actually better than the default
kernel, and records the answer so the question is never asked again.
The decision is made by the code that already makes it.
FindFastestbenchmarks acandidate set and returns the winner, starting from
Defaultas the incumbent, andDefaultis registered as candidate 0 for every GEMM op. So checking a borrow isjust
FindFastestwith the candidate set narrowed from every solution the backendoffers to the single borrowed one. It inherits the screening passes, the timer and
the numerics check that a tuning run already goes through, rather than standing up
a second winner-selection mechanism beside it. The write is its own step:
FindFastestAmongpersists nothing, andRecordBorrowedforce-persists theverdict because a reuse pass runs with tuning off.
The winner is persisted whenever the comparison completes, including
Defaultwhenthe borrow loses; a comparison that throws records nothing and is reported untuned
instead. That shape then becomes an ordinary exact hit, so neither the nearest
search nor this comparison is repeated on a later pass, and execution never has to
borrow at all. A shape with no eligible neighbour and no usable non-Default
wildcard is different: nothing is recorded and it falls back to
Default, so itsnearest search does repeat on a later call. A wildcard that IS usable is validated
and persisted like any other donor.
Borrowing now requires recording.
IsNearestMatchEnabled()reads therecord-borrowed flag, so turning recording off turns borrowing off with it: a pass
that measured a donor but wrote nothing would leave runtime on
Defaultwhile thedecision rested on a measurement runtime cannot reproduce.
The ladder is deferred rather than run inline. The
select_algorithmhooks firewhile lowering, before
finalize()decides layouts, so an extern winner is queuedon
V.graph.pending_tunableop_ladderand laddered once the layouts are final.Routing covers a wider set than the ladder.
_TUNABLEOP_ROUTING_CHOICESis theladder's set plus
bias_addmm: the ladder cannot rebuild its meta, but running itin the worker still keeps a hipBLASLt fault out of the compile.
On the Inductor side, an aten candidate is benchmarked in the TunableOp worker
rather than inline. Extern kernels are otherwise benchmarked in the current process
on the explicit assumption that they do not crash; hipBLASLt tuning breaks that
assumption, and a fault there takes the compile with it.
Warm, then measure. The first call to a GEMM in the worker is where TunableOp
does its compile-time-only work -- the full solution search in tune mode, the
nearest-match scan and borrow validation in reuse mode. Benchmarking straight away
reports that work as the kernel's cost, which is wrong twice over: serving never
repeats it, and the inflated number loses the autotune race to a slower triton
template that was measured honestly. So the job now pays that cost in a discarded
call, then measures with tuning off, which is exactly the configuration serving
runs.
That bug was worth roughly the whole regression it caused. On one model an addmm
of 3072x1894x242432 went from a 3.5 ms aten candidate to over 7.45 ms, lost to a
4.71 ms triton kernel, and never appeared in the autotune ranking at all -- while
the solution TunableOp had just recorded for that shape ran in 2.9 ms. Measured
end to end, that model went from -56% against baseline to +1.4%. Observed rather
than derived: the benchmarker discards its own first call, so where the tuning
cost survives into the reported time has not been traced.
A reply is not a measurement.
submit()previously reported any value theworker returned as "ok", including
inf, whichselect_algorithmdrops silentlyrather than ranking. A non-finite or non-positive time is now reported as a fault,
which makes the existing inline fallback reachable: the candidate is timed against
the default kernel instead of vanishing. A failed warm-up is not tolerated the
same way: it logs and re-raises, so the job is filed as a fault rather than
reporting a time for a kernel that was never validated, and the caller times the
candidate inline.
@exported-using-ghexport
Differential Revision: D116493590
Differential Revision: D116493590