Skip to content

DeepSeek CUDA: fuse routed combine and shared expert add - #3827

Open
BlivionIaG wants to merge 8 commits into
ashhart:mainfrom
BlivionIaG:pr/dsv41-combine-shared
Open

BlivionIaG wants to merge 8 commits into
ashhart:mainfrom
BlivionIaG:pr/dsv41-combine-shared

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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.

Checks on this head

  • Head commit: ae51e2a197 (merge of upstream/main 9fa8863bcf into the reviewed head e7ed07550c). The merge changes CHANGELOG.md only, so every kernel, dispatch and test file is byte-identical to the qualified heads named below.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 165 problems on upstream/main 9fa8863bcf and on 68ff0ad8e6, 165 on this head, 0 new (tools/zig/lean_new.py). tools/pr_check.py --base 68ff0ad8e6 --pr 3827: 0 errors, 0 warnings.
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check build.zig zig and git diff --check: clean.
    • zig build -Dcpu=apple_m1 -j4 on this head: exit 0.
    • zig build compile-dsv41-runner -Dcpu=apple_m1 -j4 on this head: exit 0 (compile-only, no device run).
    • Device receipts below were measured on 4de225b08a and f335b5f556 and were not rerun on this head; the merge brought no change to the files they cover.
  • CI: all ten repository jobs passed and the two nightly jobs were skipped on the previous head e7ed07550c (run 45103196346). The refreshed head reruns them.
  • Not run, and why: 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

  • Main against branch: ae51e2a197 served against upstream/main 68ff0ad8e6 from 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.
  • Boxes it reaches: DeepSeek-V4.1 CUDA prefill with routed experts and a shared expert; the no-shared-expert path is unchanged.
  • New switch? None.
  • Environment: GB10 (SM 12.1), NVCC 13.0.88, native runner SHA256 967c9e33fd1052875e93ee56a45873bc3d182d94e828b08271f06045d110e6a3 for 4de225b08a, and cf2618a817039aef6c333778e6af9069ab84c55b67e8489701defd2a7fd70901 for f335b5f556. Host checks on this head ran on macOS arm64, Zig 0.17.0.
  • Paths and platforms the change reaches: DeepSeek-V4.1 CUDA prefill (block prefill MoE, the EXL3 block kernel, replay dispatch and the overlap call contract). Ran: GB10 via the direct tf-dsv41-test combine-add command, eager and CUDA-graph replay, plus Compute Sanitizer memcheck. Not run: any other SM, any other checkpoint.
  • Exactness: 36/36 cells bit-exact against the unfused device path, and 36 captures with 72 graph replays bit-exact against freshly executed unfused references, with the shared input changed and the fused output poisoned before each replay. The ordered one-row case also checks hard-coded BF16 ties independently of the unfused oracle. Compute Sanitizer memcheck: 0 errors.
  • Decode speed before and after: kernel-only medians on synthetic direct-test inputs, 4096 rows 4.238→3.005 ms, 8192 8.434→5.826 ms, 16384 16.809→11.631 ms, 32768 34.202→23.261 ms. Not deployment claims.
  • Prompt speed before and after: mixed integration TTFT medians, 4,224 2.335→2.324 s, 7,838 4.011→4.012 s, 16,095 7.164→7.111 s, 31,947 13.306→13.230 s (about 0.7% at 16k, 0.6% at 32k; 4k and 8k within noise).
  • Licence of any new weights or drafter: n/a.

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.
  • Covers rows 17/129/4096/8192/16384/32768 at D=5120, top-6; rows 1/17 at D=4/1028 with 1/6/32 slots; random and ordered-cancellation inputs; offset buffer guards. The ordered one-row case also checks hard-coded BF16 ties independently of the unfused oracle.
  • The new direct command does not allocate expert matrices or sweep unrelated GMv3 variants. The initial piggybacked sweep exceeded its 600-second limit after 11 fusion cells passed; the replacement completed the larger matrix both normally and under memcheck. Sanitizer timings are not performance measurements.

CUDA-graph replay qualification

Tested head: f335b5f5564daf1a1d4994fd1d5a8339605dcb78. Native runner SHA256: cf2618a817039aef6c333778e6af9069ab84c55b67e8489701defd2a7fd70901.

  • All 36 eager cells still pass. The same matrix now also performs 36 captures and 72 graph replays, all bit-exact against freshly executed unfused references.
  • Each replay changes the shared input and poisons the fused output first, so stale outputs cannot satisfy the comparison. The executable graph is used after its template graph and wrapper argument stack have been released.
  • The complete eager/replay matrix also passed Compute Sanitizer memcheck: 0 errors.
  • zig fmt --check, compile-dsv41-runner and 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.

Prompt tokens Baseline TTFT (s) Fused TTFT (s) Fused aggregate decode (tok/s)
4,224 2.33500 2.32390 78.747
7,838 4.01140 4.01190 78.516
16,095 7.16355 7.11060 78.092
31,947 13.30585 13.22980 77.779

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

  • Tested head ae51e2a197 against upstream/main 68ff0ad8e6 (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 revision 45ee5d0f…, TP=2 over the direct RoCE pair, one slot, --parallel 1, context 131072, pool 65536, graphs and drafts on. Order main/head/head/main.
  • Server SHA256: main 1223db36… / head 64c70704…; follower main 04c9c393… / head 5b0fbd18…. Only the head binaries carry combine_add_kernel (23 string matches per binary; 0 in main's).
  • Token equality: 8 fixed prompts at temperature 0 and 8 at temperature 1.0 with seed 1234, 64 tokens each — every reply token-id hash equal between the arms (8/8 in both modes, and the main arm's two runs agree with each other). A 14,001-token prompt is equal in both modes. Four queued concurrent requests each equal their own solo run (8/8 per arm and mode).
  • Decode, 7,015-token prompt, 128 tokens, three reps per run: medians 42.18 and 41.49 tok/s (main) against 43.38 and 41.47 (head); per-rep spread 38.4-49.9 and 39.5-57.9, so no difference is resolved on the path this prefill-only change leaves untouched.
  • Prompt: cold first token on the 14,001-token prompt 9.811 s and 9.851 s (main) against 9.711 s and 9.747 s (head); the 7,015-token prompt 5.129 s and 5.169 s against 5.082 s and 5.105 s. Observed medians from two serves per arm, not a confidence claim.
  • Client: /v1/completions with return_token_ids and draft: true, 38 requests per serve, all HTTP 200; every reply's tensorfold.token_sha256 was checked against its own token ids.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency: not shown for the fusion itself; the device tests compare against the unfused path, and the maintainer accepted that evidence.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "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.)
  • No precision traded for speed: the ordered FP32 FMA chain is preserved and the result rounds once to BF16, bit-exact against the unfused path.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (Kernel-only and mixed integration numbers above; no regression observed.)

- 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.
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@BlivionIaG
BlivionIaG marked this pull request as ready for review November 24, 2026 11:10
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Ran the serving comparison against current main on the GB10 pair: this head ae51e2a197 and upstream/main 68ff0ad8e6, both built from source on the two nodes, same checkpoint revision and identical flags (TP=2 RoCE, one slot, --parallel 1, graphs and drafts on), order main/head/head/main.

  • Token ids: 8 fixed prompts greedy and seeded plus a 14,001-token prompt — equal between the arms in both modes (8/8, 8/8, long equal), and equal to the main arm's own repeat. Four queued concurrent requests each equal their solo run, 8/8 per arm and mode (48/48 cross-arm cells).
  • Decode, 7,015-token prompt, 128 tokens, three reps per run: main 42.18 and 41.49, head 43.38 and 41.47 tok/s (medians; per-rep spread 38–58 tok/s, so this does not resolve a difference).
  • Cold first token, 14,001 tokens: main 9.811 and 9.851 s, head 9.711 and 9.747 s.

The body carries this as "Serving comparison against main"; the mixed-integration timings stay in their own labelled section. No source file changed.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I checked a clean trial merge of ae51e2a197 onto d1ff890729, after the new TFQ3 changes landed.

zig build test-dsv41-cuda-host test-dsv41-draft compile-dsv41-runner check-native-cuda-host -Dfixed-cpu -j2 --summary all

On M5 Max all 38 steps succeeded and 627 host tests passed. The native adapter cross-compiled for ARM64 Linux, and the runner containing combine-add cross-compiled for x86_64 Linux with compile-only images. This checks the integrated build. The 36-cell eager and graph byte comparison on the GPU still needs the final tree.

Igor Lessio - AIFLOW LABS

This branch has not been deployed

No deployments
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.

3 participants