mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5471] [Engine] DeepSeek: faster Q4_K / Q5_K decode GEMVs and light experts with the same bits, the default only on integrated GPUs #5443
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5443
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/5471
Author: @R-Okauchi
Created: 11/7/2026
Status: 🔄 Open
Base:
main← Head:dsv41-decode-kernels📝 Commits (10+)
dc27c2atests: dq_dense_test --path bench, gg::mv's time on the decode's dense shapese2a2197DeepSeek engine: DS4_MV_NR, the low-bit GEMV with several rows a warp (opt-in)f267812DeepSeek engine: the low-bit GEMV's 8-column form, for the drafter's windowsed0311cDeepSeek engine: DS4_MV_NR's kernel loads Q4_K / Q5_K sub-blocks 128 bits at a timeb01c725DeepSeek engine: the low-bit GEMV's 128-bit loads by default on CUDAe658167dq_dense_test --path bench: the best and the median of 7 timed runsd356f28DeepSeek engine: the low-bit GEMV's 6-column instance for 5-6 activations05b5036DeepSeek engine: the router's BF16 weights kept as BF16 on CUDAa2b4a9aDeepSeek engine: DS4_MV_STAGE=1, the Q4_K / Q5_K GEMV with the row's weights staged a step ahead (opt-in)ace2c6eDeepSeek engine: DS4_LIGHT_STAGE=1, the prompt's light experts with their rows staged a step ahead (opt-in)📊 Changes
5 files changed (+465 additions, -7 deletions)
View changed files
📝
src/dsv41/ds4_iq.cu(+326 -0)📝
src/dsv41/ds4_kernels.cu(+26 -0)📝
src/dsv41/ds4_kernels.cuh(+4 -0)📝
src/dsv41/ds4_model.cu(+38 -6)📝
tests/dsv41/dq_dense_test.cpp(+71 -1)📄 Description
Problem and result
On a DGX Spark (GB10), DeepSeek V4.1's decode spends part of its GPU time in the dense GEMVs (the attention's
projections, the shared expert), and a prompt spends part of its time in the light experts. The Q4_K / Q5_K GEMVs read
their weights well below what the memory gives, because each of
mv_kernel's lanes waits on its own sub-block's loads.Q5_K's wo_b (8192 x 5120, 28.8 MB) ran at 165 GB/s, where the Q8_0 GEMV of the same shape reaches 226 GB/s. This PR
adds faster forms of those kernels that give the same bits (223 GB/s for that wo_b). It makes them the default only on
a GPU that shares the PC's memory, where they were timed faster one by one.
End to end on the Spark the gain is small. Without the drafter, #5170's command decoded at 13.28 and 13.83 tok/s
against main's 12.52 and 12.54; a third run, the first after main's cold start, gave 12.22. With the drafter the speed
did not change: 14.03 and 14.67 against 13.94 and 14.77. Without the drafter the 1,308-token prompt read at 162-169
tok/s against 149-151, and with it at the same speed as main. Most of a token's time there goes elsewhere: in #5470's
profile of main on the same box, 42.0 of a token's 110.9 ms of GPU time is the wait for the CPU lane's experts.
On the discrete cards I timed (RTX 4070 Ti, RTX PRO 5000 Blackwell), the kernels were not faster overall. There
nothing changes by default, and they are opt-in.
Related discussion
#5170 (decode on a DGX Spark). Changing a default needs your agreement on scope, and there is none yet, so this is a
draft. If you would rather keep the kernels opt-in on the Spark too, that is the one function
new_kernels_default().This PR is independent of #5453 and applies to main. If #5453 lands first, the staged light kernel should take
SetArgs::wptrthe waylight_kernel_rowsdoes there (one line).Approach
mv_kernel_nr: one row per warp withmv_kernel's lanes, sub-blocks and shuffles, so the same sums in the sameorder, with Q4_K / Q5_K sub-blocks read as 128-bit loads (
decode_v).DS4_MV_NR=2/4/autogive a warpseveral rows. That is opt-in, because it was not faster at one activation.
mv_kernel_kst: the Q4_K / Q5_K GEMV with the row's weights staged a step ahead, asq8_mv_kerneldoes. A warploads its next 32 sub-blocks in coalesced words while it computes the 32 it staged. It gives the same bits as
mv_kernel_nr.light_kernel_rows_st: the prompt's light experts (256-value types), staged the same way. It gives the same bits aslight_kernel_rows.mv_kernelhas 8 for 5-8where
new_kernels_default()holds, instead of 16. A column's sums do not depend on the instance.gate_w16,gemv_bf16w). Each value is widened exactly as it is read, in thesame
fmafchain, so the logits are the same bit for bit, at half the bytes. The F32 copies took 0.34 GB for 43layers; on the Spark the weights on the GPU went from 5.86 to 5.70 GB.
dq_dense_test --path benchtimesgg::mvon the decode's dense shapes: the best and the median of 7 runs, with256 MB of copies of the matrix taking turns so the cache holds none of it.
Defaults: they are on for a GPU that shares the PC's memory (
cudaDevAttrIntegrated). Elsewhere they are opt-in:DS4_MV_NR=1(withDS4_MV_STAGE=1for the staged GEMV),DS4_LIGHT_STAGE=1andDS4_GATE_BF16=1.mv_kernel_nralso runs the other low-bit types, with
mv_kernel's loads and sums. HIP and Metal keep their kernels and the F32router, since none of this was timed there.
Validation
The tests and timings below, except the builds, are of an earlier state of this branch. In it the kernels were the
default on every CUDA GPU, and it also unrolled the hyper-connections' mix loops by 4 (the same sums). I left that
unroll out of this PR because it was not timed apart. The kernels are the same at the head. On the Spark the head's
defaults are the ones that ran.
Passed:
Bits, with main's and this branch's tests built the same way (CUDA 13.0.2,
-DSTRATA_BUILD_TESTS=ON). I ranmain's
ds4_iq_test --dump, then this branch's--cmpagainst it:bit-compare vs golden: 84 buffers, 0 differ -> IDENTICAL, ALL OK. That held on an RTX 4070 Ti (sm_89, two machines), an RTX PRO 5000 Blackwell (sm_120) and a GB10(sm_121).
ds4_dq_test's dense checks gave 147 results, all ok, on each.ds4_tq_testandds4_gguf_testgaveALL OK on the RTX 4070 Ti and the RTX PRO 5000.
The kernels' times, from
ds4_dq_test --path bench, main against this branch. Each cell is the range, overDeepSeek-V4.1's 8 dense shapes, of main's time divided by this branch's (above 1: this branch is faster):
At one activation on the GB10:
Q8_0 and BF16 did not change (0.99-1.01). Q6_K, which goes through
mv_kernel_nrwithout the 128-bit loads, was1.00-1.01 at one activation, 0.97-1.05 at 4 and 0.81-1.04 at 8.
End to end on the same Spark (driver 580.178.04, nothing else on the GPU), with #5170's IQ2_XS pack and its command,
after the same 1,308-token chat prompt, greedy. main (
9f7d977d, the same code as this PR's base apart from READMEs)and this branch were built the same way, with
spark/build_engine.sh's flags:The runs, in the order they ran (the drafter's runs with
--dspark auto --dspark-conf 0.65):Run 1 was the first after the engine's Pod started, with the model's files not yet in the page cache. No two runs
gave the same 256 tokens: main's run 3 already parted from runs 1 and 5 at the first token. The CPU lane computes a
timing-dependent set of experts and rounds differently from the GPU (#5170), so I compared the bits with the tests
above, not with these texts.
The server end to end on two RTX PRO 5000 Blackwell. The engine was the release's server, with DeepSeek V4.1
UD-Q2_K_XL and #5357 on both sides, the drafter on,
--parallel 4, and each engine in its own Pod with no othertraffic, with every new default on:
None of these differ beyond the runs' spread, which is why the defaults stay on integrated GPUs.
Builds of the head (
7c08d69f):121-real;121-virtual) withspark/build_engine.sh's flags, on the Spark:strata-dsv41builds. There are no warnings in the changed files apart from three that main has too.tools/dsv41/build_hip_linux.sh strata-dsv41 ds4_iq_testbuilds both.metal/with metal-cpp, targetstrata_ds4, builds.Failed: none observed.
Not run:
changes only host code there: where the defaults apply.
Limits
was up to 11% slower and Q6_K up to 19%: the new kernels' 8-column instances against main's 16, for a verify window
of 7-8 tokens. The drafter's windows here averaged 4 tokens.
the drafter I saw none.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.