Skip to content

Commit 581579a

Browse files
JohnNikolay84Sergey SOlocursoragent
authored
[ASM] [HIP] Qwe38 flash mxfp4 asm (#5757)
* Add --fused-expert option to 2stage moe tests * Add gfx950 FLAT MXFP4 fused-MoE 16x32/160/320 kernels. Relax the small-tile dim check to a 512 multiple so 2560 hidden works, dispatch FLAT tiles for irregular inter_dim, and trim e8m0 shuffle padding in the 2-stage test so E=513 fused-expert can view scales. Co-authored-by: Cursor <[email protected]> * Add new kernels and tuned config * Fix 16x320 kernel when h_dim/sub_gu > 1 * Remove redundant second loop scan * Revert temp test changes * Add test option to disable biases * Extend asm 16x160 up to con 256 for TP4 * Add 16x320 kernel for TP2 * Extend TP4/TP2 kernels to conc512 * Upmerge to top of main * Pass num_valid_tokens correctly for flat and emsort --------- Co-authored-by: Sergey SOlo <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 2530d10 commit 581579a

10 files changed

Lines changed: 101 additions & 15 deletions

‎aiter/configs/model_configs/qwen3_8_flash_fp4_tuned_fmoe.csv‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,43 @@ gfx950,256,2048,2560,640,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_
1414
gfx950,256,4096,2560,640,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,64,0,0,flydsl_mxmoe_g1_a4w4_64x256x256_xcd4,3.5%,0,flydsl_moe2_layout_afp4_wfp4_bf16_t64x256x128_atomic_sbm64,3.5%,450.16,0,0,0,983.9,0,
1515
gfx950,256,8192,2560,640,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,64,0,0,flydsl_mxmoe_g1_a4w4_64x256x256_xcd4,3.6%,0,flydsl_moe2_layout_afp4_wfp4_bf16_t64x128x128_atomic_sbm64,3.6%,735.64,0,0,0,1204.2,0,
1616
gfx950,256,16384,2560,640,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,128,0,0,flydsl_mxmoe_g1_a4w4_128x256x256_xcd4,3.5%,0,flydsl_moe2_layout_afp4_wfp4_bf16_t128x256x128_scatter_sbm128,3.5%,1117.73,0,0,0,1585.1,0,
17+
gfx950,256,1,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,11.43,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,11.43,1,1,1,2.15,0,
18+
gfx950,256,2,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,11.65,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,11.65,1,1,1,4.22,0,
19+
gfx950,256,4,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,12.77,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,12.77,1,1,1,7.70,0,
20+
gfx950,256,8,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,16.77,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,16.77,1,1,1,11.72,0,
21+
gfx950,256,16,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,26.07,_ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x160E,0.0%,0.0,,0.0%,26.07,1,1,1,15.08,0,
22+
gfx950,256,32,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,
23+
gfx950,256,64,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,
24+
gfx950,256,128,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,
25+
gfx950,256,256,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,
26+
gfx950,256,512,2560,160,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,
27+
gfx950,256,1,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,13.70,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,13.70,1,1,1,3.59,0,
28+
gfx950,256,2,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,13.58,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,13.58,1,1,1,7.24,0,
29+
gfx950,256,4,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,18.12,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,18.12,1,1,1,10.85,0,
30+
gfx950,256,8,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,28.55,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,28.55,1,1,1,13.77,0,
31+
gfx950,256,16,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,41.93,_ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x320E,0.0%,0.0,,0.0%,41.93,1,1,1,18.76,0,
32+
gfx950,256,32,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,
33+
gfx950,256,64,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,
34+
gfx950,256,128,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,
35+
gfx950,256,256,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,
36+
gfx950,256,512,2560,320,512,10,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,
37+
gfx950,256,1,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,11.41,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,11.41,1,1,1,2.37,0,fused_expert
38+
gfx950,256,2,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,11.65,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,11.65,1,1,1,4.64,0,fused_expert
39+
gfx950,256,4,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,12.60,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,12.60,1,1,1,8.58,0,fused_expert
40+
gfx950,256,8,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,17.49,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,17.49,1,1,1,12.37,0,fused_expert
41+
gfx950,256,16,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,26.60,_ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x160E,0.0%,0.0,,0.0%,26.60,1,1,1,16.26,0,fused_expert
42+
gfx950,256,32,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
43+
gfx950,256,64,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
44+
gfx950,256,128,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
45+
gfx950,256,256,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
46+
gfx950,256,512,2560,160,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
47+
gfx950,256,1,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,12.51,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,12.51,1,1,1,4.32,0,fused_expert
48+
gfx950,256,2,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,13.22,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,13.22,1,1,1,8.18,0,fused_expert
49+
gfx950,256,4,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,18.27,_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,0.0%,0.0,,0.0%,18.27,1,1,1,11.84,0,fused_expert
50+
gfx950,256,8,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,27.98,_ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x160E,0.0%,0.0,,0.0%,27.98,1,1,1,15.46,0,fused_expert
51+
gfx950,256,16,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,41.93,_ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x320E,0.0%,0.0,,0.0%,41.93,1,1,1,20.63,0,fused_expert
52+
gfx950,256,32,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
53+
gfx950,256,64,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
54+
gfx950,256,128,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
55+
gfx950,256,256,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert
56+
gfx950,256,512,2560,320,513,11,ActivationType.Silu,torch.bfloat16,torch.float4_e2m1fn_x2,torch.float4_e2m1fn_x2,QuantType.per_1x32,1,0,16,0,0,_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,0.0%,,,0.0%,0,1,1,2,0,0,fused_expert

‎aiter/ops/shuffle.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ def shuffle_weight(
155155
pad_k_to: int = 0,
156156
) -> torch.Tensor:
157157
x_type = x.dtype
158-
if hasattr(torch, "float4_e2m1fn_x2") and x_type == torch.float4_e2m1fn_x2:
158+
is_packed_fp4 = (
159+
hasattr(torch, "float4_e2m1fn_x2") and x_type == torch.float4_e2m1fn_x2
160+
)
161+
if is_packed_fp4:
159162
x = x.view(torch.uint8)
160163

161164
original_k = x.shape[-1]
@@ -192,7 +195,12 @@ def shuffle_weight(
192195
return x_
193196

194197
IN, IK = layout
195-
BK = IK * 2
198+
# A packed FP4 byte already contains two logical K values. Its 16x16
199+
# preshuffle tile is therefore IK bytes wide, not IK*2 bytes. Grouping two
200+
# adjacent tiles was layout-equivalent for widths divisible by 32 bytes, but
201+
# unnecessarily rejected valid 16-byte-aligned widths such as K=160
202+
# (80 packed bytes), used by the FLAT 16x160 MoE kernel.
203+
BK = IK if is_packed_fp4 else IK * 2
196204
K = 16 // x.element_size() if not use_int4 else 32
197205
BN = IN
198206
assert x.shape[-2] % BN == 0, f"{x.shape[-2]} % {BN} == {x.shape[-2] % BN }"

‎csrc/py_itfs_cu/asm_fmoe.cu‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ class FMoeKernel
169169
args.ptr_O = out->ptr;
170170
args.ptr_X = input->ptr;
171171
args.ptr_GU = w1->ptr;
172-
args.ptr_XC = num_valid_ids->ptr;
172+
// FLAT and EMSORT read XC[0] as the token count when this pointer is
173+
// set. The unsorted path passes an empty tensor when the caller did
174+
// not supply num_local_tokens, and that tensor's data pointer is null,
175+
// so the shader keeps the kernarg token_cnt.
176+
args.ptr_XC = num_valid_ids->ptr;
173177
args.ptr_D = w2->ptr;
174178
if constexpr(I_elemSize == 1)
175179
{
@@ -364,10 +368,16 @@ static bool ps_grid_fits(const CFG::mapped_type& cfg, int inter_dim)
364368
static bool kernel_fits(
365369
const CFG::mapped_type& cfg, int vskip, int smf, int block_size_M, int inter_dim, int model_dim)
366370
{
367-
return cfg.vskip == vskip && cfg.smf == smf && block_size_M == cfg.subGU_m &&
368-
cfg.flat == static_cast<int>(AsmMoeMode::SORTED) && inter_dim % cfg.subGU_n == 0 &&
369-
model_dim % std::max(cfg.dim_align, 1) == 0 && model_dim >= cfg.dim_min &&
370-
ps_grid_fits(cfg, inter_dim);
371+
if(cfg.smf != smf || inter_dim % cfg.subGU_n != 0 ||
372+
model_dim % std::max(cfg.dim_align, 1) != 0 || model_dim < cfg.dim_min ||
373+
!ps_grid_fits(cfg, inter_dim))
374+
return false;
375+
// flat==1 rows are the 16xN tiles. Their subGU_m is 16 and vskip is 0, so the
376+
// checks below would hide the only rows that divide inter_dim such as 160 and 320.
377+
if(cfg.flat == static_cast<int>(AsmMoeMode::NO_SORT))
378+
return true;
379+
return cfg.vskip == vskip && block_size_M == cfg.subGU_m &&
380+
cfg.flat == static_cast<int>(AsmMoeMode::SORTED);
371381
}
372382

373383
FMoeKernel* get_heuristic_kernel(int inter_dim,
@@ -384,6 +394,7 @@ FMoeKernel* get_heuristic_kernel(int inter_dim,
384394
uint32_t tg_num = 0;
385395
uint32_t num_persistent_tgs = 0;
386396
uint32_t round = 0xffffffff;
397+
int selected_flat = 0;
387398
std::string arch_id = get_gpu_arch();
388399
std::string selectedKl = kernel_name.empty() ? "" : arch_id + kernel_name;
389400
int vskip = get_vskip();
@@ -401,15 +412,19 @@ FMoeKernel* get_heuristic_kernel(int inter_dim,
401412
tg_num = inter_dim / cfg.subGU_n *
402413
sub_X_cnt; // how many thread_groups are needed to handle inter_dim
403414
uint32_t local_round = (tg_num + num_cu - 1) / num_cu;
404-
if(local_round < round || // fewer round is better
415+
const uint32_t empty = local_round * num_cu - tg_num;
416+
// Fewer rounds, then fewer empty CUs. At the same cost a flat==0 row
417+
// beats a flat==1 row with the same subGU_n, and a PS row wins a tie.
418+
if(local_round < round ||
405419
(local_round == round &&
406-
(empty_cu > (local_round * num_cu - tg_num) || // fewer empty_cu is better
407-
(empty_cu == (local_round * num_cu - tg_num) &&
408-
cfg.ps == 1)))) // prefer PS kernel
420+
(empty_cu > empty ||
421+
(empty_cu == empty && cfg.flat == selected_flat && cfg.ps == 1) ||
422+
(empty_cu == empty && selected_flat != 0 && cfg.flat == 0))))
409423
{
410-
round = local_round;
411-
empty_cu = local_round * num_cu - tg_num;
412-
selectedKl = el.first;
424+
round = local_round;
425+
empty_cu = empty;
426+
selectedKl = el.first;
427+
selected_flat = cfg.flat;
413428
if(cfg.ps == 1)
414429
num_persistent_tgs = cfg.tg_num_perCU * num_cu;
415430
else
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

‎hsa/gfx950/fmoe/silu/fmoe_bf16_pertokenMXfp4_g1u1_silu.csv‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ _ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x256E,fmoe_bf16_pertoke
1313
_ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_emsort_vs_silu_16xstkE,fmoe_bf16_pertokenMXfp4_g1u1_emsort_vs_silu_16xstk.co,0,1,0,2,1,16,256,2,64,2048,1024
1414
fmoe_bf16_pertokenMXfp4_g1u1_silu_prefill_1tg_4w_256mx1_128nx1_ps_fp32gate_route,fmoe_bf16_pertokenMXfp4_g1u1_silu_prefill_1tg_4w_256mx1_128nx1_ps_fp32gate_route.co,0,0,0,1,1,256,256,3,0,0,0
1515
fmoe_bf16_pertokenMXfp4_g1u1_silu_prefill_1tg_4w_256mx1_128nx1_ps_fp32gate_route_weighted,fmoe_bf16_pertokenMXfp4_g1u1_silu_prefill_1tg_4w_256mx1_128nx1_ps_fp32gate_route_weighted.co,0,0,0,1,1,256,256,3,0,0,0
16+
_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160E,fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x160.co,0,1,0,2,1,16,160,2,512,5632,1024
17+
_ZN5aiter47fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320E,fmoe_bf16_pertokenMXfp4_g1u1_emsort_silu_16x320.co,0,1,0,1,1,16,320,2,512,5632,1024
18+
_ZN5aiter49fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32E,fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x32.co,0,0,0,2,0,16,32,1,0,0,0
19+
_ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x160E,fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x160.co,0,0,0,1,0,16,160,1,0,0,0
20+
_ZN5aiter50fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x320E,fmoe_bf16_pertokenMXfp4_g1u1_flat_novs_silu_16x320.co,0,0,0,1,0,16,320,1,0,0,0

‎op_tests/test_moe_2stage.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,14 +747,25 @@ def calc_diff(x: torch.Tensor, y: torch.Tensor):
747747
help="""Hidden intermediate pad.
748748
e.g.: -hip 0,0""",
749749
)
750+
parser.add_argument(
751+
"--stage1-bias",
752+
type=dtypes.str2bool,
753+
nargs="*",
754+
default=[True],
755+
help="""Whether CLI-generated cases include a random per-expert stage-1
756+
bias. Default is [True] for backward compatibility. Use
757+
--stage1-bias f for bias-free models, or --stage1-bias t f to test both.
758+
FLAT MXFP4 assembly kernels do not apply this bias.""",
759+
)
750760
parser.add_argument(
751761
"--stage2-bias",
752762
type=dtypes.str2bool,
753763
nargs="*",
754764
default=[True],
755765
help="""Whether CLI-generated cases include a random per-expert stage-2
756766
bias. Default is [True] for backward compatibility. Use
757-
--stage2-bias f for bias-free models, or --stage2-bias t f to test both.""",
767+
--stage2-bias f for bias-free models, or --stage2-bias t f to test both.
768+
FLAT MXFP4 assembly kernels do not apply this bias.""",
758769
)
759770
parser.add_argument(
760771
"--no-flydsl-csv",
@@ -1279,12 +1290,14 @@ def _kw(
12791290
(quant_type, aq_dtype, wq_dtype),
12801291
(model_dim, inter_dim),
12811292
doweight_stage1,
1293+
stage1_bias,
12821294
stage2_bias,
12831295
) in itertools.product(
12841296
args.dtype,
12851297
l_quant,
12861298
args.dim,
12871299
args.doweight_stage1,
1300+
args.stage1_bias,
12881301
args.stage2_bias,
12891302
):
12901303
triple = (quant_type, aq_dtype, wq_dtype)
@@ -1311,6 +1324,7 @@ def _kw(
13111324
use_g1u1=(act_type != aiter.ActivationType.Relu2),
13121325
hidden_pad=hidden_pad,
13131326
intermediate_pad=intermediate_pad,
1327+
disable_stage1_bias=not stage1_bias,
13141328
disable_stage2_bias=not stage2_bias,
13151329
), extras
13161330
elif triple == _PER1X32_FP8_FP4:
@@ -1329,6 +1343,7 @@ def _kw(
13291343
act_type,
13301344
hidden_pad=hidden_pad,
13311345
intermediate_pad=intermediate_pad,
1346+
disable_stage1_bias=not stage1_bias,
13321347
disable_stage2_bias=not stage2_bias,
13331348
**_situv2_beta_kwargs(act_type),
13341349
), extras
@@ -1353,6 +1368,7 @@ def _kw(
13531368
preshuffle=preshuffle,
13541369
hidden_pad=0,
13551370
intermediate_pad=0,
1371+
disable_stage1_bias=not stage1_bias,
13561372
disable_stage2_bias=not stage2_bias,
13571373
**_situv2_beta_kwargs(act_type),
13581374
),
@@ -1370,6 +1386,7 @@ def _kw(
13701386
wq_dtype,
13711387
doweight_stage1,
13721388
aiter.ActivationType.Silu,
1389+
disable_stage1_bias=not stage1_bias,
13731390
disable_stage2_bias=not stage2_bias,
13741391
), extras
13751392
else:
@@ -1394,6 +1411,7 @@ def _kw(
13941411
doweight_stage1,
13951412
act_type,
13961413
use_g1u1=(act_type != aiter.ActivationType.Relu2),
1414+
disable_stage1_bias=not stage1_bias,
13971415
disable_stage2_bias=not stage2_bias,
13981416
**_situv2_beta_kwargs(act_type),
13991417
),

0 commit comments

Comments
 (0)