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
This commit is contained in:
1 parent
7a7c568b9a
commit
aea9dc3ed8
2 files changed
+101
No files matched your search
@@ -210,6 +210,46 @@ int64_t choose_resident_keep_from(const std::vector<uint64_t>& slot_bytes, uint6
|
||||
return keep;
|
||||
}
|
||||
|
||||
int64_t append_stage_lend_regions(int64_t n_layers, int64_t n_expert, const std::vector<uint64_t>& layer_blob_bytes,
|
||||
std::vector<uint64_t>& offsets, uint64_t& bytes, uint64_t cap_bytes,
|
||||
const std::vector<std::vector<std::pair<int32_t, int32_t>>>& regions,
|
||||
std::string& err) {
|
||||
const size_t blobs = (size_t) (n_layers * n_expert);
|
||||
if (n_layers <= 0 || n_expert <= 0 || layer_blob_bytes.size() != (size_t) n_layers || offsets.size() != blobs) {
|
||||
err = "append_stage_lend_regions: the plan does not match the geometry";
|
||||
return -1;
|
||||
}
|
||||
std::vector<std::pair<int32_t, int32_t>> sorted;
|
||||
for (const auto& region : regions) { // validate the whole request before touching the plan
|
||||
for (const auto& pair : region)
|
||||
if (pair.first < 0 || pair.first >= n_layers || pair.second < 0 || pair.second >= n_expert) {
|
||||
err = "append_stage_lend_regions: a lend-region expert is outside the model";
|
||||
return -1;
|
||||
}
|
||||
sorted = region;
|
||||
std::sort(sorted.begin(), sorted.end());
|
||||
for (size_t i = 1; i < sorted.size(); ++i)
|
||||
if (sorted[i] == sorted[i - 1]) {
|
||||
err = "append_stage_lend_regions: a stage's lend region repeats an expert";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
int64_t kept = 0;
|
||||
for (const auto& region : regions) {
|
||||
for (const auto& pair : region) {
|
||||
const size_t index = (size_t) pair.first * (size_t) n_expert + (size_t) pair.second;
|
||||
if (offsets[index] != kNoCacheComplement) continue; // already in the copy: the complement, or a
|
||||
// CUDA0 lend slot the region is asked to skip
|
||||
const uint64_t b = layer_blob_bytes[(size_t) pair.first];
|
||||
if (b > cap_bytes - bytes) break; // this stage's rest keeps the file fallback
|
||||
offsets[index] = bytes;
|
||||
bytes += b;
|
||||
++kept;
|
||||
}
|
||||
}
|
||||
return kept;
|
||||
}
|
||||
|
||||
bool exchange_cache_complement(std::vector<uint64_t>& offsets, size_t in, size_t out) {
|
||||
if (in == out || in >= offsets.size() || out >= offsets.size() || offsets[in] == kNoCacheComplement ||
|
||||
offsets[out] != kNoCacheComplement) return false;
|
||||
@@ -2332,6 +2372,36 @@ bool FileExpertSource::pin_cache_complement(
|
||||
}
|
||||
}
|
||||
|
||||
// A layer split: generate hands the copy every stage's lend region (`stage_lend_regions`, set before the
|
||||
// call). The prompt path borrows the tail slots of EVERY part's cache, and with `additional_gpu_pairs`
|
||||
// non-empty the single lend region above is off - so without this the borrowed experts sat in neither
|
||||
// VRAM nor RAM during a prompt and came back through page faults from the mapped shards: measured
|
||||
// 2026-10-06 on an RTX 2000 Ada + 5060 Ti rig (17/48 split, IQ3_S mapped from the GGUF, --prefill auto,
|
||||
// one 73K-token prompt) 3.7 GiB read from the NVMe for the one prompt (arena mode reads 1.1 GiB), and one
|
||||
// 8192-token chunk spent 1.5 s of its 3.9 s on host staging (arena: 0.37 s). The regions walk each
|
||||
// stage's highest slots first, as the borrowing does; the whole copy - complement and regions
|
||||
// together - stays within one budget, and experts past it keep the file fallback they had.
|
||||
int64_t stage_lent = 0;
|
||||
uint64_t stage_lent_bytes = 0;
|
||||
if (!stage_lend_regions_.empty()) {
|
||||
if (budget == std::numeric_limits<uint64_t>::max()) { // #403: the one reading, taken now
|
||||
uint64_t physical = budget_physical, commit = budget_commit;
|
||||
if (physical == 0 && !available_memory_bytes(physical, &commit)) {
|
||||
err = "FileExpertSource: cannot determine available memory for the stage lend regions";
|
||||
return false;
|
||||
}
|
||||
const uint64_t available = std::min(physical, commit);
|
||||
budget = available > headroom_bytes ? available - headroom_bytes : 0;
|
||||
}
|
||||
uint64_t cap = budget; // an explicit --resident-budget-gib caps the whole copy, regions included
|
||||
if (budget_bytes > 0 && budget_bytes != kResidentWhatFits && budget_bytes < cap) cap = budget_bytes;
|
||||
const uint64_t before = bytes;
|
||||
stage_lent = detail::append_stage_lend_regions(n_layers_, n_expert_, layer_blob_bytes_, offsets, bytes, cap,
|
||||
stage_lend_regions_, err);
|
||||
if (stage_lent < 0) return false;
|
||||
stage_lent_bytes = bytes - before;
|
||||
}
|
||||
|
||||
void* arena = nullptr;
|
||||
const uint8_t* host = nullptr;
|
||||
const uint8_t* device = nullptr;
|
||||
@@ -2701,6 +2771,7 @@ bool FileExpertSource::pin_cache_complement(
|
||||
complement_locked_ = locked;
|
||||
complement_lock_off_ = lock_off;
|
||||
complement_lent_slots_ = lend ? n_slots - keep_from : 0;
|
||||
complement_lent_slots_ += stage_lent; // and the split stages' regions: pairs the copy kept of them
|
||||
complement_ready_ = true;
|
||||
std::fprintf(stderr, "FileExpertSource: %s cache complement ready: resident %.2f GiB, pinned %.2f GiB in %.0f s%s%s\n",
|
||||
complement_pinned_ ? "mapped pinned" : pin ? "locked resident" : "pageable resident",
|
||||
@@ -2723,6 +2794,14 @@ bool FileExpertSource::pin_cache_complement(
|
||||
"cost 26%%). Free RAM or lower STRATA_RESIDENT_HEADROOM_GIB (now the RAM left free at start) and restart; "
|
||||
"the line above should read N of N.\n", missing, lendable, 100.0 * (double) missing / (double) std::max<long long>(1, lendable));
|
||||
}
|
||||
if (!stage_lend_regions_.empty()) {
|
||||
int64_t offered = 0;
|
||||
for (const auto& region : stage_lend_regions_) offered += (int64_t) region.size();
|
||||
std::fprintf(stderr, "FileExpertSource: the split stages lend %lld slots to the prompt path: %lld keep "
|
||||
"their experts in RAM too (%.2f GiB)%s\n",
|
||||
(long long) offered, (long long) stage_lent, (double) stage_lent_bytes / 1073741824.0,
|
||||
stage_lent < offered ? " (the rest are read from the file when lent: not enough RAM for them)" : "");
|
||||
}
|
||||
if (!additional_gpu_pairs.empty()) {
|
||||
std::fprintf(stderr, "FileExpertSource: %zu verified additional-GPU experts remain on the mmap fallback\n",
|
||||
additional_gpu_pairs.size());
|
||||
|
||||
Reference in new issue
Block a user