engine: a RAM budget clamped to the free RAM no longer fails its own safety check (#403)
FileExpertSource::pin_cache_complement read the available RAM twice: the budget was clamped to the first reading (less the 4 GiB headroom) and the resident-memory check then failed it on a second reading a few MB lower, so a 64 GB PC with setup's --resident-budget-gib 40 could exit at start. With a budget, the check now reuses the reading the budget was sized from, and a clamped budget stops 256 MiB under the room. An unclamped budget holds the same experts as before (the lend region is off with a budget, so `budget` there is unused). If the budget still cannot be kept (no RAM reading, an allocation that fails), generate.cpp warns and serves every expert the GPU does not hold from the files through the OS file cache (--mmap-experts) instead of exiting; the complement is left unbuilt on every failure path.
This commit is contained in:
1 parent
18a0ec2d47
commit
152f7198b9
2 files changed
+20
-5
No files matched your search
@@ -1024,6 +1024,7 @@ bool FileExpertSource::pin_cache_complement(
|
||||
uint64_t bytes = 0;
|
||||
if (!detail::make_cache_complement_plan(n_layers_, n_expert_, layer_blob_bytes_, primary_gpu_pairs,
|
||||
additional_gpu_pairs, offsets, bytes, err)) return false;
|
||||
uint64_t budget_physical = 0; // #403: the RAM reading a budget was sized from (0: no budget)
|
||||
if (budget_bytes > 0) {
|
||||
// CS-T: a RAM budget. The complement's experts in `rank` order (the expert profile, hottest first) while
|
||||
// they fit, the rest left on the mapped files; clamped to what the RAM has room for.
|
||||
@@ -1032,13 +1033,19 @@ bool FileExpertSource::pin_cache_complement(
|
||||
err = "FileExpertSource: cannot determine available RAM for --resident-budget-gib";
|
||||
return false;
|
||||
}
|
||||
budget_physical = physical;
|
||||
const uint64_t room = physical > headroom_bytes ? physical - headroom_bytes : 0;
|
||||
if (budget_bytes > room) {
|
||||
// #403: 256 MiB under the room, so the engine's own allocations after this reading still leave the
|
||||
// headroom (a budget clamped to exactly the room failed the safety check below on a reading a few MB
|
||||
// lower). An unclamped budget is unchanged.
|
||||
const uint64_t margin = 256ull << 20;
|
||||
const uint64_t clamped = room > margin ? room - margin : 0;
|
||||
std::fprintf(stderr, "FileExpertSource: --resident-budget-gib %.2f is more than the RAM has room for "
|
||||
"(%.2f GiB available minus %.0f GiB headroom): %.2f GiB\n",
|
||||
"(%.2f GiB available minus %.0f GiB headroom and a 0.25 GiB margin): %.2f GiB\n",
|
||||
(double) budget_bytes / 1073741824.0, (double) physical / 1073741824.0,
|
||||
(double) headroom_bytes / 1073741824.0, (double) room / 1073741824.0);
|
||||
budget_bytes = room;
|
||||
(double) headroom_bytes / 1073741824.0, (double) clamped / 1073741824.0);
|
||||
budget_bytes = clamped;
|
||||
}
|
||||
std::vector<uint64_t> ranked(offsets.size(), kNoComplement);
|
||||
uint64_t at = 0;
|
||||
@@ -1065,8 +1072,10 @@ bool FileExpertSource::pin_cache_complement(
|
||||
const bool lend = lend_from_slot >= 0 && lend_from_slot < n_slots && additional_gpu_pairs.empty();
|
||||
uint64_t budget = std::numeric_limits<uint64_t>::max();
|
||||
if (bytes > 0 || lend) {
|
||||
uint64_t physical = 0;
|
||||
if (!available_memory_bytes(physical)) {
|
||||
// #403: with a budget, the reading it was sized from - a second reading a few MB lower (the engine's own
|
||||
// allocations, the file cache) failed a budget the first one had clamped. (A budget turns `lend` off.)
|
||||
uint64_t physical = budget_physical;
|
||||
if (physical == 0 && !available_memory_bytes(physical)) {
|
||||
err = "FileExpertSource: cannot determine available RAM for the resident-memory safety check";
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user