mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4367] [Engine] DeepSeek-V4.1: stream the model load, 3x faster start, up to 7x faster restart #5022
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#5022
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/4367
Author: @Licenser
Created: 10/27/2026
Status: 🔄 Open
Base:
main← Head:dsv41-copy-stream📝 Commits (10+)
be01fdadsv41: drop each copied expert's file pages after the copy994f720dsv41: DS4_COPY_STREAM=1 streams the expert copy in sequential reads1c366aadsv41: the VRAM experts in the same stream as the copy6670b69dsv41: a stream reader a range of a file, sized by the smallest filed01603ddsv41: the dense weights in the experts' streama089178dsv41: the dense weights' staging buffer on huge pagesb88db8edsv41: one stream reader for all files by default18ba360dsv41: the stream reads 128 MB at a timebe00571dsv41: the stream's chunk plan and reader ranges in functions of their ownc0871e3dsv41: --stream-probe times the stream's reads and prints the settings to use📊 Changes
3 files changed (+675 additions, -165 deletions)
View changed files
📝
src/dsv41/ds4_main.cpp(+10 -1)📝
src/dsv41/ds4_model.cu(+660 -164)📝
src/dsv41/ds4_model.hpp(+5 -0)📄 Description
Problem and result
Loading DeepSeek-V4.1-Flash copies the CPU lane's experts into RAM piece by piece through the page cache, and loads
the VRAM experts and the dense weights in passes of their own. The copy and the file pages it leaves behind compete for
RAM. When part of the model is still in the page cache from the last run, free memory runs out mid-copy and the rest
of the copy runs in direct reclaim and compaction: a restart is slower than a cold start.
This PR makes the default copy drop each piece's file pages once it is copied, and adds
DS4_COPY_STREAM=1, whichreads the whole model in one sequential pass.
ds4: loaded in)5e8a4ccaDS4_COPY_STREAM=1A restart is the same binary started straight after its own load. Main's restart time depends on how much of the
model the page cache still holds: its two restarts on this machine, both with about 86 GB cached and 94 GB free at the
start, took 95.1 s and 156.7 s to get the experts into memory (the slower run's whole load was not logged). Two
runs of each case:
5e8a4cca(copy)DS4_COPY_STREAM=1DS4_COPY_STREAM=1With the stream the load takes the same 26 s from cold and on restart, and its 21.5 s carry the
VRAM experts and the dense weights as well (138.2 GB against the copy's 94.5 GB). Main's restarts ran into direct
reclaim and compaction (15,605 and 54,200 stalls in the faster one). Decode is unchanged (36.2-36.6 tok/s in every
run), and the scored output is byte-identical on both paths.
Related discussion
None. The page drop changes the default copy; I would like to agree its scope here. The stream is opt-in.
Approach
Default: the page drop.
copy_expertsdrops each copied expert's file pages right after the copy, as the VRAMupload already does, so the copy and the page cache never hold the same bytes.
DS4_COPY_DROP=0keeps them.DS4_COPY_STREAM=1: one pass. One reader reads the model's files front to back in unbuffered reads of 128 MBinto one of two pinned arenas, while a mover copies the other arena's pieces to their places: the CPU lane's
experts to RAM, a one-card layer's VRAM experts to their slots (
cudaMemcpyAsync), and the dense weights to astaging buffer on huge pages. The dense weights' VRAM is allocated first, as before, so the experts' placement sees
it; their conversion and upload run after the stream, from the staging buffer. Gaps of up to 16 MB between pieces
are read through. On the machine below the stream reads 6.4 GB/s, 95% of what its two drives read in one
sequential stream.
Settings for other drives.
DS4_STREAM_RANGES=Nsplits each file among up to N readers, for drive arrays thatone reader cannot keep busy;
DS4_STREAM_MBsets the read size.strata-dsv41 --pack <pack> --stream-probetimes the reader layouts and read sizes on the pack's own files in about 30 s, without loading the model, and
prints the settings to use:
Validation
Machine: an A40 48 GB used alone (
CUDA_VISIBLE_DEVICES), Threadripper 3960X, 184 GiB RAM, two Samsung 970 EVO 1 TBin btrfs RAID0 (fio: 6.74 GB/s in one sequential stream), Linux 7.0, transparent huge pages
madvise. Model:ISTA-DASLab DeepSeek-V4.1-Flash-1017-GSQ-RCO IQ2_XXS 2.00 bpw, the shipped expert profile. Lines that do not name main
c62d5e3aor46c152a1were measured with this PR on main5e8a4cca.Passed:
46c152a1of 34d2395f, and on mainc62d5e3aofc0871e3a.tools/dsv41/build_hip_linux.sh, targetsstrata-dsv41andds4_iq_test, ROCm 7.10.0a20251120 from AMD's TheRock wheels, setup's pin. Compiled and linked. The warnings main'sHIP build lacks are 7 of a kind it has many of, a runtime call's
hipError_tleft unchecked (-Wunused-value), allat calls this branch adds.
CUDA_VISIBLE_DEVICES=<A40> DS4_NO_EOS=1 strata-dsv41 --pack <pack> --max-context 8192 --eos 1 --dspark auto --dspark-conf 0.65 --experts 5 -v --n 32 --ids <1K prompt>with each setting. Cold: theshards' cached pages dropped first (
posix_fadviseDONTNEED); restart: straight after a load of the same binary,nothing dropped.
5e8a4cca:--scoreon the multilingual set (999 positions, windows of16, fixed placement), 4995 rows, ppl 3.1167, top-1 0.7638, on the default path at bf3f4616 and with
DS4_COPY_STREAM=1at 2f7a9afb (bf3f4616 adds only the probe).c62d5e3a, the scored output ofc0871e3ais byte-identical to main's, on the default path and withDS4_COPY_STREAM=1: the same--scoreand settings as on46c152a1below, 4995 rows, ppl 3.0856, top-1 0.7618.46c152a1, the scored output of 34d2395f is byte-identical to main's, on the default path and withDS4_COPY_STREAM=1: the same--score, 4995 rows, ppl 3.0856, top-1 0.7618, with the CPU lane's experts read inplace (
--mmap-experts on). The stream then carries the VRAM experts (36.8 GB) and the dense weights (6.2 GB), notthe RAM copy.
sizes (16 / 32 / 64 / 128 / 256 MB: 30.7 / 27.5 / 26.1 / 25.8 / 25.7 s).
--stream-probe, the output above, 27 s.Failed: none observed.
Not run:
huge-page allocations have Windows paths that were not compiled).
unbuffered file handles, so the stream stays off for them).
c62d5e3aand46c152a1: the loads, the probe and a HIP build.Limits
main's restart can copy from the page cache faster (copies of 8-9 s on this machine when the cache held the right
part of the model).
decides how much it copies while the staging is held, so a machine close to its RAM limit may copy fewer experts
(from reading the code, not measured).
30.5 s: the stream itself its usual 21.6 s, the rest of the load 4.7 s longer, with 290 compaction stalls.
Used Claude.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.