Repository navigation
[Config] [Perf] Add DeepSeek-V4.1-Flash TP4 A8W4 MoE rows for 16384 / 32768 tokens with the XCD-remap stage 1 on gfx950 (E385, top-7) - #8213
Conversation
Both FlyDSL MoE GEMM stages remap their workgroups for XCD locality with
wgid = (lin % 8) * (n // 8) + lin // 8
which is a permutation of the n workgroups only when n is a multiple of
8. Otherwise n % 8 tiles run twice and n % 8 tiles never run: stage 1
leaves rows of its output unwritten (and split-K stage 1 adds some
partial sums twice), the atomic stage 2 adds some expert contributions
twice and drops others, and the reduce stage 2 reads slots nobody
wrote. n depends on the token count, so an `_xcd` kernel can be right
at one token count and wrong at the next.
xcd_remap_bx_by already has the remainder term. Move its remap into
xcd_remap_grid, which takes the grid size from the caller, and call it
from both MoE stages. Also correct the stage-2 comment that called
xcd_swizzle an ignored argument.
Add test_flydsl_moe_xcd_swizzle_uneven_grid: both stages with
xcd_swizzle=4 on a 2 x 18 grid, every tile holding a routed row.
The same fix was proposed in ROCm#4315, closed for inactivity.
Signed-off-by: Rony Leppänen <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The MoE stages put M blocks on grid y and N blocks on grid x, so they pass grid_y as grid_m; naming the arguments makes that visible. The docstring now states the helper's xcd_swizzle > 0 precondition, which xcd_remap_bx_by checks before calling it. No compiled kernel changes: the gfx950 ISA of both MoE stages, the persistent and heterogeneous stage 2, and both GEMM callers is byte-identical to the previous commit's. Signed-off-by: Rony Leppänen <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI runs op_tests/*.py as sharded scripts, and op_tests/flydsl_tests is not in the plan, so test_flydsl_moe_xcd_swizzle_uneven_grid never ran there. The Focused regression tests step runs `python3 -m pytest -q tests` on pull requests (MI35X shard 0), so the test moves, unchanged, to tests/test_flydsl_moe_xcd_swizzle.py. It imports its data generator, tolerance check, tile_k helper and gfx950 skip from the op test file, which keeps the distinct_experts argument of _generate_a8w4_gui_data. On MI355X (torch 2.13.0+rocm10.0.0, FlyDSL 0.4.2, an empty FlyDSL cache per run): with the three kernel files of the merge-base the test fails (xcd4_uneven_grid_stage1: output has NaN), with this commit's it passes, 0 skipped; the whole tests/ directory in CI's layout runs in 13 s. Signed-off-by: Rony Leppänen <[email protected]> Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The gfx950 skip imported from the op test uses get_gfx(), which follows GPU_ARCHS and takes its last entry, so on an MI355X with GPU_ARCHS='gfx950;gfx942' the regression was skipped. It now checks get_gfx_runtime(), the running GPU, in the test body, as op_tests/test_flydsl_pa_decode.py does. On MI355X with GPU_ARCHS='gfx950;gfx942', get_gfx() returns gfx942 and get_gfx_runtime() gfx950. Under the other settings tried (unset, 'gfx950', 'gfx942;gfx950') both return gfx950. Signed-off-by: Rony Leppänen <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py # op_tests/flydsl_tests/test_flydsl_moe.py
The stage-1 grid is sized for the worst-case padded row count, and the xcd_swizzle remap spread that whole grid over the 8 XCDs, so the empty padding tail (11-25% of the tiles under real routing) landed on the last XCDs. Remap only the rows num_valid_ids covers; rows past them keep their ids and exit as before. Register xcd_swizzle=1 for every stage-1 dtype, not only a16w4. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
With the stage-1 remap over valid rows, the xcd_swizzle=1 stage 1 beats the rows ROCm#7656 picked. fused_moe on MI355X, real routing, cache flushed, against the ROCm#7656 rows on the same build: 1536 tokens -6.3%, 3000 -6.5%, 4096 -10.0%, 8192 -2.9%, 12000 -4.2%, 16384 -0.6%. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
…_ids Routing that leaves the worst-case stage-1 grid longer than the valid sorted blocks, with xcd_swizzle 1 and 4; a valid tile the remap skips leaves NaN in the output. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
FP8-A stage 2 sizes its grid from occupancy and ignores the name's persist flag, so t32x128x128_atomic_bnt2_persist and t32x128x128_atomic_bnt2 compile and launch the same kernel (identical compile arguments, persist_m=1). Name the row by the kernel it runs. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
…ens with the XCD-remap stage 1 The E385 / top-7 fused_moe shape of DeepSeek-V4.1-Flash at TP4 has no tuned rows at 16384 and 32768 tokens, so it falls back to the heuristic kernels. These two rows pick the stage-1 kernel with xcd_swizzle 1, which ROCm#7918 registers for A8W4, and the reduce stage 2.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…h-grid remap ROCm#7796 was closed without merging; ROCm#7822 handles the stage-1 padding in the dispatch instead. Drop its padding changes and tests, but keep the remap over the launch grid: stage 1 launches tile2_pad more N columns than the count the remap recomputed, so with intermediate_pad (DSv4.1 TP4: 576 + 64) an xcd_swizzle stage 1 left the padded columns unwritten. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
DSv4.1 TP4 padding (576 of 640 columns, tile_k 256): stage 1 launches a tile2_pad N block past the unpadded width. xcd_swizzle 1 and 4 must write the same output as xcd_swizzle 0, padded columns included. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
Restore dsv41_fp8_tuned_fmoe.csv; the xcd1 stage-1 rows come with the retune of the DSv4.1 TP4 rows. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Carl Persson <[email protected]>
|
@fhuizing, a small ping on my comment above with the op-level comparison: on the same build and routing, the rows here take 11 to 28 % longer per |
|
I don't think this pr is very useful in general, as discussed I will do a thorough analysis on the required MoE work. |
Summary
Adds
aiter/configs/model_configs/dsv41_s2row_tuned_fmoe.csvwith two gfx950 rows for the DeepSeek-V4.1-Flash TP4 A8W4 MoE shape (model_dim 5120, inter_dim 640, 385 experts, top-7) at 16384 and 32768 tokens. Stage 1 isflydsl_moe1_afp8_wfp4_bf16_t64x128x256_w4_bnt0_gui_xcd1, which needs the A8W4xcd_swizzle1 that #7918 registers. Stacked on #7918 atb2fc31b5f5(merge commit233ade75ba); review only the commit76d36475f3.#8051 (draft) adds rows for the same shape at 4096, 8192 and 16384 tokens to
dsv41_fp8fp4_tuned_fmoe.csv. Its 16384 row has the same key as this PR's 16384 row, with a different kernel pair (stage 1flydsl_moe1_afp8_wfp4_bf16_t128x128x256_bnt0_gui, stage 2..._reduce_sbm128, block_m 128) that needs no open PR. AITER's config merge raises an error when two files have a row with the same key, so only one of the two 16384 rows can land; the 32768 row does not overlap. On the same build and the same real prefill routing, #8051's 16384 row takes 24 to 26 % longer perfused_moecall than this PR's at 12288 and 16384 tokens (CUDA graph and eager; table in the #8051 thread). I proposed there to keep this row unless the #8051 author objects.Motivation
This shape has no tuned rows at these token counts, so
fused_moefalls back to its heuristic kernels. DeepSeek-V4.1-Flash prefills long prompts in 16,384-token chunks, so the 16384 row covers most of their MoE calls.Changes
aiter/configs/model_configs/dsv41_s2row_tuned_fmoe.csv, picked up by themodel_configs/scan: rows for 16384 and 32768 tokens, stage 1..._bnt0_gui_xcd1, stage 2flydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm64, block_m 64.Performance (if applicable)
fused_moe, 16384 / 32768 tokens, real routing, one callTesting
Only gfx950 is targeted, so MI250X and MI300X do not apply. At 16384 and 32768 tokens the
fused_moeoutput matched the plain stage-1 control bit for bit on the same inputs and routing. In SGLang serving (DeepSeek-V4.1-Flash TP4, DSpark, 4 x MI355X), both runs with the rows logged the_gui_xcd1stage 1 for these rows; GSM8K 96.11 / 96.34 against 96.27 / 97.03 for the control. A random-dataset serving A/B of these rows is pending.Documentation
Tuned-config rows only.
Dependencies
Needs #7918 (A8W4 stage 1 with
xcd_swizzle1).Breaking Changes
None.
PR Self-Review
Reviewed revision
233ade75baab4a89c60167b4330097009ad49f1eBehavior and intent
On gfx950,
fused_moefor this shape at 16384 and 32768 tokens takes the_xcd1stage 1 and the reduce stage 2 instead of the heuristic fallback; other shapes and token counts are unchanged.Validation and unverified scope
Measured with #7918, #7917 and #7940 ported together to AITER
285579b6on FlyDSL 0.4.0 (the AITER and FlyDSL of the ROCm 7.2.4 SGLang image), not on this branch. #7940 (streaming loads for large FP8 stage-2 reductions, used only withAITER_FLYDSL_STAGE2_FP8=1) was closed without merging on 11-19 because its gain was small and only applied to that opt-in path, so it is not a dependency. These rows do not need it: on the same base, #7940 alone changed thefused_moetime by -0.5% at 16384 tokens and +0.3% at 32768, which is small next to the change in the table; the gain comes from #7918 together with #7917. Theus1/us2columns come from the plain stage-1 tuning of the same tiles, not from timing the_xcd1stage 1. Not verified: other token counts, other GPUs.