Repository navigation
fix(fmoe tune): dedup fused/non-fused stage1 separately - #3805
Conversation
…t dropped pre-penalty FmoeTuner.post_process dedups candidates to the best per (stage, block_m, flat) by RAW us BEFORE the quant-fairness penalty is applied to non-fused stage1 kernels. A fused (_fp4/_fp8) stage1 kernel embeds the inter-stage quant+sort in its epilogue, so its raw us is slightly higher than an otherwise-equivalent non-fused kernel at the same block_m. With both sharing the dedup key, the fused candidate is evicted in the dedup pass; the penalty that would make it win (the separately-benchmarked dynamic_mxfp4_quant+sort cost, added only to non-_fp4/_fp8 us1) is applied afterwards, to a pool the fused kernel is no longer in. Result: the tuner systematically under-selects fused stage1 kernels for a4w4/a8w4 MoE and ships CK/non-fused configs even when fusion is faster on a fair (quant-credited) basis. Fix: add an _is_fused flag (kernelName endswith _fp4/_fp8) to the dedup key so the best fused AND best non-fused per (stage, block_m, flat) both survive into the penalty + final idxmin(us1+us2) selection. The drop column is removed immediately so downstream merge/columns are unchanged. No behavior change for shapes without fused candidates. Validated on DeepSeek-R1 MXFP4 shared-expert-fusion shape (expert=33, topk=9, 7168/2048): re-tuning flips the >=2048 token tiers from CK to fused flydsl stage1; a cuda-graph BS=256 decode bench shows ~6% lower latency / higher throughput vs the CK selection. Co-Authored-By: Claude Opus 4.8 <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
…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]>
|
@valarLip could you please review this PR? |
…-fused-dedup-fix # Conflicts: # csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py
|
Rebased onto latest main and re-tuned the DeepSeek-R1 MXFP4 shared-fusion shape (expert=33, topk=9, 7168/2048, per_1x32) to confirm the selection change still behaves. The ≥2048 tiers still flip CK → fused flydsl stage1 with this patch; reverting just the _is_fused dedup key sends 2048 back to a CK 2-stage kernel (the fused candidate is present in the profile but evicted in the pre-penalty dedup — the exact issue this PR fixes).
|
lalala-sh
left a comment
There was a problem hiding this comment.
Please simplify the code comments.
Address review feedback on ROCm#3805 (lalala-sh): trim the 6-line comment on the fused/non-fused dedup split to 3 lines while keeping the rationale (non-fused-only fairness penalty must not be pre-empted by raw-us dedup). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Rita Brugarolas Brufau <[email protected]>
|
@lalala-sh addressed your feedback |
|
@lalala-sh @ROCm/team_aiter test passed and is approved, can we merge please? |
Done, thanks for your contribution. |
#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]>
Problem
FmoeTuner.post_process under-selects fused (_fp4/_fp8) stage-1 kernels for a4w4/a8w4 MoE, shipping CK/non-fused configs even when fusion is faster on a fair basis.
Root cause
Selection runs in two passes:
Dedup to the best candidate per (stage, block_m, flat) by raw us.
Quant-fairness penalty: the separately-benchmarked dynamic_mxfp4_quant+sort cost is added to the us1 of every non-_fp4/_fp8 stage-1 (fused kernels embed quant+sort in the epilogue, so it's already in their us1).
A fused stage-1 does that extra quant work in-kernel, so its raw us is slightly higher than an equivalent non-fused kernel at the same block_m. Since both share the dedup key, the fused candidate is evicted in pass 1 — before the pass-2 penalty (which would make it win) is ever applied. The fused kernel is no longer in the pool when idxmin(us1+us2) runs.
Fix
Add an _is_fused flag (kernelName endswith _fp4/_fp8) to the dedup key so the best fused and best non-fused per (stage, block_m, flat) both survive into the penalty + final selection. Helper column dropped immediately; downstream merge/columns unchanged. No effect on shapes without fused candidates.
Validation
DeepSeek-R1 MXFP4 shared-expert-fusion shape (expert=33, topk=9, 7168/2048): re-tuning flips the ≥2048 token tiers from CK to fused flydsl stage-1. A cuda-graph BS=256 decode bench shows ~6% lower latency / higher throughput vs the CK selection
Risk
Low — pure selection-logic change in the offline tuner; no kernel/runtime changes. Shapes with only non-fused candidates are unaffected.