Skip to content

[Config] [Perf] Retune DSV4 EP8 a8w4 fused-MoE rows for M 2-8 and 1024-8192 on gfx950 - #6928

Merged
yifehuan merged 1 commit into
ROCm:mainfrom
jbelofamd:fmoe-dsv4-a8w4-ep8
Oct 27, 2026
Merged

yifehuan merged 1 commit into
ROCm:mainfrom
jbelofamd:fmoe-dsv4-a8w4-ep8

Conversation

@jbelofamd

Copy link
Copy Markdown
Contributor

Summary

Seven rows of dsv4_fp8fp4_tuned_fmoe.csv for DeepSeek-V4 with 8-way expert parallelism (7168 / 3072,
48 local experts, top-k 6, fp8 activations × MXFP4 weights) are replaced with faster kernel pairs. The
aiter.fused_moe call gets 1.17-2.22x faster at those M. At M = 8 the current stage-1 kernel is 2.2x
slower than the untuned heuristic.

Motivation

These rows are hit on current main: since #5734 the runtime key for DSV4 EP8 is top-k 6, which is how the
table keys them. In an EP8 decode or prefill step every rank calls this shape once per MoE layer.

M current row new row AITER default (µs) new row (µs) speedup
2 ..._t32x128x256_w4_gui_fp8 / layout_..._t32x128x256_reduce_nt_sbm32 ..._t32x64x256_w3_bnt0_gui_fp8 / layout_..._t32x128x256_atomic_nt_sbm32 45.6 39.0 1.17x
4 ..._t32x128x256_w4_gui_fp8 / layout_..._t32x256x256_reduce_nt_sbm32 ..._t32x64x256_w3_bnt0_gui_fp8 / layout_..._t32x128x256_atomic_nt_sbm32 49.1 37.9 1.30x
8 ..._t32x128x256_w3_gui_xcd4 / layout_..._t32x128x256_reduce_nt_sbm32 ..._t32x128x256_w3_gui_fp8 / layout_..._t32x128x256_atomic_nt_sbm32 126.2 56.8 2.22x
1024 ..._t128x256x256_gui_fp8 / layout_..._t128x256x128_reduce_nt_sbm128, bm 128 ..._t32x128x256_w3_gui_fp8 / layout_..._t32x128x256_atomic_nt_sbm32, bm 32 410.5 292.6 1.40x
2048 ..._t128x256x256_w3_gui_fp8 / layout_..._t128x256x256_reduce_sbm128, bm 128 ..._t64x256x256_w3_gui_fp8 / layout_..._t64x256x256_atomic_nt_sbm64, bm 64 496.8 332.4 1.49x
4096 ..._t128x256x256_gui_fp8 / layout_..._t128x256x256_reduce_sbm128 ..._t128x256x256_w3_gui_fp8 / ..._t64x256x256_atomic_sbm128 581.6 459.2 1.27x
8192 ..._t128x256x256_w3_bnt0_gui_fp8 / layout_..._t128x256x256_reduce_sbm128 ..._t128x256x256_w2_bnt0_gui_fp8 / ..._t64x256x256_atomic_sbm128 875.9 661.8 1.32x

Kernel names are abbreviated: stage 1 is flydsl_moe1_afp8_wfp4_bf16_…, stage 2 flydsl_moe2_[layout_]afp8_wfp4_bf16_….
At M = 8 the untuned heuristic takes 58.0 µs, so the current row's t32x128x256_w3_gui_xcd4 stage 1 is the
regression.

Changes

  • aiter/configs/model_configs/dsv4_fp8fp4_tuned_fmoe.csv: seven rows of the 7168 / 3072 / E48 / top-k 6
    shape (M = 2, 4, 8, 1024, 2048, 4096, 8192) get new kernelName1, kernelName2, block_m and us. No
    rows are added or removed.
  • us is the whole fused_moe call (below), so us1, us2, err1 and err2 are empty and tflops and
    bw are 0, as in the existing M = 32768 and 131072 rows. Stage-2 sbm matches block_m in every row.

How the rows were found and measured

One MI355X runs one EP rank's call the way the serving engine makes it: aiter.fused_moe with
gate_mode="interleave", swiglu_limit=10, quant_dtype_a=fp8, expert_mask with this rank's 48 of 384
experts, and top-k 6 routing drawn uniformly over all 384 experts, so about one route in eight is local.
Three layers with different weights are called in turn, so weights are not reused from cache between
calls. Time per call is the median of CUDA-graph replays for M ≤ 8192 (eager above 1.5 ms). Candidates
were every kernel pair in AITER's own rows for this shape plus pairs from our serving tables, injected into
cfg_2stages under the exact lookup key, at every M. A candidate counts only if its output error is no worse
than the heuristic's. The rows proposed were then timed again alone, three repetitions each (the numbers
above).

This differs from the per-stage tuner, which times each stage with every route on a local expert (eight
times the per-rank work of uniform EP8 routing). That probably explains why it picked these rows.

Output error, relative L2 against an fp32 reference of the dequantized weights: 0.047-0.049 for both the
current and the new rows at every M (0 at M = 1).

Rows not changed

Testing

  • With this patch applied to 00feaa3 and nothing injected, AITER picks the new row at all seven M. In the same
    run, the current rows injected back give:

    M 2 4 8 1024 2048 4096 8192
    current row (µs) 45.9 47.4 125.9 405.8 490.9 592.2 862.4
    with this patch (µs) 38.6 38.0 57.4 296.2 333.5 446.9 644.8

    At every other M AITER's choice is unchanged, within 2.5% of the current row.

  • python3 -m unittest op_tests.tuning_tests.test_csv_validation: 19 tests pass, including the stage-2 sort
    block check and the duplicate-key check. git diff --check is clean.

  • Performance benchmarks run

  • Unit tests added/updated: not applicable (table change)

  • Tested on MI250X / MI300X: not applicable, gfx950 rows

MI355X (gfx950, 256 CUs), torch 2.12.0+rocm7.14.0, FlyDSL 0.4.0, AITER 00feaa3.

Dependencies

  • No new third-party dependencies added

Breaking Changes

None. Only the kernel choice for these seven buckets changes.

… gfx950

Replace seven rows of the 7168/3072, 48-expert, top-k 6 table (DeepSeek-V4 with
8-way expert parallelism, fp8 activations x MXFP4 weights). Each was timed as
the whole aiter.fused_moe call on one EP rank, with routing drawn over all 384
experts and the 336 non-local ones masked, CUDA-graph replays for M <= 8192.

  M      before     after     speedup
  2       45.6 us    39.0 us   1.17x
  4       49.1 us    37.9 us   1.30x
  8      126.2 us    56.8 us   2.22x
  1024   410.5 us   292.6 us   1.40x
  2048   496.8 us   332.4 us   1.49x
  4096   581.6 us   459.2 us   1.27x
  8192   875.9 us   661.8 us   1.32x

At M=8 the old stage-1 kernel (t32x128x256_w3_gui_xcd4) is slower than the
untuned heuristic (58.0 us). Output error is unchanged (0.047-0.049 relative
L2 against an fp32 reference, same as the rows replaced).

us is the whole-call time; us1/us2/err1/err2 are left empty because the rows
did not come from the per-stage tuner.

Signed-off-by: Jon Belof <[email protected]>
@jbelofamd
jbelofamd requested a review from a team October 26, 2026 03:20
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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 gfx1201 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 6928 --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.

@github-actions github-actions Bot changed the title [Perf] Retune DSV4 EP8 a8w4 fused-MoE rows for M 2-8 and 1024-8192 on gfx950 [Config] [Perf] Retune DSV4 EP8 a8w4 fused-MoE rows for M 2-8 and 1024-8192 on gfx950 Oct 26, 2026
@zufayu
zufayu requested a review from yifehuan October 27, 2026 01:14

@yifehuan yifehuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yifehuan
yifehuan merged commit 55306fe into ROCm:main Oct 27, 2026
56 checks passed
phambinhfin added a commit to phambinhfin/aiter that referenced this pull request Oct 27, 2026
The gfx942 / 304 CU rows for model_dim 6144, inter_dim 256, 257 experts, top-9 -
the TP8 decode shape - select `fmoe_bf16_blockscaleFp8_g1u1_vs_silu_1tg_32x128`
and its `ps` variant at M = 1 and 2, then switch to
`fmoe_bf16_a16_blockscaleFp8_g1u1_vs_silu_1tg_16x128_flat_pf3` from M = 4 on.

The flat kernel is faster at M = 1 and 2 as well. Point those two rows at it.

One MI325X, stock aiter, same image and process throughout; the only variable is
this file. Weights rotate over 8 independent expert sets so a call does not
reread what the previous call left in cache. Median of 5 rounds:

       M   32x128 (current)   flat_pf3 (this change)   speedup
       1         99.16 us             60.30 us          1.64x
       2         99.65 us             60.97 us          1.63x
       4         64.39 us             64.53 us          1.00x
       8         80.92 us             81.39 us          0.99x
      16         69.87 us             71.46 us          0.98x
      32 .. 2048  unchanged within 1%

Only M = 1 and 2 are touched: `get_padded_M()` rounds M up to the next power of
two, so 3-4 take the M = 4 row and 5-8 take M = 8. Everything from M = 4 up is
an untouched control, and the arms agree there to within 1%, which also bounds
the measurement noise.

Output against the current row, relative L2: 1.5e-2 at M = 1 and 1.7e-2 at M = 2.
The same comparison at M = 4 and 8, where both tables are identical and the same
kernel runs, gives 6.8e-3, so most of that is the kernel's own run-to-run
variation rather than the change.

`us` is the whole `fused_moe` call, so `us1`, `us2`, `err1` and `err2` are left
empty and `tflops` and `bw` are 0, following ROCm#6928.

Signed-off-by: Pham Binh <[email protected]>
zhiding512 added a commit that referenced this pull request Nov 4, 2026
…hem in test_moe_ep

A caller behind an expert-parallel dispatch passes fused_moe an expert mask,
and the launches it masks compile for the mask's length: the gfx950 masked
stage-2 reduction and route-guarded GEMM2, the gfx1250 g2l route and bf16
gather-reduce. No tuned row records that length, so the AOT build never
compiled them and EP serving JIT-compiled them on the request path.

aiter/aot/flydsl/moe_ep_profiles.csv lists EP callers as what one rank passes
fused_moe: local experts, routing columns, expert-mask length, largest M.
moe.py replays each profile with the mask at both ends of every get_padded_M
bucket up to that M (bisecting between them as for rows), with and without
num_local_tokens, against the tuned tables serving reads, so a profile needs
no tuned row. --ep-profile selects profile tables; without --csv and
--ep-profile both defaults are replayed, and run_aot replays both.

The default table covers gfx950 Kimi-K3 EP8, DeepSeek-V4-Pro EP8 (EPLB r0,
r32, r64) and EP16, GLM-5.3-Flash EP8/EP4/EP2, and gfx1250 Kimi-K3 EP8/EP16
and DeepSeek-V4-Pro EP4, from the EP rows tuned in #5804, #6928, #6435,

op_tests/test_moe_ep.py -t aot_ep_profiles, first in the defaults, runs every
profile of the GPU's arch through the EP fused_moe call in FlyDSL run-only
mode and requires logits_diff < 0.01. The MXFP4 cases now pin quant_dtype_a
instead of setting env switches, accept SiTUv2, and compare against a
stage-wise reference that quantizes a4w4 activations as the kernels do.

Co-authored-by: Cursor <[email protected]>
phambinhfin added a commit to phambinhfin/aiter that referenced this pull request Nov 5, 2026
The gfx942 / 304 CU rows for model_dim 6144, inter_dim 256, 257 experts, top-9 -
the TP8 decode shape - select `fmoe_bf16_blockscaleFp8_g1u1_vs_silu_1tg_32x128`
and its `ps` variant at M = 1 and 2, then switch to
`fmoe_bf16_a16_blockscaleFp8_g1u1_vs_silu_1tg_16x128_flat_pf3` from M = 4 on.

The flat kernel is faster at M = 1 and 2 as well. Point those two rows at it.

One MI325X, stock aiter, same image and process throughout; the only variable is
this file. Weights rotate over 8 independent expert sets so a call does not
reread what the previous call left in cache. Median of 5 rounds:

       M   32x128 (current)   flat_pf3 (this change)   speedup
       1         99.16 us             60.30 us          1.64x
       2         99.65 us             60.97 us          1.63x
       4         64.39 us             64.53 us          1.00x
       8         80.92 us             81.39 us          0.99x
      16         69.87 us             71.46 us          0.98x
      32 .. 2048  unchanged within 1%

Only M = 1 and 2 are touched: `get_padded_M()` rounds M up to the next power of
two, so 3-4 take the M = 4 row and 5-8 take M = 8. Everything from M = 4 up is
an untouched control, and the arms agree there to within 1%, which also bounds
the measurement noise.

Output against the current row, relative L2: 1.5e-2 at M = 1 and 1.7e-2 at M = 2.
The same comparison at M = 4 and 8, where both tables are identical and the same
kernel runs, gives 6.8e-3, so most of that is the kernel's own run-to-run
variation rather than the change.

`us` is the whole `fused_moe` call, so `us1`, `us2`, `err1` and `err2` are left
empty and `tflops` and `bw` are 0, following ROCm#6928.

Signed-off-by: Pham Binh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants