Repository navigation
[FlyDSL] [gfx1250] Fix the dropped K tail and the bias column offset in the grouped MoE TDM GEMM - #6663
Conversation
…M GEMM The grouped TDM GEMM ran K // tile_k k-tiles, so a K that tile_k does not divide silently dropped its last partial tile. DeepSeek-V4.1-Flash at TP4 (inter_dim=640, default tile_k=256) lost 128 of 640 in GEMM2 (MoE output rel_l2 ~0.44); V4-Pro at TP8 (inter_dim=384) lost a third of K. Round the k-tile count up. On the ragged last tile every K-advancing TDM load (A, B, A-scale, B-scale) clamps its inner extent, so nothing past the row end is read and the hardware zero-fills the rest, and the tile computes only its remaining k128 steps. All of it is compile-time gated: when tile_k divides K the generated ISA is byte-identical to before. K must be a multiple of 128. Tested on gfx1250: tail results are bitwise equal to the same data zero-padded to a tile_k multiple across pipeline variants; fused_moe at inter_dim=640 is bitwise equal to weights zero-padded to 768; tuned shapes of other models are bitwise and timing unchanged. Co-authored-by: Cursor <[email protected]>
Untuned shapes (no CSV row) ran tile_k=256, which leaves a K tail whenever the K of either GEMM is an odd multiple of 128 (e.g. inter_dim 384/640). tile_k=128 divides every K the kernel accepts. Blank tile_k cells and the env-override base follow the same default; tuned rows are unaffected. On gfx1250, untuned shapes run within -8%..+5% of the tile_k=256 default (gemm1+gemm2), with outputs bitwise unchanged. Co-authored-by: Cursor <[email protected]>
… N start The epilogue read bias[expert, col] with col relative to the workgroup's N tile, so every N tile past the first added the first tile's bias. GEMM1 has 2*inter_dim columns and GEMM2 model_dim, so every biased MoE (e.g. gpt-oss) on this path was silently wrong, and its output also changed with tile_n. Tested on gfx1250: with zero weights the GEMM2 output equals bias[col] in every N tile (tile_n 128/256) and GEMM1 matches swiglu(bias) per tile; biased fused_moe (a8w4/a4w4) is now bitwise invariant across tile_n, tile_n2 and tile_k, and its logits_diff vs the torch reference drops from 3.2e-5/9.4e-5 to 3.7e-6/3.9e-6. Unbiased kernels are unchanged. Co-authored-by: Cursor <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Resolve the grouped MoE TDM conflict using the tiled API and its full tensor bounds. Preserve ragged-K zero filling and full K-tile advances for split-inner scale loads, along with the bias offset fix. Validation: repository-wide Black and Ruff pass; 44 gfx1250 configurations compile with pinned FlyDSL 0.4.0. The two row-major tile_k=256 compile failures reproduce on main. GPU runtime validation requires gfx1250 hardware.
Honor the main-branch revert of the gfx1250 tiled TDM API migration. Restore the original PR kernel, retaining the K-tail bounds, partial-tile compute, and bias column offset fixes. Validation: repository-wide Black and Ruff pass. All 46 gfx1250 compile configurations pass with FlyDSL 0.4.0, including both row-major tile_k=256 cases. Runtime numerics require gfx1250 hardware.
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]>
`--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]>
#6768) * [Config] Kimi-K3 TP8 gfx1250 grouped-MoE tuning (experts split 8 ways) 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]> * [FlyDSL][MoE] Grouped-MoE AOT: skip the stage-2 quant prep a shape cannot 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]> * [Config] Kimi-K3 TP8 grouped MoE: keep only the rows that are faster 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]> * [FlyDSL][MoE] Test the Kimi-K3 TP8 grouped MoE past its tuned buckets 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]> * [FlyDSL][MoE] Test the Kimi-K3 TP8 grouped MoE with a K tail in GEMM2 #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]> * [FlyDSL][MoE] Let the grouped-MoE CSV sweep run SiTUv2 and K-tail rows `--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]> * [Config] Kimi-K3 TP8 grouped MoE: retune against the default tiles of #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]> * [FlyDSL][MoE] Test every row of the Kimi-K3 TP8 grouped-MoE table 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]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
The gfx1250 grouped a8w4/a4w4 MoE TDM GEMM (
grouped_gemm_gfx1250_a8w4) had two silent correctness bugs:K // tile_kk-tiles, so a K thattile_kdoes not divide lost its last partial tile. DeepSeek-V4.1-Flash at TP4 (inter_dim=640, defaulttile_k=256) lost 128 of 640 in GEMM2; the MoE output was off by rel_l2 ≈ 0.44 against the same weights zero-padded to 768. V4-Pro at TP8 (inter_dim=384) lost a third of K.bias[expert, col]withcolrelative to the workgroup's N tile, so every N tile past the first added the first tile's bias. GEMM1 has2*inter_dimcolumns and GEMM2model_dim, so every biased MoE on this path (e.g. gpt-oss) was wrong, and its output also changed withtile_n.Changes
mxfp4_preshuffle_gfx1250_tdm.pytile_kdivides K the final ISA is byte-identical tomain. K must be a multiple of 128 and now raises instead of silently computing a prefix.blk_n).grouped_gemm_mxfp4.py: the buffer-ring clamp keeps its previous value (it counts full tiles), now written against the rounded-up tile count.grouped_moe_gfx1250.py: shapes without a tuned CSV row default totile_k=128, which divides every K the kernel accepts (blanktile_kcells and the env-override base follow). Tuned rows are unaffected.Validation
On gfx1250 with the pinned FlyDSL 0.4.0:
tile_kmultiple, and rel_l2 against an fp64 dequantized reference is 1.66e-3 (bf16 output rounding, same as a divisible K). Covers a8w4/a4w4, post/mid-compute pipelines, carry prefetch, rolled drain, A-scale prologue, row-major A-scale, split-inner TDM, cluster 1x4/2x2, persistent workers,tile_k128/256/512, K <tile_k, and the GEMM1 swiglu epilogue. Before the fix the same check gave rel_l2 0.453 at K=640, i.e. sqrt(128/640).fused_moeend to end, 21 cases:inter_dim=640is bitwise equal to the weights zero-padded to 768 for a8w4 (AITER_FORCE_A8W4=1) and a4w4 at 16/256/2048 tokens, with default tiles,tile_k256 (tail),tile_k2512,tile_m32, carry prefetch andcluster_n4.bias[col]in every N tile (tile_n128/256), and GEMM1 matchesswiglu(bias)per tile.fused_moe(a8w4/a4w4) is now bitwise invariant acrosstile_n,tile_n2andtile_k.tile_k=128runs gemm1+gemm2 within −8% to +5% of the oldtile_k=256default, with bitwise-identical output.Known limitations (not addressed here)
inter_dimis not a multiple of 256 (e.g. 640) still fails in the standalone stage-2 quant kernel, which requiresfeat_dim % 256 == 0.tile_ndoes not divide is still unsupported; the stage-1 quant already requiresmodel_dim % 256 == 0.waves_per_tensor_tdm=4withm_warp=2produces NaN onmainas well; this PR does not change that.