Skip to content

[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

Closed
amd-pedghazi wants to merge 20 commits into
ROCm:mainfrom
amd-pedghazi:amd/dsv41-e385-s2row-xcd1

Conversation

@amd-pedghazi

@amd-pedghazi amd-pedghazi commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds aiter/configs/model_configs/dsv41_s2row_tuned_fmoe.csv with 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 is flydsl_moe1_afp8_wfp4_bf16_t64x128x256_w4_bnt0_gui_xcd1, which needs the A8W4 xcd_swizzle 1 that #7918 registers. Stacked on #7918 at b2fc31b5f5 (merge commit 233ade75ba); review only the commit 76d36475f3.

#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 1 flydsl_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 per fused_moe call 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_moe falls 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

  • New aiter/configs/model_configs/dsv41_s2row_tuned_fmoe.csv, picked up by the model_configs/ scan: rows for 16384 and 32768 tokens, stage 1 ..._bnt0_gui_xcd1, stage 2 flydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm64, block_m 64.
  • No code change.

Performance (if applicable)

Hardware Workload/configuration Before After Change
MI355X (gfx950), ROCm 7.2.4, FlyDSL 0.4.0 fused_moe, 16384 / 32768 tokens, real routing, one call plain stage-1 rows, without the PRs below these rows, with #7918 and #7917 (and the closed #7940, see below) -22.5% / -16.7%

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Only gfx950 is targeted, so MI250X and MI300X do not apply. At 16384 and 32768 tokens the fused_moe output 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_xcd1 stage 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

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Tuned-config rows only.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Needs #7918 (A8W4 stage 1 with xcd_swizzle 1).

Breaking Changes

None.

PR Self-Review

Reviewed revision

233ade75baab4a89c60167b4330097009ad49f1e

Behavior and intent

On gfx950, fused_moe for this shape at 16384 and 32768 tokens takes the _xcd1 stage 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 285579b6 on 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 with AITER_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 the fused_moe time 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. The us1 / us2 columns come from the plain stage-1 tuning of the same tiles, not from timing the _xcd1 stage 1. Not verified: other token counts, other GPUs.

eppaneamd and others added 16 commits November 6, 2026 09:08
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.
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 8213 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

cpersson-amd and others added 3 commits November 18, 2026 20:37
…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]>
@amd-pedghazi

Copy link
Copy Markdown
Contributor Author

@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 fused_moe call than ours (4096 and 8192 in #8650, 16384 in #8213; CUDA graph replay). Do you agree with point 1 there (for each key the faster row stays), or do you prefer point 3 (#8051 lands first, and we replace its three rows in a follow-up once #7918 is merged)? Our rows need #7918, which is still open, so they cannot land before it.

@fhuizing fhuizing closed this Dec 1, 2026
@fhuizing

fhuizing commented Dec 1, 2026

Copy link
Copy Markdown

I don't think this pr is very useful in general, as discussed I will do a thorough analysis on the required MoE work.

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.

5 participants