perf(ds4): fuse expert-major MoE route combine - #658
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
4f900f1 to
1997438
Compare
There was a problem hiding this comment.
Review completed against the latest diff
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
You’re at about 90% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Summary
Speeds up DeepSeek-V4 heterogeneous prefill by fusing the post-MMID route reduction used by the production expert-major path.
The active path previously evaluated:
down_e -> mul(route weights) -> permute -> cont -> sum_rows -> add(shared expert)This PR replaces the reduction and optional shared-expert add with one
GGML_OP_DS4_MOE_COMBINEkernel. It now applies insideeval_moe_owner_expert_major_batched, so both the R9700 hot/shared owner and the Strix cold owner use it.This is deliberately described as a post-MMID combine, not a down-projection epilogue: the grouped down projection still materializes
down_e. The optimization removes the weighted-route intermediate and the following transpose/reduction chain.Set
DFLASH_MOE_FUSED_COMBINE=1to enable the qualified expert-major path. Set it to0to retain the legacy graph sequence.Heterogeneous prefill results
Measured on Lucebox6 with Radeon AI PRO R9700
gfx1201+ Strix Halogfx1151, the ROCmFP2 model, unchanged production placement (hot/layer=60, hot stack 2580, cold stack 8428), caches disabled, and the same candidate binary with the feature forced OFF or ON.Each cell used two warmups followed by five measured cache-cold requests. The order was OFF-A, ON-A, ON-B, OFF-B. All measured samples were retained.
chunk=512chunk=2048Both bracketed comparisons agree in sign:
The 2048 workload was noisier, but the gain survived both independent ON/OFF brackets. No outlier was deleted when calculating the pooled result.
Raw measured prefill samples
The tested server-code base was
b9d37b32. Currentmainat publication isf5475131; the intervening commits only change documentation and assets, so the server code under test is unchanged. The replacement PR commit is based directly onf5475131.Kernel-level measurement
The focused benchmark uses the model's exact hidden width (
n_embd=4096) and top-k 6. It compares the actual legacy graph with the fused operation after two warmups and seven measured samples.gfx1201gfx1201gfx1151gfx1151These are combine-kernel speedups, not whole-model speedups. The end-to-end gains are the pooled figures above.
Correctness and execution proof
cd5cb9fb5ac3c4f4007e8b41d117da21622439cd05c1728f3e82f90e4f869dad.gfx1201andgfx1151.test_deepseek4_mmid_grouped_cuda: 72/72 cases passed on each GPU, including masked fused-zero coverage.test_deepseek4_unit: passed on each GPU.git diff --check: clean.The qualified evidence is preserved on Lucebox6 at:
/home/cheese/pr658-active-path-final-r2-20260826T1624Z/qualified-evidenceManifest SHA-256:
44f1a353b6d84cd67f8339796296537b7ee7e6b901b57b8b9553d4cb89a5639fScope
This PR claims a heterogeneous prefill improvement. It does not claim a decode speedup. A deeper fusion that avoids materializing
down_ewould require a separate grouped-MMID down-projection redesign and is outside this change.