Repository navigation
[FlyDSL] Kimi-K3 TP8 gfx1250 grouped-MoE tuning (experts split 8 ways) - #6768
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
The K=384 configuration is not safe across the full production dispatch range yet. The Python 3.12 AOT build currently reports multiple Please fix the runtime/default fallback so K=384 is handled correctly for every token bucket, rather than relying only on additional tuning rows. Please add regression coverage that exercises the real dispatch at the larger token counts, and rerun AOT correctness and same-machine performance tests without forcing a configuration. |
|
Thanks @zufayu. All four points are addressed on the branch ( 1. AOT Cause. The grouped-MoE AOT precompiled the stage-2 activation quant + preshuffle for every CSV row. Its quant layout needs Why the runtime doesn't need it. The runtime launches that prep only when gemm1 cannot requantize its own output: a gemm1 bias, or Fix. The AOT now skips that prep for such a shape and prints a note; the job's other kernels still compile.
2. Token buckets past the table fell back to
3. Regression coverage through the real dispatch (
The test runs JIT, not run-only. The grouped-MoE AOT builds only the auxiliary kernels; the TDM GEMM has no AOT wiring yet, so run-only cannot load the GEMM for any shape. The existing grouped tests fail the same way under run-only, before and after this change. 4. Same-machine performance, no forced config ( End-to-end
The 2048–16384 rows had been chosen on GEMM time. Their larger tile_m pads more rows for the routing, quant and gather kernels around the GEMMs, and that costs more than the GEMMs gain. Those four rows are dropped (below the 1.03× bar the tuning used), so their buckets take the default tiles, which the k-tile fit keeps correct. The table now has 11 rows, 1–1024 tokens. |
|
Thanks for the detailed follow-up. The AOT fix, large-token regression cases, and unforced end-to-end performance results address the concerns on the previous base. However, current main has since merged #6663, which adds correct K-tail handling to the grouped TDM GEMM and changes its default Please rebase onto current main and reconcile these changes semantically, rather than just resolving the conflict textually. Keep the AOT fix and useful tuning, but remove or justify any remaining divisibility restriction/retile logic. On the rebased head, please rerun the K=384 default-dispatch correctness cases (including the 32768 and 131072 token buckets), the AOT build, and same-machine performance without forced configuration, then let CI complete. I can re-review that head promptly. |
Kimi-K3 served as one tensor-parallel group of 8 on gfx1250 with its MoE split across the group (ATOM K3_MOE=tp) runs the FlyDSL grouped TDM MoE: every rank holds all 896 experts with inter_dim 3072 / 8 = 384, top-16, SiTUv2 (beta 4, linear_beta 25), A4W4 MXFP4 per_1x32, GUGU weights. tuned_grouped_fmoe had no row for that shape, so every call took the TDM function's default tile. The default is also wrong for this shape. It runs GEMM2 with tile_k 256 on K = 384 and drops the last 128 of K. Against the torch reference of aiter's own test (op_tests/flydsl_tests/test_flydsl_grouped_gemm._torch_moe_ref, whose gate is logits_diff <= 0.01), its output is 0.194-0.203 logits_diff away on main, for every token count. (gyu/k3-455-tp8 cc8d4ff fits the tile at run time instead; that commit is not on main.) model_configs/kimik3tp8_tuned_grouped_fmoe.csv adds 15 rows for token buckets 1, 2, 4, ..., 16384, which covers every padded token count of a TP8 server that batches up to 16384 tokens. kimik3tp8_untuned_grouped_fmoe.csv lists the same shapes. Every row sets tile_k2 = 128, which divides K. Every row matches the reference: logits_diff 4.5e-6 to 1.1e-4. No key repeats a row of another grouped table. Measured with a sweep of the production call, not with gemm_moe_tune.py --grouped-gemm. That tuner has four problems here: - It times every non-Swiglu row as Silu, so a SiTUv2 row never matches its own candidate and all candidates run the default tile. - It clears _GROUPED_CONFIG_CACHE but not _find_grouped_config's lru_cache, so every candidate after a shape's first runs the first one's tile. - It varies only tile_m and never times the default. - It lays out scales differently from the n32k4 layout the model loads. The sweep instead: - prepares weights and scales the way ATOM does on gfx1250 (moe_shuffle_weight / moe_shuffle_scale, GUGU, n32k4); - calls fused_moe with SiTUv2, GateMode.INTERLEAVE and per_1x32, using random top-16 routing; - uses as baseline the default tile written as an explicit row with tile_k2 = 128, and checks it against the torch reference per token; - runs each candidate as a single config row, clears both lookup caches, and checks that the kernel looked that row up; - requires each candidate's output to be bit-identical to the baseline's; - times each candidate as a CUDA-graph replay. GEMM1 tiles are swept first, with tile_m2 = tile_m. GEMM2 tiles are then swept on the best GEMM1. The baseline and the four fastest candidates are re-timed at the end. Tiles that do not divide N or K are excluded: GEMM1 tile_n 512 on N = 768 page-faults. token default us -> tuned us 1 22.7 -> 19.7 (1.15x) 2 23.8 -> 19.9 (1.19x) 4 28.9 -> 23.3 (1.24x) 8 45.1 -> 35.6 (1.27x) 16 66.7 -> 55.2 (1.21x) 32 94.9 -> 79.5 (1.19x) 64 128.0 -> 107.1 (1.20x) 128 160.4 -> 138.1 (1.16x) 256 178.7 -> 151.8 (1.18x) 512 189.9 -> 162.1 (1.17x) 1024 212.0 -> 182.8 (1.16x) 2048 246.9 -> 233.2 (1.06x) 4096 396.1 -> 351.6 (1.13x) 8192 640.2 -> 607.7 (1.05x) 16384 1129.1 -> 1051.1 (1.07x) Measured on MI455X (gfx1250, 256 CU) with aiter main e999585 and FlyDSL 0.4.0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nnot build The grouped-MoE AOT precompiled the stage-2 activation quant + preshuffle (route-ksplit or plain) for every CSV row. Its quant layout needs feat_dim % 256 == 0 on gfx1250 (wave32, pk8), so a row with inter_dim 384 (Kimi-K3 at TP8, 3072 / 8) failed the whole job: "[FAIL] compile ... feat_dim must be a multiple of 256, got 384". The runtime launches that prep only when gemm1 cannot requantize its own output (a gemm1 bias, or AITER_FLYDSL_DISABLE_GEMM1_REQUANT=1); a bias-free MoE has gemm1's epilogue write the MX payload and scales instead. So a job whose inter_dim the quant layout rejects has no stage-2 prep to build: it is skipped with a note, and the job's other kernels (stage-1 route + quant, the gather-reduce epilogue) still compile. quant_layout_supported() reports exactly the geometry the per-block quant builders accept (_quant_layout's checks), unlike fused_quant_preshuffle_supported(), which adds the compact path's limits and would skip shapes the stage-2 builders do take. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…end to end Timed through the real fused_moe dispatch (CUDA graph, a4w4, SiTUv2, 896 experts, top-16, 3584 -> 384, no bias, no forced config) on one gfx1250 GPU, with the table and without it (the dispatch's default tiles, k-tile fitted to K = 384), two runs each: tokens 1 2 4 8 16 32 64 128 256 512 1024 speedup 1.14 1.18 1.16 1.11 1.14 1.14 1.11 1.11 1.12 1.11 1.10 tokens 2048 4096 8192 16384 speedup 1.01 1.03 0.97 0.97 The 2048-16384 rows were chosen on GEMM time; their larger tile_m pads more rows for the routing, quant and gather kernels around the GEMMs, which cost more than the GEMMs gain. Rows below the 1.03x the tuning used are dropped; those buckets take the default tiles. Outputs are identical either way. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Kimi-K3 at TP8 with its experts split 8 ways has inter_dim 384, a multiple of 128 but not of 256. The new case runs the real fused_moe dispatch (a4w4, SiTUv2, 896 experts, top-16, model_dim 3584, no bias) against the torch reference at 32 tokens (a bucket of kimik3tp8_tuned_grouped_fmoe.csv) and at 2048, 20000 (padded to 32768) and 131072 tokens, which have no row, so the dispatch takes its default tiles. Nothing forces a config. It runs JIT rather than run-only: the grouped-MoE AOT builds only the auxiliary kernels, so run-only cannot load the TDM GEMM for any shape. Before #6663 the default k-tile was 256 and the GEMM had no K tail, so the three default-tile cases dropped the last 128 of K (logits_diff 0.20). Co-Authored-By: Claude Opus 5.5 <[email protected]>
#6663 made the grouped TDM GEMM run a K that its k-tile does not divide, with a ragged last tile, but added no in-tree test for it. Kimi-K3 at TP8 is such a shape for any GEMM2 k-tile wider than 128: inter_dim 384. The new case runs the real fused_moe dispatch (a4w4, SiTUv2, 896 experts, top-16, model_dim 3584, no bias, 2048 tokens, which have no row) with AITER_TDM_TILE_K2 at 256, one full tile and a 128-wide tail, and at 512, a single ragged tile with K < tile_k, against the torch reference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
6123d60 to
6e13e63
Compare
|
Rebased onto main Changes on this head
Next steps on this head (on gfx1250; results will be posted here)
|
`--scenario csv` skipped every row of kimik3tp8_tuned_grouped_fmoe.csv. It read act_type ActivationType.Situv2 as unsupported, and it skipped inter_dim < 512 on the grounds that tile_k 256 needs two K tiles. Since #6663 the TDM GEMM runs a ragged last k-tile, so the only K constraint left is the 128-wide WMMA step. The sweep now takes SiTUv2 and prints it as such rather than as silu. It skips a model_dim or inter_dim that is not a multiple of 128. With a bias, it also skips an inter_dim that is not a multiple of 256: a gemm1 bias turns off gemm1's own requantization, and the stage-2 quant that replaces it needs inter_dim % 256 == 0. Kimi-K3 at TP8 has inter_dim 384 and no bias, so its rows run with --no-bias. Its default --csv-path also pointed at op_tests/aiter/configs, which does not exist; it is <repo>/aiter/configs/tuned_grouped_fmoe.csv, as the comment says. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…6663 #6663 made the dispatch's default k-tile 128 for both GEMMs and let the TDM GEMM run a ragged last k-tile. Every row of this table had been measured against the old default, and buckets 2048-16384 had no row at all. The table was retuned through the production call on one gfx1250 GPU (MI455X, 256 CU, FlyDSL 0.4.0). The call is fused_moe with a4w4 and SiTUv2 (beta 4, linear_beta 25): 896 experts, top-16, model_dim 3584, inter_dim 384, no bias, GateMode.INTERLEAVE and random top-16 routing. Each candidate ran as a one-row table, found through the normal lookup, and its output had to be bit-identical to the default tiles' output. Timing is a CUDA graph of 16 calls that rotates over 8 weight copies and 8 routings, so the weights are cold, as in the model, where every layer reads its own. The hot number replays a single call. Each bucket's best candidate and two runners-up were re-timed against the default and the previous row, ABBA x 2. They ran at the bucket's own token count and at about 0.6x of it, a count the same row serves. Buckets 2048-16384 were also checked at T/2 + 1. The rules: - A row needs at least 1.03x over the default at the bucket's count, and at least 1.00x inside the bucket. - A previous row stays unless a new one beats it by 1% or more. Under these rules 512 and 1024 keep their rows. The fastest candidates for 4096 gained 1.15x at 4096 tokens but were 0.90x at 2049-2458, so 4096 takes 8192's tiles instead, 1.04x across the bucket. Speedup over the default tiles at the bucket's token count (us is the cold time): tokens 1 2 4 8 16 32 64 128 256 512 1024 cold 1.41 1.43 1.31 1.30 1.11 1.23 1.14 1.15 1.14 1.13 1.12 hot 1.23 1.24 1.22 1.33 1.23 1.29 1.22 1.19 1.17 1.13 1.12 tokens 2048 4096 8192 16384 cold 1.04 1.04 1.03 1.09 hot 1.05 1.04 1.03 1.10 tflops and bw are 0, as in the other grouped tables. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Kimi-K3 TP8 test ran one tuned bucket, 32, and three token counts that have no row. Every row of the table is its own tile geometry, for example: - GEMM1 tile_k 512 at 1-4 tokens; - at 1024, a gemm1 that requantizes for a GEMM2 wave tile twice its own height; - at 16384, GEMM2's single ragged k-tile (tile_k2 512 on K = 384). The test now reads the table's buckets and runs each one through the real fused_moe dispatch against the torch reference. It then runs 20000 tokens (padded to 32768) and 131072, which are past the table and take the default tiles; their routed buffers pass 2 GiB and 4 GiB. The K-tail test moves from 2048 tokens, which now have a row, to 20000, which have none, so its other tiles stay the defaults. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-moe-dryrun-20261009 aiter/aot/flydsl/grouped_moe.py stays deleted: moe.py replays the grouped table through the runtime. #6768 taught it to skip the stage-2 quant prep for an inter_dim the quant layout rejects (Kimi-K3 TP8, 384); the runtime launches that prep only when gemm1 cannot requantize (a gemm1 bias, or AITER_FLYDSL_DISABLE_GEMM1_REQUANT=1), and the replay passes SiTUv2 rows no bias, so it never reaches the prep either. Co-authored-by: Cursor <[email protected]>
#6768 added it so the grouped-MoE AOT script could skip the stage-2 quant prep that inter_dim 384 (Kimi-K3 at TP8) cannot build. This branch deletes that script: moe.py replays the grouped rows through the runtime, which launches the prep only when gemm1 cannot requantize its own output (a gemm1 bias, or AITER_FLYDSL_DISABLE_GEMM1_REQUANT=1). Kimi-K3's SiTUv2 rows take no bias, so their replay requests no stage-2 quant kernel, and nothing else calls the helper. Signed-off-by: zhimding <[email protected]> Co-authored-by: Cursor <[email protected]>
Kimi-K3 served as one tensor-parallel group of 8 on gfx1250 with its MoE split across the group (ATOM K3_MOE=tp) runs the FlyDSL grouped TDM MoE: every rank holds all 896 experts with inter_dim 3072 / 8 = 384, top-16, SiTUv2 (beta 4, linear_beta 25), A4W4 MXFP4 per_1x32, GUGU weights. tuned_grouped_fmoe had no row for that shape, so every call took the TDM function's default tile.
The default is also wrong for this shape. It runs GEMM2 with tile_k 256 on K = 384 and drops the last 128 of K. Against the torch reference of aiter's own test (op_tests/flydsl_tests/test_flydsl_grouped_gemm._torch_moe_ref, whose gate is logits_diff <= 0.01), its output is 0.194-0.203 logits_diff away on main, for every token count. (gyu/k3-455-tp8 cc8d4ff fits the tile at run time instead; that commit is not on main.)
model_configs/kimik3tp8_tuned_grouped_fmoe.csv adds 15 rows for token buckets 1, 2, 4, ..., 16384, which covers every padded token count of a TP8 server that batches up to 16384 tokens. kimik3tp8_untuned_grouped_fmoe.csv lists the same shapes. Every row sets tile_k2 = 128, which divides K. Every row matches the reference: logits_diff 4.5e-6 to 1.1e-4. No key repeats a row of another grouped table.
Measured with a sweep of the production call, not with gemm_moe_tune.py --grouped-gemm. That tuner has four problems here:
The sweep instead:
Tiles that do not divide N or K are excluded: GEMM1 tile_n 512 on N = 768 page-faults.
token default us -> tuned us
1 22.7 -> 19.7 (1.15x)
2 23.8 -> 19.9 (1.19x)
4 28.9 -> 23.3 (1.24x)
8 45.1 -> 35.6 (1.27x)
16 66.7 -> 55.2 (1.21x)
32 94.9 -> 79.5 (1.19x)
64 128.0 -> 107.1 (1.20x)
128 160.4 -> 138.1 (1.16x)
256 178.7 -> 151.8 (1.18x)
512 189.9 -> 162.1 (1.17x)
1024 212.0 -> 182.8 (1.16x)
2048 246.9 -> 233.2 (1.06x)
4096 396.1 -> 351.6 (1.13x)
8192 640.2 -> 607.7 (1.05x)
16384 1129.1 -> 1051.1 (1.07x)
Measured on MI455X (gfx1250, 256 CU) with aiter main e999585 and FlyDSL 0.4.0.