Repository navigation
[HIP] [FlyDSL] tune bmm and mxfp8 together ,update related tuned csv - #7439
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
NOT READY FOR HUMAN REVIEWPR 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 |
There was a problem hiding this comment.
🟡 Changes recommended
The new gfx950 dispatch routes FP16 outputs to a BF16-only BMM kernel, causing previously supported FP16 calls to fail with “Out must be bf16”.
1 open issue
What changed in this PR
This PR adds batched GEMM at batch size 1 as a tuning and dispatch option for gfx950 MXFP8 GEMM, alongside the existing FlyDSL kernels.
Changes:
- Expands tuning to compare BMM candidates seeded from related tuned tables.
- Adds runtime dispatch and ahead-of-time compilation support for BMM-selected rows.
- Updates MiniMax M3 and DSv4 model tuning tables.
| File | Description |
|---|---|
csrc/gemm_a8w8_mxfp8_bpreshuffle/gemm_a8w8_mxfp8_bpreshuffle_tune.py |
Adds BMM candidates and records winning backend identifiers. |
aiter/ops/gemm_op_a8w8.py |
Routes tuned gfx950 BMM selections through the batched GEMM wrapper. |
aiter/configs/model_configs/minimax_m3_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv |
Updates MiniMax M3 kernel selections and timing data. |
aiter/configs/model_configs/dsv4_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv |
Updates DSv4 kernel selections and timing data. |
aiter/aot/flydsl/gemm.py |
Handles table-specific scale-block defaults for BMM compilation jobs. |
Review effort: Balanced
|
@copilot resolve the merge conflicts in this pull request |
# Conflicts: # aiter/aot/flydsl/gemm.py Co-authored-by: solinzby1 <[email protected]>
Merged |
There was a problem hiding this comment.
🔵 Needs a closer look
AOT generation and --check omit the gfx1250 preshuffled-A-scale specialization and supported FP16 variants, leaving kernel specializations and fallback paths uncovered.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
- moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main. - gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841). - test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26. - aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001). Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity). Signed-off-by: Wulley <[email protected]>
- moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main. - gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841). - test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26. - aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001). Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity). Signed-off-by: Wulley <[email protected]>
- moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main. - gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841). - test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26. - aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001). Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity). Signed-off-by: Wulley <[email protected]>
- moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main. - gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841). - test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26. - aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001). Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity). Signed-off-by: Wulley <[email protected]>
- pre-checks.yaml: pin black to 26.10.1 (the version that psf/black@stable installs now) with the action `version` input. - pre-checks.yaml: replace the deprecated -fail-on-error with -fail-level=any. For the github-check reporter (push to main), -fail-on-error maps to error level, and ruff reports every finding as WARNING, so the job never failed on main. - aiter/aot/flydsl/gemm.py: restore mode 100755 (lost in ROCm#7439). The file has a shebang, and ruff EXE001 reports it on main. - bench_models.py: fix ruff I001 (import order). ROCm#6728 added the bench_moe_gemm_a4w4 and bench_moe_gemm_a8w4 modules, so ruff now sorts their imports as first-party. Move only these 6 lines (ruff autofix). - CONTRIBUTE.md: install the CI versions (black 26.10.1, ruff 0.16.0). Refs ROCm#4423
* [Test] test_moe_ep: add SiTUv2 A8W4 EP support and per-rank routing stats - Add -a/--activation, --beta and --linear-beta to the mxfp4 EP tests and pass beta/linear_beta through to fused_moe (defaults 4.0/25.0). - gfx950 a8w4: set AITER_SITUV2_A8W4=1 so SiTUv2 runs with fp8 activations instead of the a16w4 path, which rejects expert_mask; the a4w4 path clears it again. - Reference: reuse the quantized-activation path (previously gfx1250 a4w4 only) for a8w4 SiTUv2, quantizing both activations to fp8 with e8m0 scales; torch_moe has no SiTUv2. - SiTUv2 accuracy follows test_moe_2stage: fail only when checkAllclose mismatches and logits_diff exceeds 0.01. - Print local_routes / active_experts once before timing. It draws no random numbers and stays outside the timed fused_moe call, so inputs and timing are unchanged. * [FlyDSL] [MoE] Support EP for MXMOE GEMM1 with layout-v2 GEMM2 Port #7284 (00527e5) and cover the a8w4 SiTUv2 pairing used by Kimi K3 EP32. - get_2stage_cfgs: keep MXMOE rows under EP when GEMM2 is a flydsl_moe2_layout_ kernel. Skip the NE-keyed aux shape check there, since expert is the local count; only the scatter epilog still needs a generated scatter_reduce instance for (model_dim, topk). - _mxfp4_inline_sort_unsupported: accept expert_mask and skip the adaptive-sort instance check, since EP sorts with Opus. - _fused_moe_impl: raise NotImplementedError under EP only for native MXMOE GEMM2. - _mxfp4_a4w4_stage2_fw: forward expert_mask/topk_ids to the layout-v2 wrapper. Without them the reduce epilog sums unwritten remote-route slots. - op_tests/test_moe_mxmoe_ep.py: the PR's a4w4 tests, plus a8w4 SiTUv2 cases at Kimi K3 dims (BM32/64/128 x atomic/reduce, with and without a num_local_tokens dead tail) against an FP8-quantized torch reference, with NaN-filled stage2 buffers. * [FlyDSL] [MoE] Support A8W4 and real EP routing in tuners Add A8W4 candidate generation, activation quantization and gate/up layouts to the coupled MXFP4 tuner. Model real EP routing in the standard layout-v2 and coupled tuners, including route-stat matching, masked sorting, valid token bounds and local-expert references. Cover precision contracts and EP candidate selection with CPU unit tests. Signed-off-by: Wulley <[email protected]> * [Test] Fix A4W4 SiTUv2 reference and dtype selection in EP CLI Use the existing FP4-quantized two-stage reference for gfx950 A4W4 SiTUv2 instead of torch_moe, which does not implement SiTUv2. Set the A4W4 activation opt-in and clear the opposite precision flag when switching A4W4/A8W4. Add native CLI regression cases for real/fake EP modes and default/custom beta values. Validation: 7 dispatch checks and 4 CLI regression cases passed. A8W4 SiTUv2 and Kimi K3 EP32 with BM32 also passed the existing SiTUv2 criterion. The additional EP32 BM16/persist run stalled at GPU synchronization and was terminated; it is not counted as passing. Signed-off-by: Wulley <[email protected]> * [FlyDSL] [MoE] Use bench balanced routing for EP tuning data Replace the independent random EP routing of the layout-v2 and coupled tuners with the balanced routing of amd_moe_bench_share/bench_moe.py: tokens take topk experts at a time from a stream of random global-expert permutations, so every token picks distinct experts and global expert loads differ by at most one. When the global expert count is a multiple of topk the ids equal the bench's for the same seed; other topk/EP combinations skip experts that a permutation-spanning token already holds. Simulate EP rank 0 with 1/topk route weights, keep the test_moe_ep real-mode dispatch layout, and route padding rows to the masked extra slot so they stay inert. Replace --ep-route-match and its seed search with --ep-seed. Validation: ids and rank-0 route stats equal bench make_input() on 104 divisible cases; 49 non-divisible cases keep distinct experts per token and a global spread of at most one. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity). Kimi K3 A8W4 EP16/EP64 coupled tunes completed, and all 72 test_moe_ep real-mode cases with the tuned configs passed. Signed-off-by: Wulley <[email protected]> * [FlyDSL] [MoE] Keep MXMOE GEMM1 payload stores on 32-bit lane offsets #6464 moved the GEMM1 payload store offset to i64 so sorted payloads above 2 GiB cannot sign-wrap. Every lane then carries 64-bit store addresses, which raises the k_wave=2 (8-wave) A8W4 variant from 128 to 136 VGPRs and halves its resident workgroups per CU. Store through a buffer resource based at the block's first sorted row instead: the base is i64 and wave-uniform, and each lane keeps an i32 byte offset below BM * OUT_ROW_BYTES (asserted at compile time). The FP8 dword pair becomes one 2xi32 buffer store; FP4 stores one dword. Validation: the kw2 GEMM1 drops to 112 VGPRs (nt_xcd2 130 -> 126), with no spills and unchanged LDS. On 2.25 GiB A8W4 and A4W4 payloads (87k and 175k rows past 2 GiB), every valid row matches the i64 store bit for bit, while the earlier i32 store faults. test_moe_mxmoe_ep.py: 31 passed. On Kimi K3 inputs the kw2 GEMM1 is 7-8% faster than with the i64 store and 3% faster than before #6464, and test_moe_ep EP32 M=3/4 fmoe is 3.9%/4.0% faster. Signed-off-by: Wulley <[email protected]> * [MoE] Add Kimi K3 A8W4 EP16/EP32/EP64 MXMOE rows to the tuned fMoE config Add the coupled MXMOE (GEMM1 + layout-v2 GEMM2) rows that real-mode EP16/32/64 runs look up for per-rank batch 1-16 x qlen 1/4/8: lookup tokens EP * {1, 2, 4, ..., 128} with expert = 896 / EP local experts, at topk 16 and 17 (identical except topk; 17 carries the masked column). 48 rows are appended; the existing rows are unchanged. The rows come from the EP tuned configs of the coupled tuner; EP16 lookup 256 and EP32 lookup 128 use the k_wave=2 GEMM1, which assumes the preceding payload-store fix. Validation: the merged tuned_fmoe has no duplicate keys. test_moe_ep.py real mode without AITER_CONFIG_FMOE passes and hits the new rows for EP32 M=1/4/128, EP16 M=1/16/128 and EP64 M=1/128. Signed-off-by: Wulley <[email protected]> * [MoE] Fix black and ruff findings on the EP32 branch - moe_mxfp4_aux.py: drop the second is_mxfp4_moe_scatter_supported left by the rebase onto #6464, which defines the same check (ruff F811). The file now matches origin/main. - gemm_moe_tune.py: sort the mxfp4_v2_tune_utils import (I001), and drop the expert-inter and token locals that _time_pair and _check_reference_pair no longer use since they build data through _case (F841). - test_moe_mxmoe_ep.py: pass check=False to the CLI subprocess.run, whose return code the test asserts with the captured output (PLW1510), and apply black 26. - aiter/aot/flydsl/gemm.py: restore the executable bit that #7439 dropped; the script keeps its shebang and __main__ like the other FlyDSL AOT scripts (EXE001). Validation: ruff 0.16.0 `ruff check .` passes; black 26.10.1 passes on the changed files and on `black .`. test_fast_tuning.py and test_moe_mxmoe_ep.py: 88 passed, 1 pre-existing failure (local flydsl lacks check_smem_capacity). Signed-off-by: Wulley <[email protected]> * [MoE] Add Kimi K3 A8W4 EP16/EP32 token-8192 MXMOE rows and group the EP rows Add the token-8192 rows for EP16 (expert 56) and EP32 (expert 28), at topk 16 and 17: MXMOE GEMM1 64x256x256_fp8out_situv2 with layout GEMM2 t64x256x128_atomic_sbm64, block_m 64, from the coupled tuner (bench balanced routing, full search). These lookups previously fell back to the default heuristics. EP64 already had the same token-8192 row. Also group the EP rows by EP size (EP16, EP32, EP64; topk 16 then 17, by token); the other rows are unchanged. Validation, against the config without these rows: test_moe_ep.py real mode, global -m 5120/6144/8192, passes, hits the new rows, and cuts fmoe time by 46-56% at EP32 and 39-49% at EP16. amd_moe_bench_share at the same batch sizes cuts FC1+FC2 time by 41-52% at EP32 and 31-44% at EP16. EP64, whose row is unchanged, stays within 0.7%. Signed-off-by: Wulley <[email protected]> * [MoE] Drop the Kimi K3 A8W4 EP16/EP32/EP64 token-8192 rows Remove the token-8192 rows for EP16 (expert 56), EP32 (expert 28) and EP64 (expert 14), at topk 16 and 17, from kimik3_a8w4_tuned_fmoe.csv. Those lookups fall back to the default heuristics again. The EP rows now cover lookup tokens up to 2048 (EP16) and 4096 (EP32, EP64); the other rows are unchanged. Signed-off-by: Wulley <[email protected]> * [Test] test_moe_2stage: skip tuned CSV rows whose topk exceeds the expert count Expert-parallel fMoE rows key on the local expert count, so the Kimi K3 A8W4 EP64 rows carry expert=14 with topk=16/17. The tuned-CSV sweep runs every row as a non-EP MoE with E=expert, where fused_topk cannot pick topk distinct experts and pads the extra slots with duplicate expert-0 routes, so the strict accuracy check fails (logits_diff ~0.17). Skip such rows; runtime config selection is unchanged. * Revert "[Test] test_moe_2stage: skip tuned CSV rows whose topk exceeds the expert count" This reverts commit 42e54f9. Signed-off-by: Liu <[email protected]> * [MoE] Drop EP16/EP64 and EP32 topk-17 Kimi K3 rows Retain the eight newly added EP32 topk-16 configurations and all pre-existing Kimi K3 rows. Signed-off-by: Liu <[email protected]> * [MoE] Restore Kimi K3 EP16 and EP32 topk-17 rows Signed-off-by: Liu <[email protected]> * [Test] Remove MXMOE EP regression test Signed-off-by: Liu <[email protected]> * [MoE] Limit MXMOE under EP to validated SiTUv2 atomic/reduce configs get_2stage_cfgs now accepts MXMOE rows under EP only with SiTUv2 and an atomic or reduce layout GEMM2, and rejects BM16 rows. BM16 sorts through the masked Opus aux sort with dispatch_policy=1, which hangs at >= 819 experts (#8014). Other activations and the scatter epilog are not validated under EP, so they stay rejected as on main. Validation: get_2stage_cfgs over every gfx950 tuned MXMOE row with is_ep=True accepts only the Kimi K3 SiTUv2 atomic/reduce rows. A BM16 EP row falls back to the default heuristics; a non-EP BM16 row is still selected. Signed-off-by: Wulley <[email protected]> * [FlyDSL] [MoE] Skip BM16 GEMM1 candidates when tuning under EP The coupled tuner (--mxfp4-flydsl) still enumerated BM16 GEMM1 candidates for A4W4 under --ep-size, and its M_est pruning kept only BM16 for rows below M_est 4. Those candidates sort through the masked Opus aux sort with dispatch_policy=1, which hangs at >= 819 experts (#8014), and the runtime rejects BM16 under EP anyway. Skip BM16 under EP for both precisions and, as for A8W4, keep every larger BM unpruned. Also fix the scatter comment: the runtime rejects the scatter epilog under EP. Validation: test_fast_tuning.py: 59 passed. The new case checks that an EP32 A4W4 row with M_est 1 gets BM32/64/128 instead of BM16 only, and that a dense A4W4 row still gets BM16. Signed-off-by: Wulley <[email protected]> * [FlyDSL] [MoE] Reject non-SiTUv2 rows when tuning MXMOE under EP get_2stage_cfgs rejects every non-SiTUv2 MXMOE row under EP, but the coupled tuner (--mxfp4-flydsl --ep-size N) still accepted SiLU and SwiGLU rows and ran a full search whose winner inference always discards. Reject them in _unsupported_row_reason, and move the EP CPU tests to SiTUv2 rows. Validation: test_fast_tuning.py: 59 passed. The EP case now also checks that a SiLU row is rejected under EP; it fails without this change. Signed-off-by: Wulley <[email protected]> --------- Signed-off-by: Wulley <[email protected]> Signed-off-by: Liu <[email protected]>
- pre-checks.yaml: pin black to 26.10.1 (the version that psf/black@stable installs now) with the action `version` input. - pre-checks.yaml: replace the deprecated -fail-on-error with -fail-level=any. For the github-check reporter (push to main), -fail-on-error maps to error level, and ruff reports every finding as WARNING, so the job never failed on main. - aiter/aot/flydsl/gemm.py: restore mode 100755 (lost in #7439). The file has a shebang, and ruff EXE001 reports it on main. - bench_models.py: fix ruff I001 (import order). #6728 added the bench_moe_gemm_a4w4 and bench_moe_gemm_a8w4 modules, so ruff now sorts their imports as first-party. Move only these 6 lines (ruff autofix). - CONTRIBUTE.md: install the CI versions (black 26.10.1, ruff 0.16.0). Refs #4423

Summary
Motivation
Changes
Performance (if applicable)
Testing
Documentation
Dependencies
Breaking Changes
PR Self-Review
Reviewed revision
Behavior and intent
Validation and unverified scope
PR-specific question
Changed op tests