engine: keep the picture reader's room in the reserve in the resident RAM mode

In the resident RAM mode (--resident-experts, --resident-budget-gib, which
setup writes for Unsloth's UD-Q4_K_XL below about 71 GB of RAM and for the
low-RAM mode, or the start's own fallback when RAM is short for the arena)
the expert cache refuses the server's VRAM command ("VRAM: not with the
resident low-RAM mode"). With the on-demand reader and only setup's 700 MiB
reserve, the reader then found about 425 MiB free and every picture went to
the processor reader: 7.67 / 6.15 / 1.49 / 1.43 s against 2.06 / 0.93 /
0.41 / 0.37 s with the room held back (l620, IQ3_S, card held to 32 GB,
--resident-budget-gib 40).

The engine knows that mode before it sizes the cache, so there it keeps the
reader's 2,048 MiB in the reserve (strata/core/reader_room.hpp, applied
once after the arena / file pass loop, before the cache is sized; the mode
is not entered later). Only an engine with --vision, --vram-elastic,
--serve and the resident RAM mode changes; a larger reserve is never
lowered. One engine log line says it; no setting, nothing for the user.

Gate on l620 (same setup, 3 starts each, alternating):
- new default with the rule: the reader on the card in 3 of 3 starts
  (1,509 MiB), 12,068 slots, pictures 2.06-2.45 / 0.91-1.08 / 0.39-0.59 /
  0.37-0.55 s, text 1,714-1,722 / 3,867-3,882 tok/s at 2K / 8K;
- old default: the reader on the card in 3 of 3, 12,068 slots, pictures
  2.07-2.37 / 0.91-1.09 / 0.39-0.59 / 0.37-0.55 s, text 1,719-1,740 /
  3,873-3,889 tok/s.
Without the resident mode nothing changes: the same 12,719 slots, the same
answers to the same prompts and pictures, the shrink path as before, the
rule's line absent (one start each, engine before and after).

Test: reader_room_test (ctest; the rule's eight input combinations and the
larger-reserve case).
This commit is contained in:
Niko1221 committed 2026-11-11 17:04:23 +01:00
1 parent 4efb5e8cbb
commit 4c8faae99d
4 files changed
+74

No files matched your search

+4
View File
@@ -277,6 +277,10 @@ if(STRATA_BUILD_TESTS)
add_executable(stream_watch_test tests/core/stream_watch_test.cpp)
target_include_directories(stream_watch_test PRIVATE include)
add_test(NAME stream_watch_test COMMAND stream_watch_test)
# the picture reader's room in the resident RAM mode (owner 11-11, reader on demand): the reserve rule, no GPU
add_executable(reader_room_test tests/core/reader_room_test.cpp)
target_include_directories(reader_room_test PRIVATE include)
add_test(NAME reader_room_test COMMAND reader_room_test)
add_executable(logit_bias_test src/core/logit_bias_test.cpp)
target_include_directories(logit_bias_test PRIVATE include)
add_test(NAME logit_bias_test COMMAND logit_bias_test)
+26
View File
@@ -0,0 +1,26 @@
#pragma once
// The picture reader's room when the expert cache cannot give it (owner 11-11, item "picture reader on demand, no reserve up front").
//
// On one NVIDIA card the server starts the GPU picture reader with the first picture and asks the engine's expert cache to make the
// reader's room then (`VRAM <reserve>`, --vram-elastic); before the first picture nothing is held back beyond the reserve setup wrote
// (700 MiB). In the resident RAM mode (the RAM copy of the experts the cache does not hold: --resident-experts, --resident-budget-gib,
// or the start's own fallback when RAM is short for the arena) the engine refuses that command ("VRAM: not with the resident low-RAM
// mode"), so the reader would find about 0.4 GiB free and go to the processor (measured on l620, IQ3_S on a card held to 32 GB:
// pictures 1.4-7.7 s on the processor against 0.4-2.1 s on the card). The engine knows that mode before it sizes the cache, so there it
// keeps the reader's room in the reserve, as before the change: the server then finds it free and starts the reader on the card.
// The mode is decided once, at start (the arena / file pass loop); nothing enters it later.
namespace strata::core {
/// The reader's room, the same number as the server's VISION_RESERVE_MIB (serve/server.py) and the reader's elastic_mib.
inline constexpr int kReaderRoomMib = 2048;
/// The VRAM reserve the expert cache is sized with. `vision`: the engine serves pictures (--vision); `vram_elastic`: the cache was
/// asked to give the reader its room on demand (--vram-elastic); `ram_copy_mode`: the resident RAM mode, in which the cache refuses
/// to resize. Only all three together raise the reserve, and never above what was asked when that is larger.
inline int reader_room_reserve_mib(int reserve_mib, bool vision, bool vram_elastic, bool ram_copy_mode) {
if (vision && vram_elastic && ram_copy_mode && reserve_mib < kReaderRoomMib) return kReaderRoomMib;
return reserve_mib;
}
} // namespace strata::core
+11
View File
@@ -19,6 +19,7 @@
#include "strata/platform/io_priority.hpp"
#include "strata/core/adapt_async_default.hpp"
#include "strata/core/arch_defaults.hpp"
#include "strata/core/reader_room.hpp"
#include "strata/core/gfx12_chunk.hpp"
#include "strata/core/nv_chunk.hpp"
#include "strata/core/nv_defaults.hpp"
@@ -7844,6 +7845,16 @@ int main(int argc, char** argv) {
srcp = &arena_src;
}
} // the arena / file pass loop (#4846)
// The picture reader's room in the resident RAM mode (strata/core/reader_room.hpp): there the cache refuses the server's VRAM
// command, so an on-demand reader keeps its room in the reserve, as before the reader went on demand. Decided here, once, before
// the cache is sized; the mode is not entered later.
if (const int keep = strata::core::reader_room_reserve_mib(o.vram_reserve_mib, o.vision, o.vram_elastic && o.serve,
o.resident_cpu_experts);
keep != o.vram_reserve_mib) {
std::fprintf(stderr, "strata generate: the resident RAM mode cannot resize the expert cache, so the picture reader's %d MiB "
"stay in the reserve (%d MiB asked)\n", keep, o.vram_reserve_mib);
o.vram_reserve_mib = keep;
}
#if defined(__linux__)
// 0.1.43.1: on by default (STRATA_ADAPT_CALLBACK_WARMUP=0 turns it off). Linux threads inherit the creator's CPU mask, and
// the host pins itself to one CPU later; a callback thread the driver creates lazily after that would run on the
+33
View File
@@ -0,0 +1,33 @@
// The picture reader's room in the resident RAM mode (strata/core/reader_room.hpp): only an engine that serves pictures, was asked for
// the shrinking cache and runs the resident RAM mode keeps the reader's 2,048 MiB in its reserve; every other start keeps its reserve.
#include "strata/core/reader_room.hpp"
#include <cstdio>
using namespace strata::core;
namespace {
int failed = 0;
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
} // namespace
int main() {
CHECK(kReaderRoomMib == 2048);
// the case: setup's 700 MiB, pictures on, the shrinking cache asked for, the resident RAM mode -> the reader's room is kept
CHECK(reader_room_reserve_mib(700, true, true, true) == 2048);
CHECK(reader_room_reserve_mib(0, true, true, true) == 2048);
// a larger reserve (the person's, the app's, Windows' own) is never lowered
CHECK(reader_room_reserve_mib(2048, true, true, true) == 2048);
CHECK(reader_room_reserve_mib(3000, true, true, true) == 3000);
// any one of the three missing: the reserve as asked (the arena mode shrinks; no pictures; no on-demand reader)
for (int v = 0; v < 2; ++v)
for (int e = 0; e < 2; ++e)
for (int r = 0; r < 2; ++r)
if (!(v && e && r)) CHECK(reader_room_reserve_mib(700, v, e, r) == 700);
if (failed) {
std::fprintf(stderr, "reader_room_test: %d failed\n", failed);
return 1;
}
std::printf("reader_room_test: ok\n");
return 0;
}