mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1190] [CLOSED] resident RAM mode with a layer split: the copy keeps each stage's lend region #3298
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#3298
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/1190
Author: @evaanp
Created: 10/6/2026
Status: ❌ Closed
Base:
main← Head:pr/lend-region-split📝 Commits (3)
3b6d636resident split: a test that the RAM copy keeps each stage's lend region (red: FileExpertSource has no stage_lend_regions, and no append_stage_lend_regions)efeadd5resident split: pin_cache_complement keeps each stage's lend region in the RAM copy too (stage_lend_regions, append_stage_lend_regions) - the experts the prompt path borrows under a split streamed from the mapped files through page faults (3.7 GiB read for one 73K prompt, 1.5 s of a 3.9 s chunk on host staging, 2026-10-06 rig); one budget caps complement and regions, experts past it keep the file fallback6d8f179generate: size every part's lend region for a layer split by the serve scan's own arithmetic (auto ceiling or the explicit chunk, the 128-slot floor, the auto percentage cap), #340's own-buffer rule deciding which parts lend nothing - and hand them to the resident copy before it pins📊 Changes
6 files changed (+440 additions, -1 deletions)
View changed files
📝
CMakeLists.txt(+15 -0)📝
include/strata/core/expert_source.hpp(+22 -0)📝
src/core/expert_source.cpp(+79 -1)📝
src/program/generate.cpp(+59 -0)📝
tests/core/file_expert_source_test.cpp(+46 -0)➕
tests/core/split_lend_complement_test.cpp(+219 -0)📄 Description
The problem
#848 gave
--resident-expertswith a layer split a RAM copy of only the experts no stage's cache holds.That left out the experts the prompt path borrows:
generate.cpphandspin_cache_complementthe laterstages' cache pairs as
additional_gpu_pairs, and with that list non-empty the function switches thesingle lend region off (
expert_source.cpp:1752,lend = ... && additional_gpu_pairs.empty()— the commentat
generate.cpp:5820: "with them the copy keeps no lend region: pin_cache_complement turns the loan off").So under a split, the experts in the tail slots of every card's cache — CUDA0's part included — are in
neither VRAM nor the RAM copy during a prompt, and the prompt reads them from the model files through page
faults.
Measured 2026-10-06 (v0.1.40 build, config: 17/48 layer split, RTX 2000 Ada
stage 0 = layers 0-16 + RTX 5060 Ti stage 1 = 17-47, IQ3_S native pack without experts.bin so
--mmap-expertsmaps the GGUF shards,--prefill auto= 8192-token chunks; each card's prompt path borrows4.31 GiB of its expert-cache slots):
--resident-experts(before)STRATA_PREFILL_TIMING=1, one 8192-token chunk (GPU wall 3132 ms arena vs 3865 ms resident): dequant 232 vs678 ms, host grouping 33 vs 187 ms, host staging 365 vs 1504 ms. The expensive experts were the file-read
ones: with the borrowed slots' bytes already in RAM, grouping/staging/dequant all stream the same
bytes the arena streams, and the walk collapses to
memcpy+cudaMemcpyinstead of aper-blob page-fault trail through the mmap'd GGUF. (
--no-prefill-borrowrestored the shortprompts but cost the 73K prefill — 1428 t/s — and decode: not the fix.)
The change
FileExpertSource::stage_lend_regions(...)(header): each stage's (layer, expert) pairs, listed fromthe cache's highest slot down — the order the borrowing takes them.
detail::append_stage_lend_regions(expert_source.cpp:186): adds the regions to the compactplan after the complement; a pair already in the copy is passed over, a stage's walk stops at the first
pair that does not fit, and the next stage's walk still runs. One budget caps the whole copy — the same
available-minus-headroom reading as the complement (#403), or an explicit
--resident-budget-gib.Experts past it keep the mapped-file fallback they have today.
pin_cache_complementfolds the regions in after its own lend walk (expert_source.cpp:1833) and sayshow many of the split's lent slots stayed in RAM (
the split stages lend N slots to the prompt path: M keep their experts in RAM too).generate.cpp:5827: sizes each part's region at the largest chunk the serve scan can ever pick — auto'sceiling
auto_ceiling, or an explicit--prefill, which the scan only walks down — with the scan's owntail-slot arithmetic (
cache_slots_for, the 128-slot floor, the autokAutoLendPctcap), and honours#340's
own_okrule: a part whose card can fund the bound chunk's buffers outright gets no region and noRAM is spent on it.
RAM arithmetic on the rig above: 25.13 GiB (complement) + ~8.6 GiB (two regions of 4.31 GiB) ≈ 33.7 GiB —
~13.5 GiB less pinned than the arena, with none of the 2.6 GiB extra NVMe reads the one prompt cost.
Answers are unchanged: the copy holds the same file bytes the fallback would read.
Untouched: the arena default, single-GPU behaviour (no regions set;
pin_cache_complement's own lend walkstays the only one), disk/keyless parking, and the expert-order/lookup semantics — resident pairs
resolve through the existing
cache_complement_blob_or_fallback.Tests
split_lend_complement_test(new, CPU-runnable): a two-stage split built the waygeneratebuildsthe call (CUDA0's cache as the primary, the later stage's pairs as
additional_gpu_pairs, emptycomplement). The device calls are wrapped at the link —
conversation_transfer_test's--wrappattern — and
pin = falsekeeps the copy pageable. It checks the copy holds exactly the two stages'lend-region pairs (
has_resident,resident_lent_slots), that the borrowed expertsare served from the RAM copy (
blob(l,e) == resident_blob(l,e), matching bytes, andfile_reads() == 0— not one read reaches the file source), that a--resident-budget-gibcap splits thetwo regions at the first pair that does not fit while the pair past it keeps its file fallback
(
file_reads() == 1), and the old #848 shape with no regions set (copy keeps nothing).Red on HEAD:
'class strata::core::FileExpertSource' has no member named 'stage_lend_regions'.file_expert_source_test.cpp: test_split_lend_regions(extended): the plan-level walk — bothregions compacted after an existing complement entry (passed over, not counted twice), whole-copy cap,
a refused walk leaves the plan untouched, out-of-range pair rejected before anything changes.
Red on HEAD:
'append_stage_lend_regions' was not declared in this scope.Measured after the change
Same rig and config as above,
--pcie-frac 0.20for all three columns (2026-10-06; interleaved A B C C runs,5 samples per run, medians):
--resident-expertsbefore--resident-expertswith this changeThe 2.1 GB that remains in every column is the PLE n-gram table (
--ple-io direct, unbuffered reads of a26.8 GiB shard, off the critical path), not experts.
conversation_cache_parity.pyreuse / disk / mixedpass byte-exact with this change on the split. Decode is unchanged by it (the regions only matter while a
prompt borrows; with resident vs arena decode differs by the cache-miss path, not by this change).
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.