Skip to content

[MoE] Add MoE configs for Qwen3.5 122B (TP1/2/4) and 35B (TP1/2), hotfix prefill Co kernels and retune MoE kernels - #3453

Merged
yixionghuo merged 7 commits into
ROCm:Qwen3.5_devfrom
apinge:qwen3.5_35b_tp1_tp2_122b_tp1_tp2_tp4
Jun 2, 2026
Merged

yixionghuo merged 7 commits into
ROCm:Qwen3.5_devfrom
apinge:qwen3.5_35b_tp1_tp2_122b_tp1_tp2_tp4

Conversation

@apinge

@apinge apinge commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

In this PR, configs have been added to cover Qwen3.5 122B (TP1/2/4) and Qwen3.5 35B (TP1/2). At these problem sizes, MoE falls back to CK 2-stage kernels.

A hotfix replaces several prefill Co kernels for
Qwen3.5 397B TP8 (HIDDEN_SIZE, INTER_SIZE_TP, E, TOPK = 4096, 128, 513, 11),
Qwen3.5 122B TP8 (3072, 1024//8, 257, 9), and
Qwen3.5 35B TP4 (2048, 512//4, 257, 9)
to prevent potential out-of-bound reads.

It also adds coverage for token lengths 32 < token_len < 8192 for these configs, generating Co kernels for all original AIter ASM kernels to improve accuracy, while keeping the first original line unchanged.

Finally, we refined and re-tuned several pyhip asmjit kernels for Qwen3.5 397B TP8, Qwen3.5 122B TP8, and Qwen35B TP4. For Qwen3.5 122B (TP1/2/4) and Qwen3.5 35B (TP1/2), the CK kernels are updated and re-tuned to avoid mistakenly selecting the original aiter asm kernels under these configs.

Technical Details

Add MoE configs for Qwen3.5 122B (TP1/2/4) and 35B (TP1/2)

  1. Force run_1stage = False in aiter/fused_moe.py fused_moe to prevent selecting the single-stage asm MoE kernel.

  2. In csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py, comment out tasks.extend(self.gen_2stages_asm1_task(info, blockMs)) and task_1stage.extend(self.gen_1stage_asm_task(info)) to avoid selecting the single-stage asm kernel and the stage-1 asm kernel.

Note: These changes are only intended for kernel tuning purposes. Once tuning is complete, these files should be reverted to their original state.

  1. tune moe
python3 csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py -i aiter/configs/model_configs/qwen3_5_35b_fp8_ptpc_untuned_fmoe_tp1_tp2.csv -o aiter/configs/model_configs/qwen3_5_35b_fp8_ptpc_tuned_fmoe_tp1_tp2.csv --timeout 300 -v --all 

python3 csrc/ck_gemm_moe_2stages_codegen/gemm_moe_tune.py -i aiter/configs/model_configs/qwen3_5_122b_fp8_ptpc_untuned_fmoe_tp1_tp2_tp4.csv -o aiter/configs/model_configs/qwen3_5_122b_fp8_ptpc_tuned_fmoe_tp1_tp2_tp4.csv --timeout 900 -v --all

Prefill Co kernel hotfix

A hotfix adds tuned prefill kernel configs (moe_2stage_down and moe_2stage_gateup) with dyn=True, based on commit tingqli/pyhip@8a58dea

pyhip code as

        # Qwen3.5 397B  TP8
        #HIDDEN_SIZE, INTER_SIZE_TP, E, TOPK = 4096, 128, 513, 11

        # Qwen3.5 122B  TP8
        #HIDDEN_SIZE, INTER_SIZE_TP, E, TOPK = 3072, 1024//8, 257, 9

        # Qwen3.5 35B  TP4
        HIDDEN_SIZE, INTER_SIZE_TP, E, TOPK = 2048, 512//4, 257, 9
        for prec in [prec_fp8_ptpc]:
            TILE_M, TILE_N = 16, 64
            
            for DYN in [True]:
                GATE_TILE_N, DOWN_TILE_N = 128, 128
                if DYN:
                    GATE_TILE_N = 256
                for TILE_M in [64, 128]:
                    batch = [512,1024,2048,4096,8192, 16384, 32768]
                    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=}')

Extended Token Length Coverage

We supplement the previous two PR #3400 and #3341 by adding coverage for token lengths 32 < token_len < 8192 for the following configs: Qwen3.5 397B TP8, Qwen122B TP8, and Qwen35B TP4.

Test Plan

Test Result

MoE Performance Comparison for Qwen3.5 122B (TP1/2/4) and 35B (TP1/2): Before vs After Tuning (us)

Unit: us. Lower is better.

35B TP1

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 257 -k 9 -dim 2048,512 -p t   -t  1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
token origin (us) tuned (us)
1 44.0352 41.1955
2 44.8655 43.8050
4 61.7852 62.0853
8 88.4653 89.5452
16 398.9060 134.6550
32 213.9570 182.8250
64 241.8670 233.6750
128 305.1070 262.3050
256 307.5170 338.2750
512 313.7870 304.7750
1024 426.3670 453.0850
2048 642.9870 742.1850
4096 1025.4900 1284.8800
8192 1742.0400 2236.3700
16384 3160.9200 4335.9500
32768 5980.2500 8498.0400

35B TP2

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 257 -k 9 -dim 2048,256 -p t   -t  1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
token origin (us) tuned (us)
1 38.5750 36.7953
2 37.7052 35.8250
4 47.0252 45.5950
8 65.4555 66.7150
16 96.3152 94.7655
32 130.9170 123.7650
64 150.5760 152.5340
128 192.5970 167.8350
256 188.8270 177.2550
512 195.6270 197.5350
1024 251.4470 290.5650
2048 409.8950 469.1640
4096 626.7160 791.5350
8192 1097.9000 1381.5800
16384 1996.4500 2644.3700
32768 3932.2500 5185.8600

122B TP1

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 257 -k 9 -dim 3072,1024 -p t   -t  1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
token origin (us) tuned (us)
1 59.0353 66.4950
2 74.9950 75.0653
4 114.9550 124.7560
8 187.3560 190.6160
16 866.1880 306.5460
32 498.9880 491.5060
64 620.3680 614.1360
128 729.3590 700.1270
256 742.8190 743.4870
512 759.4290 817.2970
1024 1095.8800 1153.8200
2048 1656.3100 1930.3400
4096 2747.2900 3085.9800
8192 4825.3100 5258.0700
16384 8884.8100 9891.8500
32768 16748.8000 19221.0000

122B TP 2

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 257 -k 9 -dim 3072,512 -p t   -t  1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
token origin (us) tuned (us)
1 54.0152 45.0152
2 53.7555 54.0650
4 79.3750 79.6153
8 115.0250 117.4960
16 521.9270 182.2560
32 296.4770 265.6250
64 317.1770 345.5850
128 407.3780 384.1860
256 411.5180 403.4360
512 427.0270 443.8260
1024 580.2480 657.1060
2048 942.1380 1056.6100
4096 1474.6600 1800.7300
8192 2614.2800 3247.3600
16384 4748.4200 6239.1400
32768 8937.9700 12401.4000

122B TP 4

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 257 -k 9 -dim 3072,256 -p t   -t  1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
token origin (us) tuned (us)
1 48.8550 46.7450
2 45.5350 40.8952
4 55.7552 53.5652
8 85.7252 83.5555
16 125.7850 121.4050
32 181.8870 168.1940
64 190.0460 215.6950
128 236.3170 241.8050
256 245.0770 256.0350
512 256.2670 288.2550
1024 346.6680 414.2250
2048 561.4760 663.0340
4096 883.8370 1132.4900
8192 1571.8000 1962.7300
16384 2906.5500 3720.8000
32768 5720.2800 7436.0800

Accuracy of Co Kernels

python3 op_tests/test_fused_moe_ptpc_acc.py

All tests passed.

Performance of Co Kernels

397B TP8

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 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
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 19.517 0.846436
torch.bfloat16 2 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 37.7072 0.863892
torch.bfloat16 4 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 48.667 0.859436
torch.bfloat16 8 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 66.707 0.858978
torch.bfloat16 16 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 95.315 0.860168
torch.bfloat16 32 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 142.966 0.861557
torch.bfloat16 64 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 298.074 0.120857
torch.bfloat16 128 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 350.924 0.129166
torch.bfloat16 256 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 396.064 0.117676
torch.bfloat16 512 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 416.934 0.115431
torch.bfloat16 1024 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 450.054 0.124433
torch.bfloat16 2048 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 582.812 0.128431
torch.bfloat16 4096 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 995.864 0.127843
torch.bfloat16 8192 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 1747.09 0.124889
torch.bfloat16 16384 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 3188.32 0.125051
torch.bfloat16 32768 4096 128 513 11 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 6056.36 0.124723

122B TP8

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 257 -k 9 -dim 3072,128 -p t   -t  1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
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 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 16.697 0.837565
torch.bfloat16 2 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 25.3575 0.842611
torch.bfloat16 4 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 34.5873 0.870524
torch.bfloat16 8 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 44.7875 0.86145
torch.bfloat16 16 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 69.1762 0.855326
torch.bfloat16 32 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 81.525 0.854624
torch.bfloat16 64 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 156.853 0.117844
torch.bfloat16 128 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 182.184 0.1303
torch.bfloat16 256 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 184.474 0.125776
torch.bfloat16 512 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 200.654 0.118553
torch.bfloat16 1024 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 222.624 0.118105
torch.bfloat16 2048 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 402.053 0.121427
torch.bfloat16 4096 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 640.771 0.118817
torch.bfloat16 8192 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 1120.24 0.12373
torch.bfloat16 16384 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 2066.37 0.121092
torch.bfloat16 32768 3072 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 4014 0.121556

35B TP4

python3 op_tests/test_moe_2stage.py -q 2 -a silu -e 257 -k 9 -dim 2048,128 -p t   -t  1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
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 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 14.087 0.878418
torch.bfloat16 2 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 22.2373 0.866211
torch.bfloat16 4 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 28.857 0.865723
torch.bfloat16 8 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 37.597 0.863098
torch.bfloat16 16 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 53.3462 0.856842
torch.bfloat16 32 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 65.165 0.857193
torch.bfloat16 64 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 117.754 0.109276
torch.bfloat16 128 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 133.963 0.118004
torch.bfloat16 256 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 137.133 0.135437
torch.bfloat16 512 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 144.954 0.12184
torch.bfloat16 1024 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 169.734 0.119408
torch.bfloat16 2048 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 276.342 0.120077
torch.bfloat16 4096 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 443.723 0.121232
torch.bfloat16 8192 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 766.432 0.120856
torch.bfloat16 16384 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 1408.49 0.121068
torch.bfloat16 32768 2048 128 257 9 0 2 torch.float8_e4m3fnuz torch.float8_e4m3fnuz True False 0 0 False 2713.75 0.121602

Submission Checklist

Co-authored-by: Cheng Luo [email protected]
Co-authored-by: Xiake.Sun [email protected]

@apinge
apinge marked this pull request as ready for review June 1, 2026 08:33
@apinge
apinge marked this pull request as draft June 1, 2026 08:56
@apinge
apinge force-pushed the qwen3.5_35b_tp1_tp2_122b_tp1_tp2_tp4 branch from 3551781 to fbd7fe3 Compare June 1, 2026 08:58
@apinge
apinge marked this pull request as ready for review June 1, 2026 09:48
@apinge
apinge marked this pull request as draft June 1, 2026 10:00
@apinge apinge changed the title [MoE] Add MoE configs for Qwen3.5 122B (TP1/2/4) and 35B (TP1/2) [MoE] Add MoE configs for Qwen3.5 122B (TP1/2/4) and 35B (TP1/2), hotfix prefill Co kernels and retune MoE kernels Jun 2, 2026
@apinge
apinge marked this pull request as ready for review June 2, 2026 05:45
@yixionghuo
yixionghuo merged commit dd9d1bb into ROCm:Qwen3.5_dev Jun 2, 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.

2 participants