Skip to content

[Config] gfx950 DSv4.1-Flash TP4 A8W4 MoE rows for the 385-expert top-7 key - #8051

Draft
fhuizing wants to merge 1 commit into
mainfrom
folkert/dsv41-moe-a8w4-e385-top7
Draft

fhuizing wants to merge 1 commit into
mainfrom
folkert/dsv41-moe-a8w4-e385-top7

Conversation

@fhuizing

Copy link
Copy Markdown

Summary

Add gfx950 tuned rows for the DeepSeek-V4.1-Flash TP4 A8W4 MoE key (model_dim 5120, inter_dim 640, 385 experts, top-7) at 4096, 8192 and 16384 tokens, to aiter/configs/model_configs/dsv41_fp8fp4_tuned_fmoe.csv.

Motivation

With the shared expert fused as expert 385 (--enforce-shared-experts-fusion), SGLang looks up (5120, 640, 385, top-7) with FP8 activations and MXFP4 weights. No table has rows for this key, so prefill falls back to the heuristic pair: a stage 1 with BF16 output, a separate FP8 quant of the intermediate, and the atomic stage 2. MoE is about 31% of prefill GPU time in a DSv4.1-Flash TP4 trace on MI355X (19 full-M calls per 16k chunk).

Changes

  • 16384 and 8192 tokens: flydsl_moe1_afp8_wfp4_bf16_t128x128x256_bnt0_gui + flydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm128 (block_m 128).
  • 4096 tokens: flydsl_moe1_afp8_wfp4_bf16_t64x128x256_w4_bnt0_gui + flydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm64 (block_m 64).
  • Both pairs write FP8 from stage 1 (no separate quant) and use the deterministic reduce epilogue. Token counts up to 2048 keep the heuristic.

gemm_moe_tune.py (uniform random routing) picks the XCD-swizzled *_xcd4_fp8 stage 1. With the shared expert on every token that stage 1 is 15% slower than the unswizzled one, and the pair it picked is 3–7% slower than the heuristic end to end. The rows here were chosen with shared-expert routing instead (see below).

Performance (if applicable)

fused_moe end to end (sort, input quant, both stages, reduction), BF16 hidden states, gate_mode=INTERLEAVE, quant_dtype_a=fp8, intermediate_pad=64. Routing: top-6 of 384 routed experts plus expert 384 on every token. Skew 0 is uniform routed popularity; skew 1 adds an N(0, 1) per-expert logit bias. Median of 30 interleaved reps after 10 warm-up calls, one process.

Hardware Tokens Routing Before (us) After (us) Change
MI355X (gfx950) 16384 skew 0 2516.9 (896 TFLOP/s) 2221.5 (1015 TFLOP/s) 1.133x
MI355X (gfx950) 16384 skew 1 2234.7 2159.9 1.035x
MI355X (gfx950) 8192 skew 0 1308.0 1245.6 1.050x
MI355X (gfx950) 8192 skew 1 1326.3 1242.6 1.067x
MI355X (gfx950) 4096 skew 0 839.8 774.3 1.085x
MI355X (gfx950) 4096 skew 1 837.6 723.0 1.159x

TFLOP/s counts the padded inter_dim (640). Kernel breakdown at 16384 tokens, skew 0: stage 1 1383 → 1202 us (no separate 2 x 84 us quant), stage 2 953 us atomic → 663 us GEMM + 270 us reduction.

Testing

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

Documentation

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

Tuned-table rows only.

Dependencies

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

Breaking Changes

None.

PR Self-Review

Reviewed revision

ab3e993

Behavior and intent

Only the (5120, 640, 385, top-7) A8W4 key changes kernels, for padded token tiers 4096, 8192 and 16384. Other keys and token counts are untouched.

Validation and unverified scope

On MI355X (gfx950, FlyDSL 0.5.0):

  • AITER_LOG_TUNED_CONFIG=1: fused_moe logs using 2stage (kernelName1=..., kernelName2=...) with the new rows for 4096, 8192 and 16384 tokens.
  • python op_tests/test_moe_2stage.py --no-legacy --csv-filter t128x128x256_bnt0_gui t64x128x256_w4_bnt0_gui: the three new rows pass the strict check against the torch reference (no NaN, logits_diff 1.35e-4, the same as the existing DSv4.1 2304-inter rows at 1.37e-4).
  • pytest op_tests/tuning_tests/test_csv_validation.py op_tests/tuning_tests/test_config_shape_collision.py: 52 passed.

Not verified: serving end to end, and real DSv4.1 routing (the routing above is synthetic; the gain depends on expert-popularity skew, from 1.035x to 1.133x at 16384 tokens). Shapes at 2048 tokens and below were not measured and keep the heuristic.

Seen while testing, not changed here: flydsl_moe1_afp8_wfp4_bf16_*_xcd4_fp8 stage 1 returns NaN output under the routing above, both with flydsl_moe2_afp8_wfp4_bf16_t64x128x128_atomic (16384 tokens) and with flydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm64 (8192 tokens). The tuner's uniform routing does not show it.

PR-specific question

Will answer once the automated PR Self-Review comment is posted.

Changed op tests

None.

…-7 key

DeepSeek-V4.1-Flash at TP4 with the shared expert fused as expert 385 looks up
(model_dim 5120, inter_dim 640, E 385, top-7) with FP8 activations and MXFP4
weights. No table has rows for it, so prefill runs the heuristic pair with a
BF16 stage-1 output, a separate FP8 quant and the atomic stage 2.

Add rows for 4096, 8192 and 16384 tokens: FP8 stage-1 output with the layout
stage 2 and its reduce epilogue. The XCD-swizzled stage 1 that gemm_moe_tune.py
picks under uniform routing is slower with the shared expert on every token.
@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 8051 --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.

@peymanr

peymanr commented Nov 23, 2026

Copy link
Copy Markdown

This looks like the same bug as #8382, at your 385-expert, top-7 key. We reproduced it on MI355X (gfx950) at (5120, 640, 385, top-7) with intermediate_pad=64, using random MXFP4 weights and random routing:

  • Both flydsl_moe1_afp8_wfp4_bf16_t64x128x256_w4_bnt0_gui_xcd4_fp8 and ..._t64x256x256_w3_bnt0_gui_xcd4_fp8 returned non-finite output on 32 of 32 calls. Stage 2 was flydsl_moe2_layout_afp8_wfp4_bf16_t64x256x128_reduce_sbm64.
  • The non-swizzled ..._t64x128x256_w4_bnt0_gui_fp8 was finite on 0 of 32 failing calls, as were both xcd4 kernels at pad 0.
  • In these runs, every buffer allocated inside fused_moe was filled with 0xFF (NaN) before the call. This makes unwritten memory visible.

Cause. With a non-zero pad, the XCD remap in the xcd4 stage 1 counts one fewer N block than the kernel launches. With pad 64 and tile_k 256, the launch has 10 N blocks and the remap hands out 9. Stage-1 columns 576-639 and their scales are never written. The stage 2 here reads all 640 columns, so whatever those bytes hold reaches every output row.

Whether a call fails depends on what the reused memory held, not on routing. That may be why the tuner's runs looked clean, but we did not check this.

Fix. The fix is proposed in #8512. It is a one-term change so that the remap covers every launched N block. With the patch, the xcd4 kernel failed 0 of 32 calls and left no columns unwritten, against 32 of 32 unpatched. Its output was bit-identical to the non-swizzled kernel's. That run was at the 384-expert key; we did not rerun the patch at the 385 key.

Effect on this PR. The non-swizzled stage 1 does not run the remap, so this cause does not affect the rows proposed here. However, we only tested t64x128x256_w4_bnt0_gui_fp8, not t128x128x256_bnt0_gui.

Question. Did your NaN runs, and the gemm_moe_tune.py run, pass a non-zero intermediate_pad? We could not reproduce any failure at pad 0. If you saw NaN without a pad, it has another cause that this fix does not address.

Not tested:

  • The atomic stage 2 you also saw NaN with. We only used the reduce stage 2.
  • GPUs other than MI355X, or any ROCm/torch stack other than ROCm 10 / torch 2.13.
  • How often this fails under the normal allocator without the 0xFF fill.
  • End-to-end SGLang/vLLM serving, real DeepSeek-V4.1 weights, or multi-GPU tensor parallelism.
  • The gate-only and separate gate/up stage-1 paths, tile_k values other than 256, and split-K with the patch.
  • Kernel timing with the patch.

@amd-pedghazi

Copy link
Copy Markdown
Contributor

@fhuizing Hi, our draft #8213 adds a row for the same key (5120, 640, 385 experts, top-7) at 16384 tokens, plus one at 32768, in dsv41_s2row_tuned_fmoe.csv. AITER's config merge raises an error on a duplicate key, so only one of the two 16384 rows can land.

The two 16384 rows:

Stage 1 Stage 2 block_m Measured on
#8051 t128x128x256_bnt0_gui reduce_sbm128 128 AITER main, FlyDSL 0.5.0, synthetic shared-expert routing: 2221.5 us (skew 0)
#8213 t64x128x256_w4_bnt0_gui_xcd1 reduce_sbm64 64 AITER 285579b6 + ports of #7917 and #7918, FlyDSL 0.4.0, real routing: 1574.5 us (2031.5 us with the plain stage 1)

These numbers cannot be compared: the base, the FlyDSL version and the routing all differ. Also, our row needs #7918 (xcd_swizzle 1), and in our tests it needed #7917 as well; neither is merged.

Proposal: your 16384 row stays, because it works on main today. I will remove the 16384 row from #8213 and keep only 32768. When #7917 and #7918 are merged, we time both 16384 rows on the same build, with the same routing and timing method, and keep the faster one. Does that work for you?

Two more notes. Our planned rows for 512 to 2048 tokens will not overlap yours. We also see the NaN you reported for the _xcd*_fp8 stage 1, at 1536 and 2048 tokens, while the v2-layout stage 1 with the same XCD remap gives no NaN. I will open an issue with the details.

@amd-pedghazi

Copy link
Copy Markdown
Contributor

Hi @fhuizing, a follow-up to my comment of 11-23. I ran the op-level comparison I proposed, so here are the numbers.

Setup. One MI355X per token count, the whole fused_moe call (sort, quant, both stages, reduce), real prefill routing captured from a random 1k/1k serving run, 8 rounds, CUDA graph replay and eager. Median over the rounds, in us per call. FlyDSL 0.4.0 with #7917 and #7918 ported on AITER 285579b6. Variants: no tuned row at these sizes (heuristic), our rows (#8650 for 4096 and 8192, #8213 for 16384), your rows (#8051), and your 4096 and 8192 rows with our 16384 row. A repeat of the first variant is the drift control (within 1 %). The spread over the rounds is 0.1 to 1.3 %.

CUDA graph replay, us per call

M bucket no row ours #8051 #8051 vs ours
2176 4096 612.4 405.0 450.7 +11.3 %
3072 4096 631.8 438.5 510.8 +16.5 %
4074 4096 702.9 495.1 610.0 +23.2 %
5120 8192 900.5 629.5 804.0 +27.7 %
6144 8192 1004.9 700.8 894.5 +27.6 %
8192 8192 1155.3 821.0 1033.8 +25.9 %
12288 16384 1143.6 1143.2 (same 16384 row as the no-row variant) 1445.4 +26.4 %
16384 16384 1487.5 1487.0 (same row) 1846.4 +24.2 %

Eager gives the same picture (+7 to +21 % at 4096, +25 to +26 % at 8192, +24 to +25 % at 16384). Your 4096 and 8192 rows are still 10 to 27 % faster than no row, so they help; ours help more.

Why. At 8192 tokens our stage 1 (t64x128x256, XCD swizzle on) takes 477 us against 653 us for yours (t128x128x256); stage 2 takes 271 and 296 us.

Limits. This is op level only (no serving run). It ran on FlyDSL 0.4.0 and on our routing, not on your synthetic shared-expert routing and FlyDSL 0.5.0. Our rows need the XCD-swizzled stage 1 of #7918, which is not merged yet; yours work on main today. If you prefer another timing method (routing, number of calls, GPU count), tell me and I will run it.

Proposal.

  1. For each of the three keys the faster row stays: 4096 and 8192 from [FlyDSL] [Perf] Add DeepSeek-V4.1-Flash TP4 A8W4 MoE rows for 512-8192 tokens with the XCD-remap stage 1 on gfx950 (E385, top-7) #8650, 16384 from [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. Your rows would be dropped from those keys, or kept for the time before [FlyDSL] MoE stage 1: XCD remap over the valid rows only #7918 lands, as you prefer.
  2. I do not remove the 16384 row from [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 for now, because it is faster by about 25 %. I said on 11-23 that I would; if you object, tell me and I will follow the agreement we make here.
  3. If you would rather keep the rows that work on main today, a second option is that [Config] gfx950 DSv4.1-Flash TP4 A8W4 MoE rows for the 385-expert top-7 key #8051 lands first, and we replace its three rows in a follow-up once [FlyDSL] MoE stage 1: XCD remap over the valid rows only #7918 is merged (the config merge raises an error when two files hold the same key at the same token count, so the rows cannot sit side by side).

I can rerun with your method, or on a build with FlyDSL 0.5.0, if that helps.

This branch has not been deployed

No deployments
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.

3 participants