Skip to content

[MoE] Optimize qwen3.5 397B ptpc fp8 moe prefill and decoding - #3341

Merged
yixionghuo merged 8 commits into
ROCm:Qwen3.5_devfrom
apinge:moe_prefill_qwen3.5_308
May 28, 2026
Merged

yixionghuo merged 8 commits into
ROCm:Qwen3.5_devfrom
apinge:moe_prefill_qwen3.5_308

Conversation

@apinge

@apinge apinge commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

This PR aligns with PR #3309 and optimizes Qwen3.5‑397B PTPC FP8 MoE prefill and decoding.

Technical Details

  1. Optimizes E=512 TOPK=10 prefill and decode moe kernel
  2. Add new feature E=513 TOPK=11 prefill and decode moe kernel

Test Plan

Test Result

E=512 TOPK=10

Prefill

python3 op_tests/test_moe.py -t g1u1_fp8quant -d bf16 -m 8192 -hd 4096 -id 128 -e 512 -k 10

[aiter] [perf] use_g1u1=True token=8192, quant=fp8quant, model_dim=4096, inter_dim=128, E=512, shared_E=0, topk=10, dtype: torch.bfloat16, torch_avg: 104992.45 us, asm_avg:  1965.33 us, ck_avg:  1673.85 us, asm/torch uplift: 5242.2%, ck/torch uplift: 6172.5%, asm/ck: -14.8% [asm vs torch][checkAllclose atol=100 rtol=0.01 passed~]

Decode

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 512 -k 10 -dim 4096,128 -p t   -t  1 2 4 8 12 16 32
dtype token model_dim inter_dim E topk actType qType AQDType WQDType use_g1u1 doweight_stage1 hidden_pad intermediate_pad preshuffle us err
torch.bfloat16 1 4096 128 512 10 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 16.307 0.85083
torch.bfloat16 2 4096 128 512 10 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 35.4573 0.85437
torch.bfloat16 4 4096 128 512 10 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 45.357 0.857788
torch.bfloat16 8 4096 128 512 10 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 63.267 0.857849
torch.bfloat16 16 4096 128 512 10 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 92.3358 0.858871
torch.bfloat16 32 4096 128 512 10 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 130.726 0.854683

E=513 TOPK=11

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 513 -k 11 -dim 4096,128 -p t   -t  1 2 4 8 12 16 32 8192 16384 32768 65536
dtype token model_dim inter_dim E topk actType qType AQDType WQDType use_g1u1 doweight_stage1 hidden_pad intermediate_pad preshuffle us err
torch.bfloat16 1 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 22.037 0.875244
torch.bfloat16 2 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 34.127 0.850952
torch.bfloat16 4 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 48.837 0.858337
torch.bfloat16 8 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 67.9173 0.860504
torch.bfloat16 12 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 81.8563 0.866211
torch.bfloat16 16 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 94.885 0.856506
torch.bfloat16 32 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 143.625 0.857582
torch.bfloat16 8192 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 1757.9 0.124887
torch.bfloat16 16384 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 3198 0.124635
torch.bfloat16 32768 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 6096.55 0.124592
torch.bfloat16 65536 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 11988.9 0.125783

Links

# clone code and install pyhip
git clone https://github.com/tingqli/pyhip/ -b moe_prefill_fp8_308
cd pyhip && pip install -e .
# update test according to the case see pyhip test example below
...
# run pyhip and generate co
rm ~/.pyhip/ -rf
cd pyhip/tests/contrib/moe
PYHIP_SIMPLE_GEN_FILENAME=1 python3 test_moe.py
cp ~/.pyhip/*.co aiter/hsa/gfx942/fmoe_asmjit/

# tune
python3 csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py -i aiter/configs/model_configs/qwen3_5_397b_fp8_ptpc_untuned_fmoe.csv -o aiter/configs/model_configs/qwen3_5_397b_fp8_ptpc_tuned_fmoe.csv --timeout 300 -v --all --e2e_tune
 
# fuse qwen3_5_397b_fp8_ptpc_tuned_fmoe.csv to aiter/configs/tuned_fmoe.csv

pyhip test example

# Qwen3.5
HIDDEN_SIZE, INTER_SIZE_TP, E, TOPK = 4096, 128, 513, 11
for prec in [prec_fp8_ptpc]:
    TILE_M, TILE_N = 16, 64
    batch = [2, 4, 8, 16, 32]
    test_dec = TestCase(TILE_M, TILE_N, HIDDEN_SIZE, INTER_SIZE_TP, E, TOPK)
    test_dec.entry_common('aiter', [1] + batch, prec=[prec])
    test_dec.entry_common('16x32_2s_b1', [1], prec=[prec])
    test_dec.entry_common('16x32_2s_b', batch, prec=[prec])

    for DYN in [True, False]:
        GATE_TILE_N, DOWN_TILE_N = 128, 128
        if DYN:
            GATE_TILE_N = 256
        for TILE_M in [64, 128]:
            batch = [8192, 16384, 32768, 65536 ]
            test_prefill = TestCase(TILE_M, GATE_TILE_N, HIDDEN_SIZE, INTER_SIZE_TP, E, TOPK, DYN_SCHEDULE=DYN, STAGE2_TILE_N=DOWN_TILE_N)
            test_prefill.entry_common('aiter', batch, prec=[prec])
            test_prefill.entry_common('mxn_2s', batch, prec=[prec])
            test_dec.show_perf(f'qwen dec {TILE_M=} {DYN=}')
            test_prefill.show_perf(f'qwen prefill {TILE_M=} {DYN=}')

Submission Checklist

Co-authored-by: Cheng Luo [email protected]
Co-authored-by: Tingqian Li [email protected]

tingqli and others added 7 commits May 21, 2026 13:33
@apinge
apinge marked this pull request as ready for review May 26, 2026 02:46
@apinge apinge changed the title [MOE] Optimize qwen3.5 397B ptpc fp8 moe prefill and decoding [MoE] Optimize qwen3.5 397B ptpc fp8 moe prefill and decoding May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants