Repository navigation
[FlyDSL] [CI] [JIT] [MHA] Route MHA forward through a tuned backend row - #5762
amd-bartgips wants to merge 24 commits into
Conversation
bf10259 to
fbf18fa
Compare
346dcd7 to
2d1a827
Compare
6b6067a to
397f2d4
Compare
#5762 raised its fixed-delta gate to 3%. This branch replaced that gate with the shared PromotionPolicy, so the merge keeps this branch's version of the three files; the next commits move the shared policy to the same 3%. Co-authored-by: Cursor <[email protected]>
8776074 to
8a11428
Compare
Moved unchanged from the MHA forward tuner branch (#5762) so that other tuners can use them without waiting for it: - mp_tuner: optional per-candidate status and detail (return_status), a per-candidate progress queue with result_callback, a faulted group keeping the candidates it had already measured, MpTunerTask, broader accelerator-fault detection, and a pool restart on a stale PID map. - TunerCommon.measurement_kwargs, so --warmup and --iters reach the timed call instead of run_perftest's defaults. - _read_csv builds a new frame rather than assigning into a slice. - FileBaton treats a zombie lock holder as dead, so a builder that exited without releasing its lock no longer wedges the module build.
Moved unchanged from the MHA forward tuner branch (#5762) so that other tuners can use them without waiting for it: - mp_tuner: optional per-candidate status and detail (return_status), a per-candidate progress queue with result_callback, a faulted group keeping the candidates it had already measured, MpTunerTask, broader accelerator-fault detection, and a pool restart on a stale PID map. - TunerCommon.measurement_kwargs, so --warmup and --iters reach the timed call instead of run_perftest's defaults. - _read_csv builds a new frame rather than assigning into a slice. - FileBaton treats a zombie lock holder as dead, so a builder that exited without releasing its lock no longer wedges the module build.
#5762 raised its fixed-delta gate to 3%. This branch replaced that gate with the shared PromotionPolicy, so the merge keeps this branch's version of the three files; the next commits move the shared policy to the same 3%.
2760b97 to
d7c3e42
Compare
Moved unchanged from the MHA forward tuner branch (#5762) so that other tuners can use them without waiting for it: - mp_tuner: optional per-candidate status and detail (return_status), a per-candidate progress queue with result_callback, a faulted group keeping the candidates it had already measured, MpTunerTask, broader accelerator-fault detection, and a pool restart on a stale PID map. - TunerCommon.measurement_kwargs, so --warmup and --iters reach the timed call instead of run_perftest's defaults. - _read_csv builds a new frame rather than assigning into a slice. - FileBaton treats a zombie lock holder as dead, so a builder that exited without releasing its lock no longer wedges the module build.
Moved unchanged from the MHA forward tuner branch (#5762) so that other tuners can use them without waiting for it: - mp_tuner: optional per-candidate status and detail (return_status), a per-candidate progress queue with result_callback, a faulted group keeping the candidates it had already measured, MpTunerTask, broader accelerator-fault detection, and a pool restart on a stale PID map. - TunerCommon.measurement_kwargs, so --warmup and --iters reach the timed call instead of run_perftest's defaults. - _read_csv builds a new frame rather than assigning into a slice. - FileBaton treats a zombie lock holder as dead, so a builder that exited without releasing its lock no longer wedges the module build.
Moved unchanged from the MHA forward tuner branch (#5762) so that other tuners can use them without waiting for it: - mp_tuner: optional per-candidate status and detail (return_status), a per-candidate progress queue with result_callback, a faulted group keeping the candidates it had already measured, MpTunerTask, broader accelerator-fault detection, and a pool restart on a stale PID map. - TunerCommon.measurement_kwargs, so --warmup and --iters reach the timed call instead of run_perftest's defaults. - _read_csv builds a new frame rather than assigning into a slice. - FileBaton treats a zombie lock holder as dead, so a builder that exited without releasing its lock no longer wedges the module build.
8a11428 to
ab166eb
Compare
ab166eb to
5e212c8
Compare
5e212c8 to
2057f17
Compare
e3a353a to
2412741
Compare
2057f17 to
f0621a0
Compare
Moved unchanged from the MHA forward tuner branch (#5762) so that other tuners can use them without waiting for it: - mp_tuner: optional per-candidate status and detail (return_status), a per-candidate progress queue with result_callback, a faulted group keeping the candidates it had already measured, MpTunerTask, broader accelerator-fault detection, and a pool restart on a stale PID map. - TunerCommon.measurement_kwargs, so --warmup and --iters reach the timed call instead of run_perftest's defaults. - _read_csv builds a new frame rather than assigning into a slice.
gfx and cu_num cannot tell MI300X from MI325X, so a row measured on one would be applied on the other. chip_info gains get_gpu_model (with an AITER_GPU_MODEL override for replay environments), normalize_gpu_model and get_tuning_hardware, the (gfx, gpu_model, cu_num) triple a family scopes its rows by. run_config filters a tuned CSV by gpu_model when the CSV has that column, the same way it already filters by gfx and cu_num. Moved from the MHA forward tuner branch (#5762), since nothing in it is MHA-specific; @yzhou103 wrote the run_config filter.
9f020c6 to
c055f86
Compare
A tuner measures a candidate in its own worker; serving reads the tuned CSV through the public operator in a new process. Nothing checked that the two agree, so a row could be written that dispatch never honors. aiter/utility/selection_proof.py (standard library only) closes that gap for any family: - the operator calls record_selection(family, ...) where it dispatches, a no-op unless a probe asked for it; - the family's tuner module runs run_selection_probe(probe) when started with --_selection_probe, with a probe that calls the public operator, checks it against a reference and times it; - prove_selection starts that child with the family's config env var pointing at the candidate CSV and returns verified, wrong_selection (ran correctly, dispatched elsewhere) or failed. TunerCommon opts a family in with SELECTION_PROBE_MODULE, SELECTION_FAMILY and expected_selection, reuses the existing config_env_name, and then gives it prove_selection and a default run_config that proves each row. Families that do not opt in see no change. The mechanics are lifted from the MHA forward tuner (#5762), which becomes the first family to use them.
f0621a0 to
98674fd
Compare
zufayu
left a comment
There was a problem hiding this comment.
Re-reviewed current head 9641c5a against its stacked base. The shipped CSV is empty, so default dispatch is unchanged. Exact hardware/problem keys, padded/paged and torch.compile bypasses, backend-decline fallback, GPU-model handling, and selection recording are covered by the targeted 126-test validation. I found no correctness blocker in this PR. Approving from the integration side; the stacked-base/retarget CI and the requested tuned-policy owner review remain independent merge gates, not reasons to defer this code review.
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
|
@zoe-cop review |
|
@valar-cop review |
get_gfx() names only the last GPU_ARCHS entry, so with GPU_ARCHS=gfx942;gfx950 a gfx942 dropped every tuned row. Check the running arch against get_gfx_list() instead.
The key coerced it with int(), which raised TypeError before dispatch once a row matched the GPU and head dims.
The key builder now reads batch from cu_seqlens_q, as it reads the other cells from q, k and v. The call site passes the tensor and no longer computes a cell by hand. test_mha_optional_flydsl runs flash_attn_varlen_func in its own namespace. That namespace now stubs get_mha_fwd_tuned_backend and record_mha_fwd_selection, the two policy names the function calls.
An older libdrm amdgpu.ids can lack a product, and then the HIP device name carries no model. The fallback now maps 0x74A1 and its VF 0x74B5 to mi300x, and 0x74A5 and its VF 0x74B9 to mi325x. The IDs come from ROCm's amdgpu.ids and mi_gpu_spec.yaml. The MI308 IDs in MI308_CHIP_IDS stay out of the table.
|
Hi @shay-li77, thank you for taking this review! Quick summary: both review threads from valar-cop are fixed and resolved, and there is no open change request. The earlier approval was dismissed, so the PR needs a fresh approval, including one from team_aiter. I just merged main into the branch ( |
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 23 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ROCm/aiter PR #5762 — [FlyDSL] [CI] [JIT] [MHA] Route MHA forward through a tuned backend row
Review (advisory):
Validation (deterministic): NOT RUN — REVIEW_AUTO_VALIDATE=0 (auto-validation disabled); the target this PR adds, op_tests/tuning_tests/test_mha_fwd_dispatch.py, was not run by this review
Perf (advisory): NOT RUN — the target ships no benchmark entry point (no --scenario bench, no perftest/@benchmark harness); the PR claims no numbers and changes no kernel
Size: 1312 lines / 13 files — over the review bar
Design (advisory): SPLIT — the natural seams: the chip_info.get_gpu_model move + comm_fused_moe_host dedup; the tuned_mha_fwd schema/loader + jit/core config property + empty CSV; the mha.py dispatch threading + lookup + tests + CI lists
Human: recommend yzhou103 review whether PR #5762's tuned-row contract — the gpu_model fallback order, the decline-to-auto-select-without-FlyDSL fallback, and a MHA_FWD_BACKENDS set that must grow with every new backend (main's mha_v4 today) — is the right policy for the #6580 tuner that will write the rows
📝 [verified] op_tests/tuning_tests/test_mha_fwd_dispatch.py's TestMhaVarlenForward mocks mha.get_gfx but not mha._IS_GFX1250_ASM_DEVICE, so on a gfx1250/MI450 box the metadata-only _select_gfx1250_fmha_fwd_varlen_asm returns the BF16 constant for the CPU dummies and dispatch reaches the real fmha_fwd_with_sink_varlen_asm — the "CPU-only tests" claim holds only on non-gfx1250 boxes (today's matrix runs them on gfx950/gfx942). Author must also mock _IS_GFX1250_ASM_DEVICE, as op_tests/test_mha_optional_flydsl.py's namespace already does.
📝 [verified] The PR's one admitted runtime cost — the 31-cell key construction in aiter/ops/mha_fwd_policy.py on every eager matching call once rows exist — ships with no measurement, and the test target exposes no benchmark entry point, so eager callers (vLLM's opaque-op path) cannot know the per-call price before #6580 turns the rows on. Reviewer should ask the author for a per-call number, or where #6580 measures it, before rows land.
1 finding(s) posted inline, on the lines they are about:
aiter/ops/mha.py:3696— The diff no longer applies to the merge target
| S_dmask = torch.empty((0,), dtype=torch.float32, device=q.device) | ||
| rng_state = torch.empty((2,), dtype=torch.int64, device=q.device) | ||
| elif gfx1250_asm == _GFX1250_VARLEN_ASM_FP8: | ||
| elif selected_backend in (None, "asm_v3") and ( |
There was a problem hiding this comment.
git apply fails at aiter/ops/mha.py:3696 — and the conflict sits inside the exact dispatch chain this PR re-gates: main added the elif can_impl_fmha_v4_thd(): branch (#8704) between the gfx1250 FP8 branch and the fmha_v3 branch, that branch checks no selected_backend, and MHA_FWD_BACKENDS in aiter/ops/mha_fwd_policy.py has no mha_v4 entry, so after the forced rebase a row pinning ck for a gfx950 hd256 bf16 GQA varlen call (a shape only mha_v4 serves) would silently run mha_v4 instead of the row's backend, and no row can ever pin the backend auto-select chooses there. Author must rebase and extend the selected_backend in (None, <name>) gating — and MHA_FWD_BACKENDS, or an explicit decline — to the mha_v4 branch.
On an exact match in
aiter/configs/tuned_mha_fwd.csv,flash_attn_varlen_funcruns the backend the row names:asm_v3,ck,opusorflydsl. On a miss it runs today's auto-select. The CSV ships empty, so nothing changes until a row is written to it; #6580 writes the rows and adds Triton and Gluon rows.Stack. main → #5762 (this) → #6580 → #5849. Builds on #5846 (merged). No kernel changes and no Triton code: a
tritonorgluonrow is an unknown backend here and is skipped.How
gfx,gpu_modelandcu_num. A row names only a backend; each backend keeps its own configs.gpu_modelkeeps MI300X and MI325X rows apart: both are gfx942 with 304 CUs, but MI325X has faster memory.chip_info.get_gpu_model(first commit, moved here from [CK] [CI] [JIT] [Tuning] Per-candidate faults, selection proof and auto-select in --compare #5846) reads it from the HIP device name or, for the gfx950 parts an older libdrm leaves unnamed, from the PCI product ID (subsystem_device, thendevice) as upstreamamdgpu.idslists it.comm_fused_moe_hostnow calls it instead of keeping its own copy of the PCI table. [Triton/Gluon] [JIT] Identify MI350P, and stop hardcoding the XCD count #5182'sget_device_name()names families (MI300 covers MI300X and MI325X), so it can't serve as the key.gpu_modelblank (or a table without the column), which are valid for every model with thatgfxandcu_num. Failing those, it uses another model's rows with the samegfxandcu_num(the alphabetically first, logged once). So it is never worse off than with a table without the model key. A model with rows of its own uses only those.unknownis refused: it means the tuner could not tell the model.cu_seqlens_*_padded) or a paged KV cache (block_table) are keyed. For those,q.shape[0]andk.shape[0]count physical rows or KV-pool blocks rather than tokens, so such rows are rejected at load and such calls skip the lookup; they run auto-select as today. Padded rows are not planned: the real token count lives incu_seqlens_q[-1]on the GPU. Paged rows need a key that does not depend on the pool size and will get their own PR.Trade-offs
fullgraph=Trueon the second token count, and recompiled per token count without it. vLLM on ROCm calls aiter attention inside an opaque custom op (unified_attention_with_output), so the lookup runs eagerly there, and HIP graph capture still runs the row.Overlaps. #6893 (varlen calls with a sink go to CK), #5223 (single-sequence calls go to OPUS), #5910, #7214 (merged; FP8 descales for FlyDSL varlen, same FlyDSL gate, kept as main has it), #7487 (merged; one gfx1250 varlen ASM gate, which an
asm_v3row may take and any other row skips), #7584 (merged; OPUS varlen gained D=128 behindAITER_ENABLE_FMHA_OPUS, so anopusrow serves hd128 only where that flag is set) and #6767 (gfx1250-strict plumbing inmha.pyandcore.py) touch the same code.asm_v3split-KV rows follow once #5592 merges.Size. 12 files, +1,212 / −42 (about 555 lines of tests). Owners: @valarLip; @yifehuan / @charlieguo1106 for the
comm_fused_moe_host.pychange. Builds on @amd-yashagar's #5592.PR Self-Review
Reviewed revision
324a374cbBehavior and intent
flash_attn_varlen_funclooks up an exact-match row intuned_mha_fwd.csvand runs the backend it names (asm_v3,ck,opusorflydsl); on a miss it auto-selects exactly as today. Rows are keyed on the problem plusgfx,gpu_modelandcu_num. A GPU whose model has no rows uses rows without a model, then another model's rows with the samegfxandcu_num. A row the call can't honour warns once and falls back to auto-select. The shipped CSV is empty, so nothing changes until rows are written (#6580).Validation and unverified scope
Head
324a374cb(mainbf5994891merged in, which includes #5846 and #8313), one MI350X (gfx950):python3 -m unittest op_tests.tuning_tests.{test_mha_fwd_dispatch,test_csv_validation,test_config_shape_collision,test_dispatch_verification,test_tuner_infra}: all 132 passed.python3 -m pytest op_tests/test_mha_optional_flydsl.py: all 6 passed. Main passes them too;7c6726630failed the twoflash_attn_varlen_funccases.gpu_modelPCI-ID fallback now also maps MI300X (0x74A1, VF0x74B5) and MI325X (0x74A5, VF0x74B9), from ROCm'samdgpu.idsandmi_gpu_spec.yaml. The MI308 IDs stay out.opustest fails against the hd192-only gate main had before [HIP] [Feature] Add group/varlen and sliding-window support to the hd128 opus forward #7584.Unverified:
get_gpu_modelwas checked on MI355X only, where the HIP device name identifies it; the PCI-ID lookup is unit-tested only. MI300X vs MI325X was not run (no access to both).PR-specific question
The
.github/changes only addop_tests/tuning_tests/test_mha_fwd_dispatch.pyto existing test lists:split_tests.sh(run byaiter-test.yaml'ssplit_aiter_testsjob underpull_request, notpull_request_target, so fork code gets a read-only token and no secrets) and theunittestcommand intuning-tests.yaml, which runs only onscheduleandworkflow_dispatch. No trigger, permission, secret or runner changes.Changed op tests
test_mha_fwd_dispatch.py(new): the lookup and dispatch this PR adds, with backends mocked. It covers one key shared by a call and its row, bad and duplicate rows, other hardware or head dims, a multi-archGPU_ARCHSbuild, a call withhow_v3_bf16_cvt=None, thegpu_modelfallback (a model without rows, rows without a model, a table without the column, a model with its own rows), padded and paged calls skipping the key, compiled callers, a declined row falling back to auto-select (including anopusrow on hd128 with and withoutAITER_ENABLE_FMHA_OPUS), and the public op reaching the pinned forward. Nothing else tests this code.test_tuner_infra.py(extended):TestGpuModelKeyforchip_info.get_gpu_model: products that share an arch get distinct models, a device name without a model falls back to the PCI product, the PCI lookup preferssubsystem_deviceoverdevice, and the gfx942 IDs map MI300X and MI325X (VFs too) but no MI308 ID.test_csv_validation.py(extended):test_mha_fwd_runtime_schema: the shippedtuned_mha_fwd.csvhas exactly the runtime columns, no duplicate keys, and every row loads.test_mha_optional_flydsl.py(two stubs): the test runsflash_attn_varlen_funcin its own namespace. That namespace now stubsget_mha_fwd_tuned_backendandrecord_mha_fwd_selection, the two policy names this PR adds to the function. Its checks do not change.README.md: liststest_mha_fwd_dispatch.py. Documentation only.