[Perf][FlyDSL] Tune DeepSeek V4 fused MoE for C1/C2/C32/C64 decode - #4314
Open
Fangzhou-Ai wants to merge 2 commits into
Open
[Perf][FlyDSL] Tune DeepSeek V4 fused MoE for C1/C2/C32/C64 decode#4314Fangzhou-Ai wants to merge 2 commits into
Fangzhou-Ai wants to merge 2 commits into
Conversation
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
from
July 21, 2026 05:43
b2a4557 to
3eedab1
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
from
July 21, 2026 05:49
3eedab1 to
b2a4557
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
from
July 21, 2026 06:33
b2a4557 to
1d5dc26
Compare
Fangzhou-Ai
marked this pull request as ready for review
July 21, 2026 08:54
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
from
July 21, 2026 17:19
b752196 to
7591eb1
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
2 times, most recently
from
July 28, 2026 07:20
b752196 to
ff7fa8d
Compare
Fangzhou-Ai
changed the base branch from
afz/moe-xcd-remainder-fix
to
afz/dsv4-fmoe-bm16-post4
July 28, 2026 07:20
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 28, 2026 21:05
7b833d0 to
28e167f
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
from
July 28, 2026 21:06
ff7fa8d to
86c94af
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 28, 2026 21:21
28e167f to
6ae0905
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
2 times, most recently
from
July 30, 2026 15:24
d5821d9 to
a52d2b7
Compare
Enable 16-row FP8-activation/FP4-weight FlyDSL kernels for the gfx950 DeepSeek V4 7168/512/E385/top-k7 sparse-decode shape, selecting them only for the C32 and C64 production rows. Round activation-scale resource bounds to 32 rows so the BM16 path preserves the shuffled scale-buffer allocation. This tuning layer is stacked on the fused heterogeneous MoE change, so the 32-row rounding lands once in the shared kernel body and covers both the ordinary and heterogeneous paths. Both selected BM16 kernels use XCD0, and C4, C16, and C128+ rows remain unchanged. The XCD remainder fix is an independent change and is no longer part of this chain. Isolated stage timing improved from 142.2405 to 82.0800 us at C32 (1.73x) and from 249.7220 to 129.3620 us at C64 (1.93x). Repeated outputs were bitwise stable, and GSM8K completed 1,319 samples with 95.375% strict match and 95.299% flexible extraction. AI assistance was used to implement, test, benchmark, and document this change. Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Fangzhou Ai <fangzhouai@gmail.com>
Select the kw4 stage-1 route for the E385/top-k7 C1 and C2 rows while keeping the existing stage-2 kernels unchanged. Paired same-GPU dispatch measurements improve total stage time by 29.38% at C1 and 22.53% at C2. Fixed-seed strict-reference checks pass without NaNs, and matched FSE-on serving improves output throughput by 8.09% at C1 and 0.85% at C2. AI assistance was used to tune, validate, benchmark, and document this change. Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Fangzhou Ai <fangzhouai@gmail.com>
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
from
July 30, 2026 15:56
a52d2b7 to
57e848f
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 30, 2026 15:59
6ae0905 to
2a4cb13
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
7168/512/E385/top-k7at C1, C2, C32, and C64.kw4stage-1 kernel for C1/C2 while retaining their existing stage-2 selections.Stack and scope
This is the top layer of the DeepSeek-V4 stack and targets #4269's staging branch directly:
The PR contains two tuning commits across four files. The C1/C2 follow-up is CSV-only and changes exactly two rows. The C32/C64 commit contains the tuned CSV, the three ordinary FlyDSL BM16 enablement changes, and the BM16 scale-boundary regression in
op_tests/test_moe_2stage.py.#4269 is the base because it moves the ordinary mixed-MoE builders into
mixed_moe_gemm_2stage_common.py, which this PR modifies. The tuning itself remains separate from FHMoE dispatch and adds no FHMoE API fields.Why the source changes are required
The CSV cannot enable BM16 alone:
tile_m=16registry entry, runtime lookup rejects the configured kernel and AOT skips it;An independent probe with only the registry entry injected produced NaNs and 99.9% differing elements. Applying all three enablement changes completed without NaNs.
Tuned routes
The table compares the base and tuned rows in
dsv4_fp8fp4_tuned_fmoe.csv. Commonflydsl_moe{1,2}_afp8_wfp4_bf16_prefixes are omitted.t32x128x256_w4_gui_fp8->t32x64x256_w4_gui_kw4_fp8t32x256x256_atomict32x128x256_w2_gui_fp8->t32x64x256_w4_gui_kw4_fp8t32x256x256_atomic_xcd4t32x128x256_w3_gui_xcd4_fp8->t16x128x256_w3_gui_fp8t32x256x256_atomic_bnt2_xcd4_persist->t16x256x256_atomict32x128x256_w3_gui_xcd4_fp8->t16x128x256_w3_gui_fp8t32x256x256_atomic_bnt2_xcd4->t16x256x256_atomicThe CSV
err1/err2values are the tuner's stored stage pass values, not a claim of bitwise end-to-end equality.Rebase and validation
The two tuning commits were restacked patch-identically onto corrected #4269 head
2a4cb1339;git range-diffreports both commits unchanged. GitHub now reports this PR mergeable with a clean merge state.The stack was installed editable with
PREBUILD_KERNELS=0and tested using the repository's unchanged scripts on 8×gfx950 withTP=8, expert parallelism disabled, and performance concurrency 4. The server selected native-FP8 shared-expert fusion, internal E=385/top-k=7, and the tuned C1/C2 rows on every rank.GSM8K, all 1,319 samples, 20-shot, concurrency 64,
max_tokens=2048, temperature 0:All requests returned HTTP 200 without retries or server errors. Compared with the immediately preceding same-script baseline, both metrics changed by -4/1319 answers (-0.303 percentage points).
InferenceX 8K-input/1K-output, concurrency 4, 40/40 requests:
Compared with the immediately preceding TP8/C4 run, output throughput improved 0.41%, TTFT improved 2.75%, and TPOT improved 0.38%.
The final base-only change after the runtime run forwards
pass_swiglu_limitin #4269's AOT adapter and does not alter these runtime kernels or routes.Static validation:
Result: passed.
Duplicate-work check
Open-PR searches found no equivalent DeepSeek-V4 C1/C2/C32/C64 FP8/FP4 tuning change. #3835 tunes the separate
dsv4_fp4_tuned_fmoe.csvA4W4 configuration and does not overlap this patch.AI assistance
OpenAI Codex was used to audit, implement, test, benchmark, restack, and document this change. The human submitter reviewed the changes and is responsible for understanding and defending them end-to-end.