mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2963] [Engine] resident RAM mode: the RAM copy is page-locked in slices when the one page-locked allocation is refused (32K prompt 10.5 -> 6.6 s, decode -13% a round) #4364
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#4364
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/2963
Author: @sergqwer
Created: 10/17/2026
Status: 🔄 Open
Base:
main← Head:pr/resident-pin-slices📝 Commits (1)
df2c2a9resident RAM mode: the RAM copy is page-locked in slices when the one page-locked allocation is refused📊 Changes
5 files changed (+266 additions, -42 deletions)
View changed files
📝
docs/DETAILS.md(+7 -0)📝
include/strata/core/expert_source.hpp(+12 -3)📝
include/strata/core/pinned.hpp(+6 -0)📝
src/core/expert_source.cpp(+211 -26)📝
src/core/pinned.cu(+30 -13)📄 Description
Problem and result
With
--resident-experts(and--resident-budget-gib, which setup writes for the large Unsloth quants), the experts the GPU does not hold are copied into RAM, page-locked by onecudaHostAlloc. When the driver refuses that one allocation, the copy is malloc'd and only locked in the working set. A Q8_0 pack's ~100 GiB copy on a 128 GB Windows PC is such a case: WDDM caps page-locked memory at the GPU's shared-memory budget. What the refusal costs today, inpin_cache_complement:pinned()is false for every expert andpcie_layer()is false, so the PCIe share (--pcie-frac) fetches nothing and every decode miss goes to the CPU;After: the same bytes are registered slice by slice, and the experts in them are DMA'd and read over PCIe again. Forced on this PC: a fresh 32K prompt 10.5 -> 6.6 s, decode -13% a round (18.8 -> 16.4 ms), start 22.5 -> 16.9 s; that is path 1's speed. Nothing changes when the one allocation is granted.
Related discussion
None beyond this PR. It was #2963 before the 0.2.0-beta tracker reset, unchanged except for the rebase. No default changes where the allocation is granted (the identity runs below); where it is refused, the new path is the fallback.
Approach
Three paths, each named in the log (
page-locking path 1/2/3 ... X of Y GiB pinned):cudaHostAlloc, as before.VirtualAlloc'd (posix_memalignelsewhere) and registered withcudaHostRegister(Portable | Mapped)slice by slice, before anything writes it. Each slice is about one layer of the pack, cut at expert starts (page-aligned where possible), with its own device alias. Registration stops at the first refusal.pinned()anddevice_alias()look the slice up; an expert no slice holds whole is the CPU's.pcie_layer()is true. By default the slices stop below the GPU adapter's shared-memory budget, less what the process uses there and a margin (on a layer split, the smallest room of the devices): pinned until the driver refused a slice, the copy filled that WDDM segment and every GPU phase of the prompt path got slower (numbers in the code comment).STRATA_COMPLEMENT_PIN_GIB:all= slices until the driver refuses one,N= at most N GiB,0= path 3.STRATA_PARTIAL_PIN=1budget prefix keeps its own path.pinned.cu: #243's privatesliced_pin_limitbecomes the publicshared_pin_limit_for(dev); the arena'sSTRATA_ARENA_PIN_GIB=autocalls it for the current device, as before.STRATA_PIN_MARGIN_GIBsets the margin (default 4 GiB, #243's value).STRATA_TEST_COMPLEMENT_REFUSE=1takes the one allocation as refused, so paths 2 and 3 can be tested on a PC whose driver grants it.docs/DETAILS.md: one bullet in the resident-mode section.Validation
Revision: this branch, one commit
df2c2a92onmaine88ee39d(v0.2.0-beta + 12 commits), against a build ofmaine88ee39dwith the same configure. RTX 5090, Ryzen 9 9950X3D, 128 GB, Windows 11; MSVC 2022 17.14, CUDA 13.3, release configure (-DSTRATA_PORTABLE=ON,75-real;86-real;89-real;120-real, ggml at the pinned 3cf03257). Model: the NVFP4 GPTQ pack (Maximilian228/Qwen3.8-Flash-Next-NVFP4-GPTQ-Strata, upstream setup's--family nvfp4 --model NVFP4files).Passed:
Identity.
strata --servewith setup's model files plus--expert-cache 3000 --prefill auto --spec 6 --spec-min-p 0.7 --max-context 262144 --kv int8 --gpu 0 --pcie-frac 0 --adapt-every 1000000, envSTRATA_PREFILL_CPU_SHARE=0 STRATA_PCIE_BALANCE=0 STRATA_IQ_MT_MIN=1 STRATA_DUMP_FIRST_LOGITS=<file>; a 2,100-token and a 32,037-token prompt, 32 greedy tokens each. First-token logits and tokens:main, default mode1e9c612cf5b2872cmain,--resident-experts(58.97 GiB copy, onecudaHostAlloc)maindefault--resident-experts, path 1 (58.97 of 58.97 GiB pinned)STRATA_TEST_COMPLEMENT_REFUSE=1: 45 of 45 slices, 58.97 GiB, 22,903 of 22,903 experts, in 4.4 s)STRATA_COMPLEMENT_PIN_GIB=0: nothing pinned, 60,389 MiB locked)(resident runs with
STRATA_RESIDENT_HEADROOM_GIB=10)Speed.
--resident-experts --expert-cache auto --vram-reserve-mib 1500 --prefill auto --spec 6 --spec-min-p 0.7 --kv int8 --max-context 262144,STRATA_RESIDENT_HEADROOM_GIB=10. This PC grants the allocation, so paths 2 and 3 are forced withSTRATA_TEST_COMPLEMENT_REFUSE=1. 3 starts per path, interleaved (p2 p3 p1 p3 p1 p2 p1 p2 p3). Each start: 3 decodes of up to 600 tokens after a 45-token prompt, then two fresh 32K prompts. Mean ± sd over the starts:The cache got 7,136-7,210 slots and the RAM copy was 48.13-48.26 GiB. Path 2 registered 37 of 37 slices (every expert of the copy) in 3.3 s. Path 3's ready time includes locking 48 GiB in the working set. "ms a round" = decode time / (tokens - accepted drafts).
Failed: none observed.
Not run:
posix_memalign); not run.expert_source.cppandpinned.cu; no ROCm or Mac here. SYCL keeps its ownexpert_source(unchanged).Limits
cudaHostRegisterdirectly, as path 1'scudaHostAllocdoes; 0.2.0's pinned-memory test knob (STRATA_TEST_PIN_BUDGET_MIB) does not count either of them.477ac13c(0.1.45) a batch without--vram-reserve-mib(the cache filled the card, ~100 MiB free) had one path-2 run at 22 s for the 32K prompt, with the engine's own "only N MiB of VRAM free" warning.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.