Repository navigation
Support k_wave for fp4 gemm1 and tune for dsv3 v4 - #3825
Merged
Merged
Conversation
Stage1+stage2 mixed fp4/fp8 MoE GEMM kernel builders. No behavior change:
- remove dead dtype branches (f16-a/f16-b/int4/int8); a16wi4 lives in
moe_gemm_2stage.py, so this file only ever sees a/b in {fp4,fp8}
- hardcode env flags to defaults (FLIR_CK_LDS128 -> pad_k=0; STAGE1/2_CSHUFFLE
-> cshuffle on); drop dead _if_then + unused os/contextmanager imports
- strip comments 410->16, docstrings to one line
- scope-aware underscore-prefix rename of 492 locals (ast-based; import
aliases / attributes / kernel-name string tags left intact)
Validated 48/48 byte-exact on cold flydsl recompile across
{a4w4,a8w4,a8w8} x {sep,interleave} x {kw1,kw2} x out x async.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
The cross-wave reduction scratch in mixed_moe_gemm_2stage stage1 reuses the X/out LDS buffer (sized ~k_wave*tile_m*tile_k) but needs k_wave*tile_m*tile_n*4 bytes. For tile_n=128 with k_wave>1 (e.g. t32x128x256_kw2) the scratch overruns into lds_tid, corrupting the token/scale row indices read by the cshuffle epilogue. The existing cap (num_n_waves*k_wave<=8) bounds thread count, not the scratch size, so the autotuner could enumerate and select the broken config. Add a 4*tile_n<=tile_k guard so the reduction scratch always fits the buffer. Shipped tuned configs only use t32x32/t32x64 kw (all satisfy the guard); this just removes the latent t32x128_kw>1 candidates from future tuning. tile_k=512 with tile_n=128 stays allowed. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…e_gemm_2stage Resolves the failing Black and Ruff CI style checks: reformat to Black default and drop nine F841 unused local assignments flagged on PR-changed lines (state, inter_dim_valid, two pad_k, pipe_m_repeat_packed, num_threads_per_quant_blk, c8_i32, row_stride_bytes_i32, OOB_safe_i32). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…4 small-M - Remove dsv4 a4w4 tuned/untuned fmoe CSVs. The a4w4 path for dsv4 (model_dim 7168, inter 256/384, E385/tk7) produces garbage output under the strict-accuracy + AOT-cache check in test_moe_2stage and offers no perf benefit over a8w4; dropping the CSV removes those rows from the merged tuned_fmoe.csv so the accuracy test no longer exercises them. - Re-tune dsv4 a8w4 (dsv4_fp8fp4) small-M tokens 1,2,4,8,16 for inter 256 (4096/E256/tk6) and inter 512 (E384/tk6); all 10 shapes improve -2.2%..-29.5% with k_wave (kw2/kw4) kernels now selected. - Re-tune kimi a4w4 (kimik2_fp4) small-M tokens 1,2,4,8,16 for inter 256 & 512 (E384/tk8 and E385/tk9); 15/20 shapes improve -1.2%..-25%, the rest kept (no regressions). New k_wave kernels also drop stage1 quant error from ~20% to ~0%. Edits are applied in place (existing column layout preserved); only the re-tuned rows change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- dsv3_fp4: revert the gfx-column format migration so the file stays in main's cu_num layout; only the 12 genuinely re-tuned low-conc flydsl winner rows (M=1,2,4,8,16,32 x inter 256/512) differ from main. All other winner rows, every fallback row, and dropped rows are restored identical to main. - kimik2_fp4: revert the flydsl_fallback rows to main. Only the flydsl winner version was tuned, so the CK fallback kernels should be unchanged. Net diff vs main is now winner-only: dsv3 12 rows, kimi 15 rows, dsv4 10 rows. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The dsv4 a8w4 small-M re-tune selected `flydsl_moe1_afp8_wfp4_..._t32x32x256_*_kw4` kernels for inter256 M1/M2 and inter512 M1. These have stage1 err ~11% (vs ~0% for every other a8w4 kernel) and fail the strict-accuracy + AOT-cache check in test_moe_2stage (err=0.99 end-to-end). The k_wave-4 path at tile_n=32 is broken for the fp8-activation (a8w4) case; the loose tuner errRatio (0.5) let them through. Since test_moe_2stage aborts on the first failing assert, dropping dsv4 a4w4 merely unmasked these. Revert those 3 rows to main's accurate kernels (err1=0%). The other 7 re-tuned a8w4 rows (err1=0%) and all a4w4 (dsv3/kimi) k_wave rows are unaffected — the bug is specific to a8w4 + tile_n=32 + kw4. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ll-M Root cause: the fp8/a8w4 stage1 path uses gate-up interleave, whose cross-wave k_wave reduction is the *non-fused* variant. That reduction is only correct with >=2 N-waves; at tile_n==32 (num_n_waves==1) it produces wrong results (~11% stage1 error end-to-end), which the loose tuner errRatio (0.5) accepted. The fp4/a4w4 (separated) path uses the fused reduction and is correct at tile_n==32, so this is fp8-specific. Fix: in get_flydsl_stage1_kernels, skip k_wave>1 when a_dtype=='fp8' and num_n_waves<2 (tile_n==32). a4w4 tile_n=32 k_wave is unaffected. Re-tune the 3 affected dsv4 a8w4 rows (inter256 M1/M2, inter512 M1): with the guard the tuner now picks accurate k_wave kernels at tile_n=64 (err1=err2=0.0%), which are still faster than main's non-k_wave kernels. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Cursor <[email protected]>
rbrugaro-amd
added a commit
to rbrugaro-amd/aiter
that referenced
this pull request
Jun 23, 2026
…tuned set Replace the (33,9) tuned rows with the set validated (best measured E2E) on the DeepSeek-R1 MXFP4 harness. The fused flydsl `_fp4` stage-1 was being missed by the tuner due to a fused-vs-non-fused selection bug (fixed in ROCm#3805); it is now picked at the larger token buckets. Small-token buckets intentionally keep the non-fused kernel where it benchmarked better E2E, so stage-1 is a mix of fused/non-fused by design. Non-(33,9) rows untouched (match main after ROCm#3825 dsv3-v4 retune). 16 primary + 16 flydsl_fallback rows, 26-col schema. Signed-off-by: Rita Brugarolas Brufau <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]>
Rohan138
added a commit
to Rohan138/aiter
that referenced
this pull request
Jul 9, 2026
…-V3/R1 (gfx950) DeepSeek-R1-0528-MXFP4 calls the fused MoE with 256 routed experts / topk=8 (the shared expert is handled separately by the serving framework), but dsv3_fp4_tuned_fmoe.csv keys the tuned FlyDSL entries at expert=257/topk=9 (256 routed + 1 shared). On gfx950 the runtime lookup misses and falls back to the slow FlyDSL heuristic -- ~8% E2EL regression at low concurrency (ROCM-25536; ROCm#3909). Add expert=256/topk=8 entries for the model_dim=7168 routed-expert shapes (inter_dim 256 [TP8] and 512 [TP4], all token buckets) by re-keying the existing tuned rows. Expert count does not change the per-expert GEMM shape, so the tuned kernel selection is unchanged; the rows now reflect the k_wave fp4 gemm1 kernels from ROCm#3825 and the fallback-hint cleanup from ROCm#4025. Perf/accuracy validated earlier on MI350X/gfx950, vLLM 0.21.0, DSR1-MXFP4 TP8 (pre-ROCm#3825 kernels): ck_moe_2stages token=1 43->30us; serve E2EL conc1 10846->9987ms; gsm8k 5-shot 0.965. Re-validation on the ROCm#3825-retuned kernels is advisable. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Rohan138 <[email protected]>
valarLip
pushed a commit
that referenced
this pull request
Jul 11, 2026
…-V3/R1 (gfx950) (#3911) DeepSeek-R1-0528-MXFP4 calls the fused MoE with 256 routed experts / topk=8 (the shared expert is handled separately by the serving framework), but dsv3_fp4_tuned_fmoe.csv keys the tuned FlyDSL entries at expert=257/topk=9 (256 routed + 1 shared). On gfx950 the runtime lookup misses and falls back to the slow FlyDSL heuristic -- ~8% E2EL regression at low concurrency (ROCM-25536; #3909). Add expert=256/topk=8 entries for the model_dim=7168 routed-expert shapes (inter_dim 256 [TP8] and 512 [TP4], all token buckets) by re-keying the existing tuned rows. Expert count does not change the per-expert GEMM shape, so the tuned kernel selection is unchanged; the rows now reflect the k_wave fp4 gemm1 kernels from #3825 and the fallback-hint cleanup from #4025. Perf/accuracy validated earlier on MI350X/gfx950, vLLM 0.21.0, DSR1-MXFP4 TP8 (pre-#3825 kernels): ck_moe_2stages token=1 43->30us; serve E2EL conc1 10846->9987ms; gsm8k 5-shot 0.965. Re-validation on the #3825-retuned kernels is advisable. Signed-off-by: Rohan138 <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
valarLip
pushed a commit
that referenced
this pull request
Aug 5, 2026
#3739) * configs: add DSv3-MXFP4 E=33/topk9 fused-MoE shape (shared-expert fusion) The existing dsv3_fp4 fused-MoE configs cover the routed-only shapes (model_dim=7168, inter_dim=2048, expert in {32,64}, topk=8) and the EP-sharded shapes (inter_dim in {256,512}, expert=257, topk=9). There is no entry for model_dim=7168, inter_dim=2048, expert=33, topk=9. That shape appears with shared-experts fusion ON: the always-on shared expert is folded in as the 33rd grouped-GEMM expert and topk goes 8 -> 9, so every token routes through it. With no tuned row the runtime fmoe dispatch MISSes and falls back to the generic ck::kernel_moe_mxgemm_2lds for BOTH stages, which is ~3x slower on stage2 than the flydsl/cktile kernels that already exist for the neighbouring shapes. Adds 32 rows (16 token buckets 1..32768, each a primary best-us row plus a flydsl_fallback row) to dsv3_fp4_tuned_fmoe.csv, and the 16 matching input rows to dsv3_fp4_untuned_fmoe.csv. The buckets are the contiguous powers of two (1,2,4,...,32768) that the runtime's nextPow2 token padding can request, so there is no cache-miss gap. Same FP4X2 x FP4X2 x BF16 + per_1x32 dtype combo as the existing dsv3 rows. Data produced by gemm_moe_tune.py end-to-end on 8x MI355X (gfx950, cu_num=256), aiter v0.1.14-rc0-209-g6740fb791. Signed-off-by: Rita Brugarolas Brufau <[email protected]> * configs(dsv3 mxfp4): update E=33/topk=9 stage-1+stage-2 to validated tuned set Replace the (33,9) tuned rows with the set validated (best measured E2E) on the DeepSeek-R1 MXFP4 harness. The fused flydsl `_fp4` stage-1 was being missed by the tuner due to a fused-vs-non-fused selection bug (fixed in #3805); it is now picked at the larger token buckets. Small-token buckets intentionally keep the non-fused kernel where it benchmarked better E2E, so stage-1 is a mix of fused/non-fused by design. Non-(33,9) rows untouched (match main after #3825 dsv3-v4 retune). 16 primary + 16 flydsl_fallback rows, 26-col schema. Signed-off-by: Rita Brugarolas Brufau <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Signed-off-by: Rita Brugarolas Brufau <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
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.
Summary
Three changes to the FlyDSL mixed fp4/fp8 MoE GEMM path:
k_wave (intra-block K-slice) for fp4 gemm1. At small M (≤32) the
tile_m=32blockstarves the CU; k_wave splits the K reduction across 2/4 cooperating waves to raise
occupancy. Enumerated only for
tile_m==32(no split-K / mock-gate), capped to ≤8 waves /≤512 threads, with the reduction scratch required to fit LDS (
4·tile_n ≤ tile_k). Exposed asa
_kw{N}kernel suffix and plumbed through the candidate generator,compile_flydsl_moe_stage1/flydsl_moe_stage1, AOT,fused_moe, and the tuner. Guardedoff for
fp8 & tile_n==32, where the non-fused k_wave reduction is wrong with <2 N-waves(~11% error) and was failing the strict-accuracy + AOT-cache check.
Re-tune low-concurrency configs; drop dsv4 a4w4. dsv3 (a4w4), dsv4 (a8w4) and kimi
(a4w4) M≤32 re-tuned in place (keep-better merge — only faster shapes updated, high-M rows
unchanged). dsv4 a4w4 removed: it produces garbage under strict-accuracy + AOT-cache and
offers nothing over a8w4.
Clean up
mixed_moe_gemm_2stage.py(5385→4833 lines): dead dtype branches, env flags,comments, scope-aware local renames. No behavior change — byte-identical compiled output
across 48 configs (cold recompile).
Performance — gemm1+gemm2 µs reduction
Best gemm1+gemm2 µs without this PR (no
_kwkernel) vs with it, from the same profile run(idle gfx950, 256 CU, accuracy-filtered). The gain is entirely in gemm1; gemm2's best kernel
is unchanged. Concentrated at M≤4, ~neutral by M≥8.
dsv3 a4w4 —
md7168, E257, topk9dsv4 a8w4 —
fp8·fp4kimi a4w4 —
md7168µs reduced, gemm1+gemm2 combined. "–" = re-tune didn't beat the existing kernel, old row kept
(no regressions).
Files
aiter/ops/flydsl/moe_kernels.pyaiter/ops/flydsl/kernels/mixed_moe_gemm_2stage.pyaiter/aot/flydsl/moe.py,aiter/fused_moe.py,csrc/.../gemm_moe_tune.pyaiter/configs/model_configs/{dsv3_fp4,dsv4_fp8fp4,kimik2_fp4}_tuned_fmoe.csvaiter/configs/model_configs/dsv4_fp4_{tuned,untuned}_fmoe.csvValidation
test_moe_2stage.