Repository navigation
[HIP] [FlyDSL] Register top-k for E % 4 and mixed-dtype bias, a16w4 stage2 reduce mode, tuned tables - #7067
Conversation
…tage2 reduce mode, tuned tables Top-k routing - topk_softmax_kernels_group.cu / warp_sort.h: the register-resident biased top-k path now admits num_experts % 4 == 0 (lanes past the last expert in the final round are masked) and a correction bias whose dtype differs from the gating output (e.g. an fp32 bias with bf16 logits). emit_legacy_ordered_topk ranks the candidates with one per-lane key (score, then legacy tie rank) instead of topk serial ballots. - topk_gating_kernels.cuh: a pad row (num_valid_rows) is written as id -1 / weight 0 and returns before selection. - topk.py: biased_grouped_topk always takes biased_grouped_topk_hip; moe_fused_gate leaves routed_scaling_factor to the caller and measured slower at every row count. MoE - fused_moe.py / moe_kernels.py: the a16w4 (bf16 x MXFP4) stage2 honors the table's reduce mode, as a16wi4 already did; sorting allocates the matching output layout. - gemm_a16w16_gfx950_utils.py: SPLIT_K_SEMAPHORE_MAX_LEN 256 -> 2048, so the fixed buffers stay stable across graph captures and cover larger split-K grids. Tuned tables - kimik3_a16w4_tuned_fmoe.csv: the a16w4 SiTUv2 rows switch stage2 from atomic to reduce with unchanged tiles. Measured on gfx950 (fused_moe, run_perftest): the output becomes bit-reproducible, mean relative error against an FP32 reference drops from 5.1e-3 to 2.8e-3, and time rises 2-6%. - glm53_bf16 / glm53_flash_bf16 tuned GEMM: retuned rows that measured equal or faster keep the new entries; rows that measured slower stay at their current entries.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
…tage2 reduce mode, tuned tables (#7067) Top-k routing - topk_softmax_kernels_group.cu / warp_sort.h: the register-resident biased top-k path now admits num_experts % 4 == 0 (lanes past the last expert in the final round are masked) and a correction bias whose dtype differs from the gating output (e.g. an fp32 bias with bf16 logits). emit_legacy_ordered_topk ranks the candidates with one per-lane key (score, then legacy tie rank) instead of topk serial ballots. - topk_gating_kernels.cuh: a pad row (num_valid_rows) is written as id -1 / weight 0 and returns before selection. - topk.py: biased_grouped_topk always takes biased_grouped_topk_hip; moe_fused_gate leaves routed_scaling_factor to the caller and measured slower at every row count. MoE - fused_moe.py / moe_kernels.py: the a16w4 (bf16 x MXFP4) stage2 honors the table's reduce mode, as a16wi4 already did; sorting allocates the matching output layout. - gemm_a16w16_gfx950_utils.py: SPLIT_K_SEMAPHORE_MAX_LEN 256 -> 2048, so the fixed buffers stay stable across graph captures and cover larger split-K grids. Tuned tables - kimik3_a16w4_tuned_fmoe.csv: the a16w4 SiTUv2 rows switch stage2 from atomic to reduce with unchanged tiles. Measured on gfx950 (fused_moe, run_perftest): the output becomes bit-reproducible, mean relative error against an FP32 reference drops from 5.1e-3 to 2.8e-3, and time rises 2-6%. - glm53_bf16 / glm53_flash_bf16 tuned GEMM: retuned rows that measured equal or faster keep the new entries; rows that measured slower stay at their current entries.
Conflict: gemm_a16w16_gfx950_utils.py, where ROCm#7067 raised SPLIT_K_SEMAPHORE_MAX_LEN to 2048 next to the new GFX950_FLAT_BUFFER_LIMIT_BYTES; both kept.
No conflicts, but main changed code the deployment replay runs through: - #7020: the MXFP4 inline sort takes num_local_tokens and skips expert ids outside [0, E), as the sentinel ids of EP callers are. - #7067: the a16w4 stage-2 reduce mode in fused_moe.py and Kimi-K3's a16w4 table. - #7068, #6668: gfx1250 grouped tables for DeepSeek-V4.1 MegaMoE EP and MiniMax-M3. - #7055: the OPUS CO tests read local kernel IDs; this branch's 1-GPU CI shards failed on the global ones. Co-authored-by: Cursor <[email protected]>
…tage2 reduce mode, tuned tables (#7067) Top-k routing - topk_softmax_kernels_group.cu / warp_sort.h: the register-resident biased top-k path now admits num_experts % 4 == 0 (lanes past the last expert in the final round are masked) and a correction bias whose dtype differs from the gating output (e.g. an fp32 bias with bf16 logits). emit_legacy_ordered_topk ranks the candidates with one per-lane key (score, then legacy tie rank) instead of topk serial ballots. - topk_gating_kernels.cuh: a pad row (num_valid_rows) is written as id -1 / weight 0 and returns before selection. - topk.py: biased_grouped_topk always takes biased_grouped_topk_hip; moe_fused_gate leaves routed_scaling_factor to the caller and measured slower at every row count. MoE - fused_moe.py / moe_kernels.py: the a16w4 (bf16 x MXFP4) stage2 honors the table's reduce mode, as a16wi4 already did; sorting allocates the matching output layout. - gemm_a16w16_gfx950_utils.py: SPLIT_K_SEMAPHORE_MAX_LEN 256 -> 2048, so the fixed buffers stay stable across graph captures and cover larger split-K grids. Tuned tables - kimik3_a16w4_tuned_fmoe.csv: the a16w4 SiTUv2 rows switch stage2 from atomic to reduce with unchanged tiles. Measured on gfx950 (fused_moe, run_perftest): the output becomes bit-reproducible, mean relative error against an FP32 reference drops from 5.1e-3 to 2.8e-3, and time rises 2-6%. - glm53_bf16 / glm53_flash_bf16 tuned GEMM: retuned rows that measured equal or faster keep the new entries; rows that measured slower stay at their current entries.
No conflicts, but main changed code the deployment replay runs through: - #7020: the MXFP4 inline sort takes num_local_tokens and skips expert ids outside [0, E), as the sentinel ids of EP callers are. - #7067: the a16w4 stage-2 reduce mode in fused_moe.py and Kimi-K3's a16w4 table. - #7068, #6668: gfx1250 grouped tables for DeepSeek-V4.1 MegaMoE EP and MiniMax-M3. - #7055: the OPUS CO tests read local kernel IDs; this branch's 1-GPU CI shards failed on the global ones. Co-authored-by: Cursor <[email protected]>
Summary
Top-k routing and a16w4 MoE changes on gfx950, with tuned-table updates.
Top-k routing
topk_softmax_kernels_group.cu/warp_sort.h: the register-resident biased top-k path now admitsnum_experts % 4 == 0(lanes past the last expert in the final round are masked) and a correction bias whose dtype differs from the gating output (e.g. an fp32 bias with bf16 logits).emit_legacy_ordered_topkranks candidates with one per-lane key (score, then legacy tie rank) instead oftopkserial ballots.topk_gating_kernels.cuh: a pad row (num_valid_rows) is written as id -1 / weight 0 and returns before selection.topk.py:biased_grouped_topkalways takesbiased_grouped_topk_hip;moe_fused_gateleavesrouted_scaling_factorto the caller and measured slower at every row count.MoE
fused_moe.py/moe_kernels.py: the a16w4 (bf16 x MXFP4) stage2 honors the table'sreducemode, as a16wi4 already did; sorting allocates the matching output layout.gemm_a16w16_gfx950_utils.py:SPLIT_K_SEMAPHORE_MAX_LEN256 -> 2048.Tuned tables
kimik3_a16w4_tuned_fmoe.csv: the a16w4 SiTUv2 rows switch stage2 from atomic to reduce, tiles unchanged.glm53_bf16/glm53_flash_bf16tuned GEMM: retuned rows that measured equal or faster keep the new entries; rows that measured slower stay at their current entries.Measurements (gfx950, MI355X,
run_perftest; both arms identical except the CSV)fused_moe, reduce vs atomic stage2: 2-6% slower; mean relative error against an FP32 torch reference 5.1e-3 -> 2.8e-3; the reduce output is bit-identical across runs, while atomic varies between runs on the same input.Test plan
warp_sort.h(the other two C++ files were not clang-format clean before this change either)fused_moeandtgemm.mm)op_testsfor biased grouped top-k with num_experts not a multiple of 64 and a bias dtype that differs from the gating outputop_tests/test_moe_2stage.pyon the a16w4 reduce path