Skip to content

perf(ds4): batch heterogeneous MoE prefill by expert - #640

Open
cheese-cakee wants to merge 8 commits into
Luce-Org:mainfrom
cheese-cakee:codex/perf-ds4-moe-grouped-gemm
Open

perf(ds4): batch heterogeneous MoE prefill by expert#640
cheese-cakee wants to merge 8 commits into
Luce-Org:mainfrom
cheese-cakee:codex/perf-ds4-moe-grouped-gemm

Conversation

@cheese-cakee

@cheese-cakee cheese-cakee commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Accelerates DeepSeek-V4 heterogeneous prefill by batching owner-local routed experts into grouped ggml_mul_mat_id graphs instead of issuing a serial graph per active expert.

  • enables the existing expert-major heterogeneous path from 32 tokens (previously 512);
  • builds one grouped gate/up/down MMID graph per owner GPU;
  • adds a GPU-native route histogram/prefix/scatter helper for up to 256 experts;
  • preserves masked owner routes as exact zero contributions;
  • retains DFLASH_MOE_GROUPED_MMID_PREFILL=0 and DFLASH_MOE_EXPERT_MAJOR_MIN_TOKENS=512 as rollback controls.

Matched performance

Measured on Lucebox6 with AMD Radeon AI PRO R9700 (gfx1201) + Strix Halo Radeon 8060S (gfx1151), the same ROCmFP2 model, cache disabled, two warmups, and five measured requests per cell. Baseline is current upstream/main at ac22a3ed; the measured implementation is retained in the final 041b59df history, followed only by masked-route correctness and regression-test hardening.

Workload Current main Candidate Result
401-token prefill, chunk=512 54.16 tok/s (MAD 0.19) 184.11 tok/s (MAD 1.41) 3.40x faster (+239.9%)
MoE FFN time, 401 tokens 6,791.6 ms 1,661.2 ms 4.09x reduction (-75.5%)
2048-token prefill, chunk=2048 292.42 tok/s (MAD 10.64) 304.69 tok/s (MAD 8.70) +4.2%

The wide-context cells use the same fixed 22,000 MiB expert budget (hot 60 experts/layer) on both heads so that both can run the single 2048-token chunk without an allocation failure. The headline is the matched 401-token production-prefill improvement

Correctness and validation

  • All warmup and measured full-model responses in the retained 401- and 2048-token A/B cells produced the same SHA-256: cd5cb9fb5ac3c4f4007e8b41d117da21622439cd05c1728f3e82f90e4f869dad.
  • Every retained request was cache-cold (restore=false, slot=-1, prefix_len=0, disk_hit=false).
  • test_deepseek4_mmid_grouped_cuda: parity PASS across 72 cases on physical gfx1201 and gfx1151, including direct +0.0 assertions for wide masked ROCmFP2/ROCmFP3 owner routes.
  • test_deepseek4_unit: PASS on physical gfx1201 and gfx1151.
  • git diff --check: clean.

The masked-route regression uncovered during qualification is fixed by zero-initializing compact MMID destination lanes before dispatch; this prevents unwritten owner-masked columns from contributing stale/NaN values during weighted reduction.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread server/deps/llama.cpp/ggml/src/ggml-cuda/mmid.cu Outdated
Comment thread server/deps/llama.cpp/ggml/src/ggml-cuda/mmf.cu Outdated
Comment thread server/test/test_deepseek4_mmid_grouped_cuda.cpp
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.

1 participant