mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4302] [Engine] implement cache card logic for DeepSeek-V4.1, up to 30% faster decode #4992
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#4992
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/4302
Author: @Licenser
Created: 10/27/2026
Status: 🔄 Open
Base:
main← Head:cache-cards📝 Commits (10+)
e67468adsv41: decide a decode pick's lane in one function56a8127dsv41: --expert-cache-device1 fills CUDA1 with the CPU lane's experts624a40fdsv41: CUDA1 computes its experts' part of a decode token005f7d7dsv41: refill a CUDA1 slot whose expert the main card took31d6098dsv41: CUDA1 swaps its coldest expert for a hotter CPU-lane one8837407dsv41: an expert the main card evicts goes to CUDA1 when hottere228fd7dsv41: an evicted expert takes the CUDA1 slot its swap freeddbec795dsv41: CUDA1's margin swaps every 16 tokens past a bar of its own18728c0dsv41: count the CUDA1 serve line per requestd441ea0dsv41: CUDA1 swaps at every window by default📊 Changes
4 files changed (+482 additions, -20 deletions)
View changed files
📝
docs/DEEPSEEK41.md(+38 -0)📝
src/dsv41/ds4_main.cpp(+12 -1)📝
src/dsv41/ds4_model.cu(+427 -18)📝
src/dsv41/ds4_model.hpp(+5 -1)📄 Description
Problem and result
With two cards of different speed, strata-dsv41 can only split the layers between them. The faster card then waits for
the slower one's layers, and prompt reading gets slower. On an A40 with an RTX 2080 Ti (no peer access), the best split
(4 of 40 layers on the 2080 Ti) decoded 1.7% faster than the A40 alone and read 4K-16K prompts at 0.64-0.87x.
This PR adds
--expert-cache-device1 N|autoto strata-dsv41, the Qwen engine's flag name for its helper cache. CUDA1takes no layers. It holds the experts CUDA0 leaves to the CPU lane, the most-routed first, and computes the picks it
holds while the model writes, beside the CPU lane. On the same pair with the stock IQ2_XXS 2.00 bpw set: 7.6% faster
decode than the A40 alone, prompts read at the same speed. The flag is off by default; without it the scored output is
byte-identical to main's.
Adamyno tested it in this thread on 2x RTX 2080 Ti 22 GB (i9-7980XE, the same IQ2_XXS set,
--max-context 32768 --dspark auto --cpu-threads 15), five 512-token runs each:DS4_CACHE_CARD=0(card computes none)Prompt reading was unchanged there too. The gain grows with the second card's memory (21.7 GB of experts there
against 10.3 GB here) and with the share of experts the first card leaves to the CPU lane (about 32% on one 2080 Ti,
against an A40 that holds most of the model).
Decode speed: the 52 of 58 requests with at least 20 generated tokens in both runs, paired by order; the A40 alone's
time for the arm's tokens, sum(g_arm * t_ref / g_ref), over the arm's time, sum(t_arm), from the engine's
G generated in T mslines. The cache card reads prompts at 0.99-1.00x of the A40 alone. Over the whole workload, whereprompt reading is 68% of the time, it took 0.989x the A40 alone's time and the split 1.133x.
Related discussion
None yet.
Approach
lane_of, the first commit, no change in behaviour): CUDA0's VRAM, theRAM store's zero-copy, CUDA1, skipped, or the CPU lane, in that order. CUDA1 only takes picks that would go to the
CPU lane.
ranked across all layers by their share of their layer's routing in the expert profile and copied to CUDA1 while
they fit (
--reserve-miband 256 MiB for its buffers kept free). On the pair above with the shipped profile: 1,197experts, 10.27 GB, 8.2% of the routed picks by the profile, loaded in 0.9 s.
(the input copied over, a plan kernel, the existing GGUF expert kernels
gg::moe_gate_up/gg::moe_down, theresult copied back), computes the CPU's picks meanwhile, and adds CUDA1's weighted sum into the layer's response
before publishing it. Prompt reading and windows of more than one token run as before.
heat is above the coldest's heat x 1.25 + 1.
Copies are read from the model files into pinned memory on their own thread and copied on their own stream; at most
8 swaps are in flight.
the answer's experts, the waits for it and the moves in the request.
--gpus; the engine says so at the start. Switchesfor tests:
DS4_CACHE_CARD=0(CUDA1 loaded, unused),DS4_CACHE_CARD_FILL=0(no moves),DS4_CARD_EVERY,DS4_CARD_MARGIN,DS4_CARD_BONUS(the swaps' pace and bar).docs/DEEPSEEK41.mdhas a section on it.Validation
Environment: A40 (sm_86, 48 GB, PCIe 4.0 x16) + RTX 2080 Ti (sm_75, 11 GB, PCIe 3.0 x16), no peer access;
Threadripper 3960X, 184 GiB RAM; Linux, GCC 15.2, CUDA 13.4,
packaging/build_dsv41_cuda.shwithARCH="75;86-real"(portable). Model:
ISTA-DASLab/DeepSeek-V4.1-Flash-1017-GSQ-RCO-GGUFIQ2_XXS 2.00 bpw @ cb02422c (setup's pin),--experts 5, a fresh copy of the shippeddata/dsv41/profile-2.00.binfor each run. Cards set withCUDA_DEVICE_ORDER=PCI_BUS_ID CUDA_VISIBLE_DEVICES=1,0. The first line under Passed is this branch (64437ebf)against main
46c152a1; the other lines were measured with this branch on main5e8a4cca, against5e8a4cca.Passed:
46c152a1, the A40 alone, without the flag:--scoreover the same 4,995 positions with--no-expert-cacheand the CPU lane's experts read in place (--mmap-experts on), main against this branch, inwindows of 16 and of 1: byte-identical score files.
--scoreover 5 x 1,000-token segments (4,995 positions) with--no-expert-cache, main againstthis branch, in windows of 16 and of 1: byte-identical score files.
--expert-cache-device1 autowithDS4_CACHE_CARD=0: byte-identical to the A40 alone (windows of 1).tools/quant_quality.py compare --segments, fixed placement): KL 0.0169, top-1 95.30%. Forscale, the A40 alone with its cache adapting against fixed: KL 0.0135.
serve/server.pyon 127.0.0.1, a fixed workload of 58 requests (chat, 4K and 16K prompts, agent turns,an 8K needle, four clients at once), 3 runs per test, medians, the arms in the table's order: the table above. Each
arm's start line was checked (the A40 runs layers 0-39, CUDA1 the experts; the split 0-3 and 4-39); no failed
request, no out-of-memory, the needle found 3/3 in every arm.
for it over the run, 11,033 moves: 0.51 ms waited a generated token.
46c152a1and on5e8a4cca.5e8a4cca: HIP for gfx1200 + gfx1201 (tools/dsv41/build_hip_linux.sh, targetsstrata-dsv41andds4_iq_test) with ROCm 7.10.0a20251120 from AMD's TheRock wheels, setup's pin. Compiled and linked. The warningsmain's HIP build lacks are 21 of a kind it has many of, a runtime call's
hipError_tleft unchecked(
-Wunused-value), all at calls this branch adds.Failed:
Not run:
streams, events, pinned memory and a copy thread.
becomes a cache card).
--dspark on, with and without the card.46c152a1: the lines with CUDA1, the bench and a HIP build.Limits
"gpu"list in a config is a layer split, and with"layer_split": "auto"the server puts the faster card last, which would make it CUDA1. Setup'srecommend_remote_expert_optadds--remote-expert-optbeside--expert-cache-device1on two-GPU configs, an optionstrata-dsv41 refuses. The docs set the cards through the config's
envand leave out"gpu".--dspark on, orautowhere the GPU holds enough of the experts), CUDA1 sits out its verifyrounds. Not measured.
Used Claude.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.