Skip to content

[tunableop] validate a borrowed solution before trusting it - #201769

Open
ruddhic wants to merge 108 commits into
gh/ruddhic/4/basefrom
gh/ruddhic/4/head
Open

ruddhic wants to merge 108 commits into
gh/ruddhic/4/basefrom
gh/ruddhic/4/head

Conversation

@ruddhic

@ruddhic ruddhic commented Oct 22, 2026 •

Copy link
Copy Markdown

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. 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 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:
FindFastestAmong persists nothing, and RecordBorrowed force-persists the
verdict because a reuse pass runs with tuning off.

The winner is persisted whenever the comparison completes, including Default when
the 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 its
nearest 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 the
record-borrowed flag, so turning recording off turns borrowing off with it: a pass
that measured a donor but wrote nothing would leave runtime on Default while the
decision rested on a measurement runtime cannot reproduce.

The ladder is deferred rather than run inline. The select_algorithm hooks fire
while lowering, before finalize() decides layouts, so an extern winner is queued
on V.graph.pending_tunableop_ladder and laddered once the layouts are final.

Routing covers a wider set than the ladder. _TUNABLEOP_ROUTING_CHOICES is the
ladder's set plus bias_addmm: the ladder cannot rebuild its meta, but running it
in 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 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 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

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - OUTDATED (earlier commit) - 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.

Findings (18):

[minor] aten/src/ATen/cuda/tunable/TunableOp.h:240
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.

[minor] aten/src/ATen/cuda/tunable/TunableOp.h:228
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.

[minor] torch/_inductor/tunableop.py:591
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.

[minor] torch/_inductor/tunableop.py:590
`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`.

[minor] torch/_inductor/select_algorithm.py:3923
`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.

[minor] test/test_linalg.py:9378
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.

(12 more not shown, see the review run)

Reviewed commit: 6431f6b (NOT the current head bbd1c80)

Review run

🐛 Report a bad review

🔗 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 Failure

As of commit bbd1c80 with merge base 836c141 (image):

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.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
ruddhic added a commit that referenced this pull request Oct 22, 2026
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/)
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
ruddhic added a commit that referenced this pull request Oct 23, 2026
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/)
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
ruddhic added a commit that referenced this pull request Oct 23, 2026
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/)
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
ruddhic added a commit that referenced this pull request Oct 23, 2026
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/)
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]
github-actions[bot]

This comment was marked as outdated.

[ghstack-poisoned]

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.


!(will_validate && ctx->IsRecordBorrowedEnabled())) {

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.


log.warning("TunableOp benchmark returned %r; treating as a fault", value)

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.


if not isinstance(value, (int, float)) or not math.isfinite(value) or value <= 0:

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.


if outcome.status == "ok":

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.


torch.cuda.tunable._nearest_match_enable(False)

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.


def test_nearest_match_precedes_wildcard_fallback_tunableop(self, device, dtype):

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.


mock.patch("torch._inductor.tunableop.is_reuse_mode", return_value=False),

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.


def test_non_ok_falls_through_with_tunableop_off(self):

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.


def test_nonfinite_worker_time_is_error(self):

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.


def _warm_then_measure(self) -> float:

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.


def test_algorithm_selector_hook_fires_on_every_exit(self, exit_path):

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.


def test_borrow_verdict_not_revalidated_tunableop(self, device, dtype):

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&lt;dev&gt;.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().


loses. A non-Default wildcard entry is validated and persisted the same way.

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.


def _nearest_match_enable(val: bool = True) -> None:

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.


measured = self.bmreq.benchmark()

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.


run_queued_pretunes(self)

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

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request meta-exported module: inductor ready for review Automated review passed, ready for a final review by a maintainer. release notes: linalg_frontend release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants