Repository navigation
DeepSeek CUDA: fuse routed combine and shared expert add - #3827
BlivionIaG wants to merge 8 commits into
Conversation
- Preserve the ordered FP32 sum and single BF16 rounding. - Remove the shared-expert routed intermediate and qualify the fused device output.
- Link the independently based upstream proposal.
- Keep the fusion note after an existing entry without changing producer code.
- Cover six prefill row counts, small and tail-vector shapes, and one through 32 routed slots. - Check ordered cancellation, BF16 ties and offset guards against the unfused device path.
- Capture the fused launch for all 36 numeric and boundary cases. - Poison outputs and change shared inputs before 72 replays against fresh eager references.
|
Thank you @BlivionIaG. The fused combine and shared add is narrow, keeps the ordered FP32 chain, and your GB10 receipt shows all 36 cells bit-exact against the unfused path. Keeping the overlap and buffer contracts while dropping only the two implementation-fingerprint tests is the right call. Nothing further is needed from you on this PR.
|
|
Thank you @BlivionIaG. The ordered FP32 chain, shared add and single BF16 rounding are preserved, and the overlap and buffer checks remain. The current kernel and test files match the graph-qualified version. The earlier review left no further changes for you. A serving comparison against current main remains a qualification step; the mixed-integration timings stay labelled separately.
|
|
Ran the serving comparison against current main on the GB10 pair: this head
The body carries this as "Serving comparison against main"; the mixed-integration timings stay in their own labelled section. No source file changed. |
|
Thank you, @BlivionIaG. The new serving comparison addresses the remaining comparison request: you report equal greedy, seeded and queued replies, with the mixed-integration timings kept separate. The kernel and graph-test files still match the qualified version. The ordered FP32 FMA chain, separate shared add and single BF16 rounding are preserved. No further source changes are requested; final qualification remains tied to the integrated tree.
|
|
I checked a clean trial merge of zig build test-dsv41-cuda-host test-dsv41-draft compile-dsv41-runner check-native-cuda-host -Dfixed-cpu -j2 --summary allOn M5 Max all 38 steps succeeded and 627 host tests passed. The native adapter cross-compiled for ARM64 Linux, and the runner containing Igor Lessio - AIFLOW LABS |
What this changes
Before, CUDA prefill on DeepSeek-V4.1 wrote the routed experts' FP32 output and then added the shared expert in a second launch. After, one fused pass walks the routed experts in the same ordered FP32 FMA chain, adds the shared FP32 output and rounds once to BF16, dropping the routed FP32 intermediate and that launch on the shared-expert path; the no-shared-expert path is unchanged. Every tested cell is bit-exact against the unfused device path.
atc overlap --json(run after the last merge,--base upstream/mainat9fa8863bcf): 13 files changed, 264 open PRs read (3 clean, 7 conflicting, 254 unknown). Conflicting: glm cuda: a GB10 holds the BF16 linears exactly in 12 bits a weight #3509 (1 file), qwen27: serve the 27B pair, refuse what a pair cannot keep, and die with the peer #1434 (12 files), qwen27 Metal: DSpine drafter for Qwen3.8-27B, opt-in #2634 (12), Nemotron 3.5 Transcribe: audio input, the 65,536-token window, an hour of audio, MTP drafts #1632 (12), ricursive: load Ripple's EXL3 packs through main's shared EXL3 code #2514 (8), ricursive: speed up Ripple-65B on two GB10s #2523 (11), ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522 (10). I did not resolve them: they are other PRs' edits to files this PR also touches (CHANGELOG.mdamong them), and atc does not name the file in this output. Coverage is incomplete (complete: false; limits myPullRequestsLimit, otherPullRequestsLimit, pullFilesUnavailable, pullRequestsLimit, timeLimit).Checks on this head
ae51e2a197(merge ofupstream/main9fa8863bcfinto the reviewed heade7ed07550c). The merge changesCHANGELOG.mdonly, so every kernel, dispatch and test file is byte-identical to the qualified heads named below.python3 tools/zig/lean_check.py, on the base and on this head: 165 problems onupstream/main9fa8863bcfand on68ff0ad8e6, 165 on this head, 0 new (tools/zig/lean_new.py).tools/pr_check.py --base 68ff0ad8e6 --pr 3827: 0 errors, 0 warnings.zig fmt --check build.zig zigandgit diff --check: clean.zig build -Dcpu=apple_m1 -j4on this head: exit 0.zig build compile-dsv41-runner -Dcpu=apple_m1 -j4on this head: exit 0 (compile-only, no device run).4de225b08aandf335b5f556and were not rerun on this head; the merge brought no change to the files they cover.e7ed07550c(run 45103196346). The refreshed head reruns them.zig build test test-golden(full suite) on this head; any SM other than 12.1, any other checkpoint, and TP=1 for this pack. The build machine has no CUDA device; the GB10 receipts below are the qualification.Receipt
ae51e2a197served againstupstream/main68ff0ad8e6from source on the same GB10 pair, same checkpoint, settings and flags (TP=2 RoCE, one slot). Reply token ids equal on 8 fixed prompts greedy and seeded and on a 14,001-token prompt, one stream and four queued (48/48 compared cells); decode 42.0 vs 42.4 tok/s medians within a 38-58 tok/s spread. The end-to-end A/B/A numbers in "Mixed integration evidence" remain from the dev integration and are labelled as such.967c9e33fd1052875e93ee56a45873bc3d182d94e828b08271f06045d110e6a3for4de225b08a, andcf2618a817039aef6c333778e6af9069ab84c55b67e8489701defd2a7fd70901forf335b5f556. Host checks on this head ran on macOS arm64, Zig 0.17.0.tf-dsv41-test combine-addcommand, eager and CUDA-graph replay, plus Compute Sanitizer memcheck. Not run: any other SM, any other checkpoint.Standalone device qualification
Tested commit:
4de225b08a48115d0917b250ddd48d2fd7395f62, GB10 (SM 12.1), NVCC 13.0.88. Native runner SHA256:967c9e33fd1052875e93ee56a45873bc3d182d94e828b08271f06045d110e6a3.zig build dsv41-test -Dfixed-cpu -Ddsv41-nvcc=/usr/local/cuda/bin/nvcc: passed.tf-dsv41-test combine-add: 36/36 cells bit-exact against the unfused device path.compute-sanitizer --tool memcheck --error-exitcode 86 tf-dsv41-test combine-add: the full 36-cell matrix passed; ERROR SUMMARY: 0 errors.CUDA-graph replay qualification
Tested head:
f335b5f5564daf1a1d4994fd1d5a8339605dcb78. Native runner SHA256:cf2618a817039aef6c333778e6af9069ab84c55b67e8489701defd2a7fd70901.zig fmt --check,compile-dsv41-runnerand PR checks passed locally. This addition changes only the device test and CLI help, not runtime kernels or dispatch.Mixed integration evidence — separate scope
These end-to-end measurements are from the fusion on the dev integration, not an end-to-end deployment of this standalone main-based branch. GB10 pair producer with unchanged M5 Ultra consumer, matched A/B/A (baseline/fused/baseline), three repetitions per prompt size per arm, three sustained decoders. Identical prompts, trial order, consumer, measurement source and salt; zero cached tokens and no remote fallbacks. Baseline column pools the two baseline arms. Observed medians, not a statistical confidence claim.
Canonical outputs, long-reply token IDs and all comparable sustained-decoder token prefixes matched. Zero invalid trials.
Producer exports: all manifests and every frame matched for 4096/8192/16384/32768 rows, two requests per size. Only the first request per size was independently cold.
After device qualification, the selected producer was restored and the M5 remote smoke passed: 7837 prefix tokens pulled for a 7838-token prompt, no cached tokens, eight output tokens with the expected hash. This does not establish CUDA-prefill/Metal-decode equality with native Metal prefill; the withdrawn mixed-consumer exactness gate is not reopened here.
Serving comparison against main
ae51e2a197againstupstream/main68ff0ad8e6(71 commits after the branch's merge base; none touch the files this change edits). Both arms built from source on the same GB10 pair (SM 12.1, NVCC 13.0.88, Zig 0.17.0;zig build dsv41-serve -Dtarget=aarch64-linux-gnu -Dsm=121 -Doptimize=ReleaseSafe) and served with identical flags: checkpoint revision45ee5d0f…, TP=2 over the direct RoCE pair, one slot,--parallel 1, context 131072, pool 65536, graphs and drafts on. Order main/head/head/main.1223db36…/ head64c70704…; follower main04c9c393…/ head5b0fbd18…. Only the head binaries carrycombine_add_kernel(23 string matches per binary; 0 in main's)./v1/completionswithreturn_token_idsanddraft: true, 38 requests per serve, all HTTP 200; every reply'stensorfold.token_sha256was checked against its own token ids.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Unchanged paths; this is a prefill-only fusion and its output is bit-exact against the unfused device path.)--drafter, no slower than without it, greedy and sampled. (Kernel-only and mixed integration numbers above; no regression observed.)