resident RAM mode: a budget keeps the prompt path's lend region when it has room (#1683)

pin_cache_complement set lend_from_slot = -1 whenever --resident-budget-gib was given, so the experts of the cache
slots the prompt path borrows were in neither VRAM nor RAM during a prompt and were read from the model files on every
chunk, and again when the slots were refilled - even with room left in the budget. The budget branch now appends the
lend region's experts after the ranked ones, from the last slot down (the order the borrowing takes them), while they
fit; the budget stays a hard cap, and the ones past it keep the file fallback. The start-up line reports the count, and
the lend warning names a larger budget as the remedy when one is set.

Measured on an RX 6900 XT 16 GB (HIP gfx1030), Ryzen 9 5950X, 125 GB RAM, UD-Q4_K_XL, --resident-budget-gib 71 (the
copy held all 63.47 GiB outside the cache, 7.5 GiB unused; 1,231 lent slots = 3.60 GiB), engine 0.1.42, one run per
case, greedy: file reads of the lent experts per request 0.5-2.6 GB -> 0; SSD reads per fresh 8K / 16K prompt 2.8 /
1.9 GB -> 0.3 GB; prompt-path host staging 0.8-2.1 s -> 0.06-0.5 s per request; fresh prompts 887 / 7.8K / 15.8K
tokens 180 -> 194, 633 -> 676, 677 -> 698 tok/s. Decode unchanged.

Port of PR #1896 (commit 29063eb2b).
This commit is contained in:
Evan Lightcap authored and Niko1221 committed 2026-10-14 07:07:32 +02:00
1 parent fa1d1d1ebb
commit f2e142f444
3 files changed
+57 -13

No files matched your search

+7 -3
View File
@@ -7116,14 +7116,18 @@ int main(int argc, char** argv) {
// #669 / #765: a big chunk lends many cache slots to the prompt path, and each lent slot's expert is read back
// from the SSD whenever the RAM could not keep its copy (31 GB: auto:32768 read prompts ~3x slower than auto).
// Said, never capped: --prefill is the user's, and with the RAM for them it is the faster one (+21-35%).
if (resident_ok && lend_from >= 0 && o.prefill_chunk > 8192 && xcache.slots() > lend_from &&
// #1683: with a RAM budget the lend region is kept after the ranked experts, as far as the budget reaches, so
// the advice there is a larger budget, not a smaller chunk (the budget used to keep none of it whatever the chunk)
if (resident_ok && lend_from >= 0 && (o.prefill_chunk > 8192 || o.resident_budget > 0) && xcache.slots() > lend_from &&
src.resident_lent_slots() < xcache.slots() - lend_from)
std::fprintf(stderr, "strata generate: WARNING: a prompt chunk of %lld tokens lends %lld cache slots to the "
"prompt path, but only %lld of their experts fit in RAM: the others are read from the "
"SSD on every chunk, and prompts can read ~3x slower than with --prefill auto (#669). "
"A smaller --prefill, or auto, keeps them all in RAM\n",
"%s keeps them all in RAM\n",
(long long) o.prefill_chunk, (long long) (xcache.slots() - lend_from),
(long long) src.resident_lent_slots());
(long long) src.resident_lent_slots(),
o.resident_budget > 0 ? "A larger --resident-budget-gib (the lend region comes after the ranked experts), or a smaller --prefill,"
: "A smaller --prefill, or auto,");
if (resident_ok) {
// --adapt-async: twice the exchange buffers - the second half bounces the copies in whose source is not
// page-locked (an asynchronous copy instead of the driver's staged, synchronous one)