Repository navigation
[Feature][FlyDSL] Add fused heterogeneous MXFP4/FP8 shared-expert MoE (FHMoE) and share the mixed-MoE kernel builders - #4269
Merged
Conversation
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 16, 2026 21:21
c2142ac to
bdd87fc
Compare
Fangzhou-Ai
marked this pull request as ready for review
July 16, 2026 21:24
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 16, 2026 21:26
bdd87fc to
fd07bda
Compare
Fangzhou-Ai
marked this pull request as draft
July 16, 2026 21:28
Fangzhou-Ai
marked this pull request as ready for review
July 16, 2026 21:28
Fangzhou-Ai
marked this pull request as draft
July 16, 2026 21:32
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
2 times, most recently
from
July 16, 2026 22:15
01a1de9 to
21bb7b1
Compare
Fangzhou-Ai
marked this pull request as ready for review
July 16, 2026 22:17
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 19, 2026 16:55
21bb7b1 to
e9572c9
Compare
Fangzhou-Ai
force-pushed
the
afz/custom-ar-ipc-publication
branch
from
July 20, 2026 18:42
036f04f to
dc528ea
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
2 times, most recently
from
July 20, 2026 20:41
6943b0c to
f0f528b
Compare
Contributor
Author
Fangzhou-Ai
marked this pull request as draft
July 21, 2026 05:19
This was referenced Jul 21, 2026
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 21, 2026 17:54
cc36e67 to
f167f44
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
from
July 21, 2026 18:03
1d5dc26 to
7591eb1
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 21, 2026 18:03
f167f44 to
a27e2ef
Compare
Contributor
|
@Fangzhou-Ai aiter/ops/flydsl/kernels/fhmoe.py is duplicated from original moe implement which makes the moe really hard to maintain. |
Contributor
Author
Yes, it's a good point, I was thinking to separate the common code into a new file then both moe and fhmoe can import them to reduce duplication. Do you think it's a good idea here? |
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 24, 2026 17:06
a27e2ef to
39d2259
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-bm16-tuning
branch
from
July 24, 2026 17:10
7591eb1 to
b752196
Compare
Contributor
Author
|
@yadaish I have revised this PR with a new file contains the common code to minimize the future frictions between these 2 kernels. |
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
from
July 28, 2026 07:20
39d2259 to
7b833d0
Compare
Fangzhou-Ai
force-pushed
the
afz/dsv4-fmoe-bm16-post4
branch
2 times, most recently
from
July 28, 2026 21:21
28e167f to
6ae0905
Compare
valarLip
previously approved these changes
Jul 30, 2026
Add a dedicated FHMoE dispatch, custom op, FlyDSL runtime, GPU kernel, AOT path, and correctness suite for MXFP4 routed experts with a native FP8 shared expert. Keep ordinary MoE schemas and compiler APIs unchanged behind narrow compatibility bridges. Start every FHMoE runtime and AOT job at XCD0 so this enablement has one validated scheduling contract. FHMoE-specific XCD performance tuning can follow as a separate stacked change. Validation covers exact DSV4 and small-shape sweeps, precision oracles, graph replay, compatibility, invalid contracts, XCD0 runtime/AOT normalization, Ruff, py_compile, and diff checks. AI assistance was used to implement, test, review, and organize this change. Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Fangzhou Ai <fangzhouai@gmail.com>
Move the duplicated stage-1 and stage-2 FlyDSL builders into one parameterized implementation while retaining thin cached MoE and FHMoE facades with their existing launcher ABIs and module identities. Preserve FHMoE XCD swizzling through runtime and AOT dispatch, and keep shared-expert validation fail-closed. AI assistance was used to implement, test, and review this change. Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Fangzhou Ai <fangzhouai@gmail.com>
Keep the public flydsl_moe_stage1 wrapper aligned with the shared implementation by forwarding Situv2 tuning and intra-block K-batching arguments. Add API regression coverage for the forwarded parameters. AI assistance was used to implement, test, and review 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-fmoe-bm16-post4
branch
from
July 30, 2026 15:24
6ae0905 to
bbfbda6
Compare
Forward pass_swiglu_limit through the heterogeneous AOT adapter so it remains compatible with the shared MoE precompile harness. Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: Fangzhou Ai <fangzhouai@gmail.com>
valarLip
approved these changes
Aug 1, 2026
This was referenced Aug 7, 2026
5 tasks done
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
fused_moe_custom-op schema and ordinary kernel compiler APIs.mixed_moe_gemm_2stage_common.py, leaving thin per-path facades.mainlauncher, XCD-swizzle, runtime, and AOT contracts, including the current stage-1situ_beta,situ_linear_beta,k_batch_intra_block, andpass_swiglu_limitarguments.Stack and review scope
This PR is the feature base and targets current
main. #4314 contains the DeepSeek-V4 C1/C2/C32/C64 tuning rows and is stacked on it:This PR contains four commits across ten paths:
feat(flydsl): add fused heterogeneous MoErefactor(flydsl): share MoE and FHMoE kernelsfix(flydsl): preserve ordinary MoE stage1 argumentsfix(flydsl): forward FHMoE AOT stage1 ABI flagThe feature, runtime wrappers, AOT adapter, GPU-kernel facade, and tests remain isolated in
fhmoe.py/test_fhmoe.pyfiles. Existing MoE modules contain only the narrow dispatch and shared-builder bridges needed by the new path. Tuning CSV changes remain in #4314.Why heterogeneous fusion
The checkpoint stores routed experts as MXFP4 but the shared expert as FP8. Quantizing the shared expert to MXFP4 permits ordinary homogeneous fusion but adds avoidable weight error; launching a separate FP8 shared kernel preserves precision but gives up much of the fusion gain. FHMoE keeps one fused schedule while selecting native FP8 weight and scale resources only for the final logical shared expert.
Existing callers preserve their previous behavior when the shared-expert arguments are omitted. Compatibility coverage checks that omitted and explicit-default calls are bitwise identical and that the ordinary custom-op/compiler schemas have not acquired FHMoE-only fields.
Rebase and conflict resolution
The branch was rebuilt on
mainataa6ee6102. The textual conflict was confined tomixed_moe_gemm_2stage.py: currentmainhad moved FlyDSLbuffer_opsandvectorimports into the vendored kernel namespace, while this PR had moved the implementation into the shared builder. The resolution keeps the thin facade and carries the current-main imports intomixed_moe_gemm_2stage_common.py.The rebase also forward-ports current launcher changes:
situ_beta,situ_linear_beta, andk_batch_intra_block;_FHMoEAOTBackend.build_stage1_argsexplicitly accepts and forwardspass_swiglu_limitto the shared stage-1 argument builder.The last item was caught by the Python 3.12 prebuilt-wheel CI job after the first rebase. It is adapter-protocol drift in a newly added file, not a kernel/runtime failure. The fix keeps an explicit signature rather than absorbing future protocol changes through
**kwargs, and a CPU-only regression passesFalseto prove that the value is forwarded rather than supplied by the downstream default.Validation
Focused tests on the current head:
Result: 2 passed.
The exact DSV4 FHMoE stage-1 job that failed in wheel CI was also compiled through
compile_one_configwithCOMPILE_ONLY=1, fake tensors, and targetgfx950:Additional checks:
Result: all passed. GitHub's Ruff and Black checks also pass on the current head.
Earlier full GPU correctness validation covered both the small profile and exact DeepSeek-V4 TP8 dimensions at M=4,8,16,32,64, including the FP32 oracle, isolated routed/shared contributions, forced-reduce determinism, atomic bounds, graph replay, schema compatibility, invalid contracts, and runtime/AOT bridges: 13 passed in each profile.
The editable benchmark install was refreshed from the restacked tip without prebuilding kernels:
Installed version:
0.1.20.dev34+g57e848f53.d20260730.Model evaluation and serving performance
The current rebased runtime stack was tested with the repository's unchanged scripts on 8×gfx950,
TP=8, expert parallelism disabled, and concurrency 4 for the performance point. The subsequentpass_swiglu_limitchange is AOT-only and does not alter this runtime path.The server log confirms the intended route: native-FP8 shared-expert fusion, internal E=385/top-k=7, no EP, and the tuned C1/C2 configurations on every rank.
GSM8K used all 1,319 samples, 20-shot prompts, concurrency 64,
max_tokens=2048, and temperature 0:All 1,319 requests returned HTTP 200 with no retries or server errors. Against the immediately preceding same-script baseline, both metrics moved by 4/1319 answers (-0.303 percentage points); 13 extracted answers changed, with 7 correct-to-wrong and 3 wrong-to-correct.
InferenceX 8K-input/1K-output at concurrency 4 completed 40/40 requests:
Relative to the immediately preceding TP8/C4 run, output throughput improved 0.41%, TTFT improved 2.75%, and TPOT improved 0.38%.
Commands:
Duplicate-work check
Current open-PR searches for
heterogeneous MoEandMXFP4 FP8 shared expertfound this feature PR, its tuning follow-up #4314, and #3739. #3739 is a config-only DeepSeek-V3 E=33/top-k9 tuning change where the fused shared expert uses the same MXFP4 representation as the routed experts; it does not implement this PR's heterogeneous MXFP4-routed/native-FP8-shared kernel or ABI. This updates the existing #4269 rather than opening a duplicate.AI assistance
OpenAI Codex was used to audit related work, implement and organize the patch, resolve and verify the rebase, run tests and model evaluations, restack the branches, and draft this description. The human submitter reviewed the changes and is responsible for understanding and defending them end-to-end.