[PR #4382] [Engine] DeepSeek-V4.1: the hyper-connection split off the decode path, +1.4% decode, bit-exact #5031

Open
opened 2026-11-07 16:32:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4382
Author: @Licenser
Created: 10/28/2026
Status: 🔄 Open

Base: main ← Head: dsv41-hc-mix


📝 Commits (1)

  • 9bc42f7 dsv41: the hyper-connection split beside the norm, off the decode path

📊 Changes

3 files changed (+33 additions, -58 deletions)

View changed files

📝 src/dsv41/ds4_kernels.cu (+18 -46)
📝 src/dsv41/ds4_kernels.cuh (+5 -5)
📝 src/dsv41/ds4_model.cu (+10 -7)

📄 Description

Problem and result

In a decode window every layer runs hc_mix_split twice, before the attention and before the FFN: 24 dot products
over the 4 x 5120 hyper-connection state, then the split (the gates and a 20-step 4 x 4 Sinkhorn) on one warp of the
block that finishes last. hc_pre_norm waits for all of it. Timed on its own on an A40, a call takes 15.55 us, and the
split alone 10.04 us of it: the Sinkhorn is a chain of 40 normalizations on one warp. 80 calls a token come to about
1,240 us of a 27,460 us token.

The norm does not need that split. It reads an earlier split's pre: before the attention the previous layer's
f_pre, before the FFN the attention's a_pre. post and comb are read only by hc_post at the end of the
sublayer. This PR runs the split beside the norm instead of before it. The arithmetic is the same, and so are the bits.

stock 2.00 bpw, A40 alone, 256 tokens main 5e8a4cca this PR
decode, run a 36.40 tok/s 36.76 tok/s
decode, run b 36.43 tok/s 37.07 tok/s
attention's mixing stage (DS4_PROF) 438 us/token 185 us/token

+1.4% decode on the means, about 370 us a token. The output is bit for bit main's: the scored files on two cards, and
the generated text with and without DSpark.

None. A focused change that keeps the output bit for bit.

Approach

  • On CUDA and HIP, the decode path calls hc_mix (the kernel the prompt path already uses) and then
    hc_pre_norm_split: hc_pre_norm_kernel launched with 2T blocks, where blocks T and up run the token's
    hc_split_body on their first warp, from the mixes hc_mix left. The split's outputs are complete when the kernel
    ends, before hc_post reads them.
  • hc_mix_split_kernel, its wrapper with the per-token counters and the counters (hccnt) go: nothing else used
    them. The hc_mix_split without counters stays: the Mac (Metal) decode path calls it and then hc_pre_norm, as on
    main.
  • The prompt path (hc_mix + hc_split + hc_pre_norm) and the plain hc_pre_norm are unchanged.

Validation

Machine: an A40 48 GB (sm_86) and an RTX 2080 Ti 11 GB (sm_75), each used alone (CUDA_VISIBLE_DEVICES); Threadripper
3960X, 184 GiB RAM, Linux, CUDA 13.4, packaging/build_dsv41_cuda.sh with ARCH="75;86-real". Model:
ISTA-DASLab/DeepSeek-V4.1-Flash-1017-GSQ-RCO-GGUF IQ2_XXS 2.00 bpw @ cb02422c, --experts 5, a fresh copy of
data/dsv41/profile-2.00.bin for each run. The first line under Passed is this PR (9bc42f77) against main 46c152a1;
the other lines were measured with this PR on main 5e8a4cca, against 5e8a4cca.

Passed:

  • On main 46c152a1, the A40 alone: --score over the multilingual set (999 positions, --no-expert-cache,
    STRATA_DS4_SLOT_KEEP=0 STRATA_DS4_AUTO_PIN=0, the CPU lane's experts read in place with --mmap-experts on),
    windows of 16 and windows of 1, this PR against main: byte-identical score files (4,995 rows each).
  • --score over the multilingual set (999 positions, --no-expert-cache, STRATA_DS4_SLOT_KEEP=0 STRATA_DS4_AUTO_PIN=0), windows of 16 and windows of 1, this PR against main on the same card: byte-identical score
    files (4,995 rows each) on the A40 and on the 2080 Ti.
  • Generated text: --ids <1K prompt> --n 256 (the prompt read through the chunked path), this PR against main:
    identical on the A40 (two runs each) and on the 2080 Ti (two runs each).
  • DSpark loaded (--dspark on, A40, the same 1K prompt and 256 tokens): the generated text is identical to main's,
    and so are the drafter's rounds (68 rounds, 187 of 196 drafts accepted, in both).
  • Decode on the A40, this PR and main interleaved, two runs each: the table above.
  • DS4_PROF=1 on the A40, one run each: the attention's mixing stage 438 -> 185 us a token; the GPU total 26,960 ->
    26,330 us a token (the profiler's per-stage waits make that difference larger than in a plain run).
  • A stand-alone benchmark of main's kernels at the decode shape (A40, one token, 5,000 launches each): hc_mix_split
    15.55 us, the mix alone 5.78 us, the split alone 10.04 us, an empty kernel 2.41 us.
  • Build: CUDA, sm_75 + sm_86, Linux, on main 46c152a1 and on 5e8a4cca.
  • Build, on main 5e8a4cca: HIP for gfx1200 + gfx1201 (tools/dsv41/build_hip_linux.sh, targets strata-dsv41 and
    ds4_iq_test) with ROCm 7.10.0a20251120 from AMD's TheRock wheels, setup's pin. Compiled and linked, with the same
    number and kinds of warnings as main's: one sign-compare warning moves from the removed kernel to the new block
    check (blockIdx.x >= T). Not run: there is no AMD card here.

Failed: none observed.

Not run:

  • HIP on an AMD card (built only); a Windows build. SYCL: not applicable, the SYCL engine has no DeepSeek path.
  • A Mac (Metal) build: there is no Mac here. The Mac path's calls are main's, unchanged.
  • On main 46c152a1: the 2080 Ti, the generated text, DSpark, the decode timing and a HIP build.
  • Two or more cards (layer splits, tensor-parallel groups), other packs.

Limits

  • The gain is measured on the A40 only. On the 2080 Ti alone, which holds 227 of the 15,360 experts, decode could not
    show it: two runs of this PR differed by 2.6% (21.86 and 21.30 tok/s), more than the 1.4% the A40 showed; main
    5e8a4cca ran at 21.61 and 21.20 tok/s.

Used Claude.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4382 **Author:** [@Licenser](https://github.com/Licenser) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `dsv41-hc-mix` --- ### 📝 Commits (1) - [`9bc42f7`](https://github.com/Niko1221/Strata/commit/9bc42f77092e33610b62f04b8bd9c0c74401310c) dsv41: the hyper-connection split beside the norm, off the decode path ### 📊 Changes **3 files changed** (+33 additions, -58 deletions) <details> <summary>View changed files</summary> 📝 `src/dsv41/ds4_kernels.cu` (+18 -46) 📝 `src/dsv41/ds4_kernels.cuh` (+5 -5) 📝 `src/dsv41/ds4_model.cu` (+10 -7) </details> ### 📄 Description ## Problem and result In a decode window every layer runs `hc_mix_split` twice, before the attention and before the FFN: 24 dot products over the 4 x 5120 hyper-connection state, then the split (the gates and a 20-step 4 x 4 Sinkhorn) on one warp of the block that finishes last. `hc_pre_norm` waits for all of it. Timed on its own on an A40, a call takes 15.55 us, and the split alone 10.04 us of it: the Sinkhorn is a chain of 40 normalizations on one warp. 80 calls a token come to about 1,240 us of a 27,460 us token. The norm does not need that split. It reads an earlier split's `pre`: before the attention the previous layer's `f_pre`, before the FFN the attention's `a_pre`. `post` and `comb` are read only by `hc_post` at the end of the sublayer. This PR runs the split beside the norm instead of before it. The arithmetic is the same, and so are the bits. | stock 2.00 bpw, A40 alone, 256 tokens | main 5e8a4cca | this PR | |---------------------------------------|--------------:|-------------:| | decode, run a | 36.40 tok/s | 36.76 tok/s | | decode, run b | 36.43 tok/s | 37.07 tok/s | | attention's mixing stage (DS4_PROF) | 438 us/token | 185 us/token | +1.4% decode on the means, about 370 us a token. The output is bit for bit main's: the scored files on two cards, and the generated text with and without DSpark. ## Related discussion None. A focused change that keeps the output bit for bit. ## Approach - On CUDA and HIP, the decode path calls `hc_mix` (the kernel the prompt path already uses) and then `hc_pre_norm_split`: `hc_pre_norm_kernel` launched with 2T blocks, where blocks T and up run the token's `hc_split_body` on their first warp, from the mixes `hc_mix` left. The split's outputs are complete when the kernel ends, before `hc_post` reads them. - `hc_mix_split_kernel`, its wrapper with the per-token counters and the counters (`hccnt`) go: nothing else used them. The `hc_mix_split` without counters stays: the Mac (Metal) decode path calls it and then `hc_pre_norm`, as on main. - The prompt path (`hc_mix` + `hc_split` + `hc_pre_norm`) and the plain `hc_pre_norm` are unchanged. ## Validation Machine: an A40 48 GB (sm_86) and an RTX 2080 Ti 11 GB (sm_75), each used alone (`CUDA_VISIBLE_DEVICES`); Threadripper 3960X, 184 GiB RAM, Linux, CUDA 13.4, `packaging/build_dsv41_cuda.sh` with `ARCH="75;86-real"`. Model: `ISTA-DASLab/DeepSeek-V4.1-Flash-1017-GSQ-RCO-GGUF` IQ2_XXS 2.00 bpw @ cb02422c, `--experts 5`, a fresh copy of `data/dsv41/profile-2.00.bin` for each run. The first line under Passed is this PR (9bc42f77) against main 46c152a1; the other lines were measured with this PR on main 5e8a4cca, against 5e8a4cca. **Passed:** - On main 46c152a1, the A40 alone: `--score` over the multilingual set (999 positions, `--no-expert-cache`, `STRATA_DS4_SLOT_KEEP=0 STRATA_DS4_AUTO_PIN=0`, the CPU lane's experts read in place with `--mmap-experts on`), windows of 16 and windows of 1, this PR against main: byte-identical score files (4,995 rows each). - `--score` over the multilingual set (999 positions, `--no-expert-cache`, `STRATA_DS4_SLOT_KEEP=0 STRATA_DS4_AUTO_PIN=0`), windows of 16 and windows of 1, this PR against main on the same card: byte-identical score files (4,995 rows each) on the A40 and on the 2080 Ti. - Generated text: `--ids <1K prompt> --n 256` (the prompt read through the chunked path), this PR against main: identical on the A40 (two runs each) and on the 2080 Ti (two runs each). - DSpark loaded (`--dspark on`, A40, the same 1K prompt and 256 tokens): the generated text is identical to main's, and so are the drafter's rounds (68 rounds, 187 of 196 drafts accepted, in both). - Decode on the A40, this PR and main interleaved, two runs each: the table above. - `DS4_PROF=1` on the A40, one run each: the attention's mixing stage 438 -> 185 us a token; the GPU total 26,960 -> 26,330 us a token (the profiler's per-stage waits make that difference larger than in a plain run). - A stand-alone benchmark of main's kernels at the decode shape (A40, one token, 5,000 launches each): `hc_mix_split` 15.55 us, the mix alone 5.78 us, the split alone 10.04 us, an empty kernel 2.41 us. - Build: CUDA, sm_75 + sm_86, Linux, on main 46c152a1 and on 5e8a4cca. - Build, on main 5e8a4cca: HIP for gfx1200 + gfx1201 (`tools/dsv41/build_hip_linux.sh`, targets `strata-dsv41` and `ds4_iq_test`) with ROCm 7.10.0a20251120 from AMD's TheRock wheels, setup's pin. Compiled and linked, with the same number and kinds of warnings as main's: one sign-compare warning moves from the removed kernel to the new block check (`blockIdx.x >= T`). Not run: there is no AMD card here. **Failed:** none observed. **Not run:** - HIP on an AMD card (built only); a Windows build. SYCL: not applicable, the SYCL engine has no DeepSeek path. - A Mac (Metal) build: there is no Mac here. The Mac path's calls are main's, unchanged. - On main 46c152a1: the 2080 Ti, the generated text, DSpark, the decode timing and a HIP build. - Two or more cards (layer splits, tensor-parallel groups), other packs. ## Limits - The gain is measured on the A40 only. On the 2080 Ti alone, which holds 227 of the 15,360 experts, decode could not show it: two runs of this PR differed by 2.6% (21.86 and 21.30 tok/s), more than the 1.4% the A40 showed; main 5e8a4cca ran at 21.61 and 21.20 tok/s. Used Claude. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5031
No description provided.