[PR #1190] [CLOSED] resident RAM mode with a layer split: the copy keeps each stage's lend region #3298

Closed
opened 2026-11-07 14:40:27 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • 3b6d636 resident 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)
  • efeadd5 resident 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 fallback
  • 6d8f179 generate: 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-experts with 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.cpp hands pin_cache_complement the later
stages' cache pairs as additional_gpu_pairs, and with that list non-empty the function switches the
single lend region off (expert_source.cpp:1752, lend = ... && additional_gpu_pairs.empty() — the comment
at 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-experts maps the GGUF shards, --prefill auto = 8192-token chunks; each card's prompt path borrows
4.31 GiB of its expert-cache slots):

arena (default) --resident-experts (before)
RAM pinned for experts ~47 GiB (all) 25.13 GiB (complement only)
available RAM 3.5 GB 24.8 GB
decode 62.8 t/s 62.3 t/s
prefill 73K cold 2339 t/s 1892 t/s (-19%)
short prompts (70 tokens, cold) ~90-110 t/s ~50-65 t/s
NVMe read during one 73K prefill ~1.1 GB ~3.7 GB

STRATA_PREFILL_TIMING=1, one 8192-token chunk (GPU wall 3132 ms arena vs 3865 ms resident): dequant 232 vs
678 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 + cudaMemcpy instead of a
per-blob page-fault trail through the mmap'd GGUF. (--no-prefill-borrow restored the short
prompts 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 from
    the 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 compact
    plan 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_complement folds the regions in after its own lend walk (expert_source.cpp:1833) and says
    how 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's
    ceiling auto_ceiling, or an explicit --prefill, which the scan only walks down — with the scan's own
    tail-slot arithmetic (cache_slots_for, the 128-slot floor, the auto kAutoLendPct cap), and honours
    #340's own_ok rule: a part whose card can fund the bound chunk's buffers outright gets no region and no
    RAM 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 walk
stays 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 way generate builds
    the call (CUDA0's cache as the primary, the later stage's pairs as additional_gpu_pairs, empty
    complement). The device calls are wrapped at the link — conversation_transfer_test's --wrap
    pattern — and pin = false keeps the copy pageable. It checks the copy holds exactly the two stages'
    lend-region pairs (has_resident, resident_lent_slots), that the borrowed experts
    are served from the RAM copy (blob(l,e) == resident_blob(l,e), matching bytes, and
    file_reads() == 0 — not one read reaches the file source), that a --resident-budget-gib cap splits the
    two 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 — both
    regions 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.20 for all three columns (2026-10-06; interleaved A B C C runs,
5 samples per run, medians):

arena (default) --resident-experts before --resident-experts with this change
RAM copy ~47 GiB (all experts) 25.13 GiB 32.32 GiB (25.1 complement + 7.20 GiB lend regions, 3849 slots)
available RAM (58 GiB host) 4.2 GB 24.8 GB 17.5 GB
prefill, 73K cold 2341 t/s 1892 t/s 2287 / 2285 t/s (two runs)
short prompts (66-85 tokens, cold) 96-105 t/s 50-65 t/s 87-104 t/s
NVMe read over one 73K prompt 2.1 GB 3.7 GB 2.1 GB

The 2.1 GB that remains in every column is the PLE n-gram table (--ple-io direct, unbuffered reads of a
26.8 GiB shard, off the critical path), not experts. conversation_cache_parity.py reuse / disk / mixed
pass 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.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1190 **Author:** [@evaanp](https://github.com/evaanp) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/lend-region-split` --- ### 📝 Commits (3) - [`3b6d636`](https://github.com/Niko1221/Strata/commit/3b6d63617dce0f97284dea5b143df6da382947a7) resident 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) - [`efeadd5`](https://github.com/Niko1221/Strata/commit/efeadd5d98f0cc2719c9ce30704ad4403a56883e) resident 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 fallback - [`6d8f179`](https://github.com/Niko1221/Strata/commit/6d8f1798585b71952c0dc503bcaf5f6ed7386a64) generate: 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) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 Description ## The problem #848 gave `--resident-experts` with 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.cpp` hands `pin_cache_complement` the later stages' cache pairs as `additional_gpu_pairs`, and with that list non-empty the function switches the single lend region off (`expert_source.cpp:1752`, `lend = ... && additional_gpu_pairs.empty()` — the comment at `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-experts` maps the GGUF shards, `--prefill auto` = 8192-token chunks; each card's prompt path borrows 4.31 GiB of its expert-cache slots): | | arena (default) | `--resident-experts` (before) | |---|---|---| | RAM pinned for experts | ~47 GiB (all) | 25.13 GiB (complement only) | | available RAM | 3.5 GB | 24.8 GB | | decode | 62.8 t/s | 62.3 t/s | | prefill 73K cold | 2339 t/s | 1892 t/s (-19%) | | short prompts (70 tokens, cold) | ~90-110 t/s | ~50-65 t/s | | NVMe read during one 73K prefill | ~1.1 GB | **~3.7 GB** | `STRATA_PREFILL_TIMING=1`, one 8192-token chunk (GPU wall 3132 ms arena vs 3865 ms resident): dequant 232 vs 678 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` + `cudaMemcpy` instead of a per-blob page-fault trail through the mmap'd GGUF. (`--no-prefill-borrow` restored the short prompts 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 from the 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 compact plan 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_complement` folds the regions in after its own lend walk (`expert_source.cpp:1833`) and says how 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's ceiling `auto_ceiling`, or an explicit `--prefill`, which the scan only walks down — with the scan's own tail-slot arithmetic (`cache_slots_for`, the 128-slot floor, the auto `kAutoLendPct` cap), and honours #340's `own_ok` rule: a part whose card can fund the bound chunk's buffers outright gets no region and no RAM 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 walk stays 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 way `generate` builds the call (CUDA0's cache as the primary, the later stage's pairs as `additional_gpu_pairs`, empty complement). The device calls are wrapped at the link — `conversation_transfer_test`'s `--wrap` pattern — and `pin = false` keeps the copy pageable. It checks the copy holds exactly the two stages' lend-region pairs (`has_resident`, `resident_lent_slots`), that the borrowed experts are served from the RAM copy (`blob(l,e) == resident_blob(l,e)`, matching bytes, and `file_reads() == 0` — not one read reaches the file source), that a `--resident-budget-gib` cap splits the two 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 — both regions 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.20` for all three columns (2026-10-06; interleaved A B C C runs, 5 samples per run, medians): | | arena (default) | `--resident-experts` before | `--resident-experts` with this change | |---|---|---|---| | RAM copy | ~47 GiB (all experts) | 25.13 GiB | 32.32 GiB (25.1 complement + 7.20 GiB lend regions, 3849 slots) | | available RAM (58 GiB host) | 4.2 GB | 24.8 GB | 17.5 GB | | prefill, 73K cold | 2341 t/s | 1892 t/s | 2287 / 2285 t/s (two runs) | | short prompts (66-85 tokens, cold) | 96-105 t/s | 50-65 t/s | 87-104 t/s | | NVMe read over one 73K prompt | 2.1 GB | 3.7 GB | 2.1 GB | The 2.1 GB that remains in every column is the PLE n-gram table (`--ple-io direct`, unbuffered reads of a 26.8 GiB shard, off the critical path), not experts. `conversation_cache_parity.py` reuse / disk / mixed pass 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:40:27 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3298
No description provided.