Repository navigation
[MHA] Tune MHA forward across every backend on the shared tuning contract - #6580
Draft
amd-bartgips wants to merge 5 commits into
Draft
amd-bartgips wants to merge 5 commits into
amd-bartgips wants to merge 5 commits into
Conversation
This was referenced Oct 15, 2026
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 15, 2026 13:47
5e212c8 to
2057f17
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 15, 2026 13:47
2cfd4e2 to
cea9f92
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 16, 2026 08:01
2057f17 to
f0621a0
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 16, 2026 08:01
cea9f92 to
41ec951
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 16, 2026 08:03
f0621a0 to
98674fd
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 16, 2026 08:03
41ec951 to
8ca1329
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 16, 2026 12:16
8ca1329 to
52c49b0
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 16, 2026 12:16
98674fd to
7ad4275
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 26, 2026 08:54
7ad4275 to
e10cf33
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 26, 2026 08:54
af4c60d to
dcdf0e5
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 26, 2026 12:33
e10cf33 to
eba1d35
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 26, 2026 12:33
dcdf0e5 to
543795a
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 26, 2026 14:42
eba1d35 to
f350402
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
2 times, most recently
from
October 26, 2026 16:18
cfbfea8 to
ca442bd
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 26, 2026 16:18
f350402 to
8d4326e
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 27, 2026 08:29
ca442bd to
4ed3bd0
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 27, 2026 08:29
8d4326e to
40499c9
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
2 times, most recently
from
October 27, 2026 10:51
6c90856 to
353a718
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
3 times, most recently
from
October 28, 2026 08:39
1911985 to
3984c97
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 28, 2026 08:39
353a718 to
d80c2d5
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
October 28, 2026 14:49
3984c97 to
d6e8acd
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
October 28, 2026 14:49
d80c2d5 to
c204d35
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
November 3, 2026 16:03
d6e8acd to
3edb3a5
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
November 3, 2026 16:03
c204d35 to
2d30c99
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
2 times, most recently
from
November 4, 2026 12:18
7afdcbc to
4a86817
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
2 times, most recently
from
November 9, 2026 15:49
ed20d45 to
3af5360
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
November 9, 2026 15:49
4a86817 to
b39ee86
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
November 9, 2026 15:59
3af5360 to
6dde747
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
November 9, 2026 15:59
b39ee86 to
3c4a532
Compare
…tile A triton or gluon row calls Triton's varlen entry with config=None, so Triton resolves its own tile from its JSON as today, and dispatch copies the result into the caller's out. The row stores config_digest, a hash of the tile Triton resolved when it was tuned. At load the hash is recomputed, and the row is skipped with a warning naming the tuner if Triton now resolves another tile, if the digest is missing, or if the key needs what Triton's varlen entry lacks (soft-cap, FP8 inputs, sinks, ...). The hash goes through Triton's private _get_config until a public resolver exists; if that changes, the rows are skipped, never run with a stale tile.
op_tests/tuners/tune_mha_fwd.py times every MHA forward backend as shipped for each shape (one candidate per backend; each picks its own kernel or tile) and writes the fastest correct one. With --compare --update_improved a row is kept only when it beats what serves the shape today, including auto-select, by --min_improvement_pct and a fresh process verifies that dispatch selects it. - Backends that cannot serve a shape correctly are skipped (on soft-capped shapes only CK is measured); inputs it cannot synthesize are refused. A shape left with no backend is skipped rather than failing the run. - Kernel time through run_perftest on rotated inputs, for the candidates and for the probe that --compare and run_config time a row with, so neither host-side dispatch, which graph-captured serving does not pay, nor inputs left warm in cache decide a row. - A chunked fp32 reference with rtol 0.02 and no element outside it. atol is 0.02 up to 1024 keys and shrinks as 1/sqrt(keys) beyond, or a kernel that drops a long sequence's last keys would pass. - A Triton row whose tile changed is stale: a plain rerun retunes it. The untuned CSV gives the shared duplicate-shape check its key, which now includes gpu_model when the table has it: gfx and cu_num cannot tell an MI300X row from an MI325X row for the same shape.
Tables compiled into C++ are looked up by (gfx, cu_num, shape) only, so rows tuned on two products that share those (MI300X and MI325X) would collapse into whichever row comes last. The merge-time duplicate check now accepts rows that differ only in gpu_model, which is right for tables dispatched at runtime such as tuned_mha_fwd.csv; the build refuses them until codegen can key on the model.
The shared tuner no longer keys rows on gpu_model, so the MHA tuner adds it to its live hardware and stamps its rows with it. --run_config reads the rows dispatch serves this GPU, by the same fallback: its own model's, else rows without a model (or a table without the column), else another model's with the same gfx and cu_num. Verification therefore leaves the model to the fresh process, whose recorded selection shows whether the row served. The --run_config filter goes through _rows_for_this_gpu, which the MHA tuner overrides; for other tuners it still checks gfx and cu_num. mp_tuner(return_status=True) now returns (results, statuses); tune() joins them into the records result_to_df reads.
amd-bartgips
force-pushed
the
users/bartgips/fmha-tuner-family
branch
from
November 12, 2026 09:58
6dde747 to
579db97
Compare
amd-bartgips
force-pushed
the
users/bartgips/fmha-single-store
branch
from
November 12, 2026 09:58
3c4a532 to
4cc8ead
Compare
6 of 11 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
op_tests/tuners/tune_mha_fwd.pywrites the rows that #5762 reads, and this PR lets those rows name Triton and Gluon. For each shape the tuner times every MHA forward backend as shipped and writes the fastest correct one. It updates the tuned CSV through the existing--compare --update_improvedflow, using #5846's dispatch verification and auto-select baseline.Stack. main → #5762 → #6580 (this) → #5849. #5846 has merged. No kernel changes and no Triton code changes. Four commits: Triton and Gluon rows in dispatch, the tuner, a build-time check that keeps per-model rows out of compiled tables, then the tuner's own
gpu_modelkey.Triton and Gluon rows (first commit)
config=Noneand storesconfig_digest, a hash of the tile Triton resolved at tuning time. If Triton now resolves another tile, dispatch skips the row with a warning, and the tuner treats it as stale and retunes it.min_seqlen_q(Triton ignores it), a left window of 0 (Triton reads it as no window), and ALiBi or sink logits (no tuner run measures them on Triton).out, dispatch copies the result into it: one extra copy per call on a Triton row.The tuner (second commit)
min_seqlen_q, dropout or gfx1250.--compareuses to time a row both go throughrun_perftestwith their inputs as arguments, so both rotate copies of the inputs and neither reads them warm from cache. A row is kept for its device kernel time. Under CUDA/HIP graphs, as in vLLM and SGLang, host-side launch cost disappears and kernel time is what the caller sees.--compare --update_improved, a row is kept only if it beats what serves today, auto-select included, by--min_improvement_pct(3% by default), and a fresh process verifies that dispatch selects it.untuned_mha_fwd.csvgives the shared duplicate-shape check its key, which now includesgpu_modelwhen a table has it:gfxandcu_numcannot tell an MI300X row from an MI325X row for the same shape.test_config_shape_collisionnow checks the MHA table too.Compiled tables (third commit)
gpu_model. That is right for a table read at runtime, such astuned_mha_fwd.csv. The CK GEMM tables, however, are compiled into a C++ lookup keyed ongfx,cu_numand shape only, so the last of two such rows would silently serve both GPUs.filter_tune_df, which every CK GEMM codegen goes through, now raises when a row names agpu_model. No compiled table ships the column and no CK GEMM tuner writes it, so no build changes today. A row with the cell blank still passes. The check can go once codegen keys on the model.The tuner's
gpu_modelkey (fourth commit)gpu_model, so the MHA tuner adds it to its own hardware fields and stamps its rows with it.--run_configreads the rows dispatch would serve this GPU, by [FlyDSL] [CI] [JIT] [MHA] Route MHA forward through a tuned backend row #5762's fallback: its own model's, else rows without a model (or a table without the column), else another model's with the samegfxandcu_num. Verification leaves the model to the fresh process, whose recorded selection shows whether the row served.--run_configfilter moves into_rows_for_this_gpu, which the MHA tuner overrides; for every other tuner it still checksgfxandcu_num.mp_tuner(return_status=True)now returns(results, statuses)([CK] [CI] [JIT] [Tuning] Per-candidate faults, selection proof and auto-select in --compare #5846);tune()joins them into the recordsresult_to_dfreads.Not covered
cu_seqlens_*_padded) are not tuned, and [FlyDSL] [CI] [JIT] [MHA] Route MHA forward through a tuned backend row #5762 rejects their rows. The key would need the real token count, which iscu_seqlens_q[-1], a GPU tensor: reading it per call costs a device sync, and in a graph-captured call the value cannot be read at all.q.shape[0]counts padded rows and would map different workloads to one row.block_table) is also excluded:k.shape[0]is the KV pool size, not the sequence length. It needs a different key and will get its own PR.Questions for the Triton owners (@azaidy, @vgokhale)
_get_configtoday. #6613 proposes a publicget_mha_fwd_configfor it. Until then, a change to the private function makes rows be skipped, not wrongly run.Result (MI355X, 8 shapes, with
--compare). Two rows were written, both Triton on hd64, non-causal: 1,024 keys at 40.6 µs vs 51.5 µs from auto-select (21%), and 4,096 keys at 381.9 vs 399.3 µs (4.4%). The other six shapes were within 3% or slower, so auto-select keeps them.Open: timing robustness. With both sides timed on rotated inputs, the probe and the candidate loop agree within about 1% for every backend except Triton on the 1,024-key shape: 40.6 µs in the probe vs 42.8 µs in the candidates. The
uscolumn in the CSV is the candidate time. Run to run, CK has moved more than the 3% gate on one shape (64.1 vs 52.1 µs in earlier runs, same GPU). I plan to follow up on this separately, possibly by adopting the timers from #6715; until then, I would not read 3–5% margins from a single run as real.Reproduce:
python3 op_tests/tuners/tune_mha_fwd.py -i untuned.csv -o tuned.csv --mp 1 --compare --update_improved, withuntuned.csvin the format ofaiter/configs/untuned_mha_fwd.csv.Tested. Head
9683e2f42on #57625e2e1e056(main1863bb8e4, which includes #5846), on one MI355X:python3 -m unittest op_tests.tuning_tests.{test_mha_tuner_logic,test_mha_fwd_dispatch,test_compare_logic,test_dispatch_verification,test_csv_validation,test_tuner_infra,test_config_shape_collision,test_mp_tuner_logic}: 225 run, 217 passed. 7 were skipped and 1 failed for one reason: main's Gluon MHA kernel ([Triton/Gluon] [GFX950] Productize gluon mha kernel from GFX950-gluon-tutorials #5153) importswarp_pipeline_stage, which this container's Triton 3.6.0 lacks, soaiter.ops.triton.attention.mhadoes not import here.test_tune_pipeline.TestTunePipeline.test_mha_fwd_mp1(a real tune of one shape on two backends): passed.test_run_config.TestRunConfig.test_mha_fwd: skipped, because the shipped CSV has no rows for this GPU.--run_configfallback, for verification leaving the model to dispatch, and forfilter_tune_dfrefusing model rows fail on the code without them.The sweep above ran on head
d80c2d5cf(mainbbef5a6f2), before the rebases.Sweep (µs, kernel time; best candidate per backend)
--compare(auto-select → row)These were bf16, batch 4, 16 heads; "1024" and "4096" are the keys per sequence.
asm_v3rejects hd64. Opus has no hd64 varlen kernel; its hd128 varlen kernel (#7584, merged after the sweep) is opt-in behindAITER_ENABLE_FMHA_OPUS. FlyDSL declined every shape, and Gluon does not compile with Triton 3.6.0.Size. 17 files, +1,919 / −19 (about 880 lines of tests). Owners: @yzhou103 (tuning), @valarLip (MHA), @azaidy and @vgokhale (Triton rows).