Merge branch 'f-135-eng' into rel-0.1.35
This commit is contained in:
commit
772c9330e9
5 files changed
+171
-23
No files matched your search
@@ -1024,6 +1024,22 @@ 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;
|
||||
#if defined(_WIN32)
|
||||
// #467: the GPU cache's pre-fill touched its experts through the mapping (~19 GiB on a 24 GB card), and Windows
|
||||
// counts those file pages in this process's working set, not as available: a 32 GB PC read 0.44 GiB here
|
||||
// (20.7 GiB before the start). Trimmed, they move to the standby list (still cached, counted as available).
|
||||
// Resident mode only: nothing else calls this function. Locked/pinned pages stay; the rest fault back softly.
|
||||
{
|
||||
uint64_t before = 0, after = 0;
|
||||
const bool read_before = available_memory_bytes(before);
|
||||
(void) SetProcessWorkingSetSize(GetCurrentProcess(), (SIZE_T) -1, (SIZE_T) -1);
|
||||
if (read_before && available_memory_bytes(after))
|
||||
std::fprintf(stderr, "FileExpertSource: available RAM %.2f GiB, %.2f GiB after the mapped experts left the "
|
||||
"process working set (#467)\n",
|
||||
(double) before / 1073741824.0, (double) after / 1073741824.0);
|
||||
}
|
||||
#endif
|
||||
const bool what_fits = budget_bytes == kResidentWhatFits; // #467: the soft mode's second try
|
||||
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
|
||||
@@ -1041,10 +1057,16 @@ bool FileExpertSource::pin_cache_complement(
|
||||
// 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 and a 0.25 GiB margin): %.2f GiB\n",
|
||||
(double) budget_bytes / 1073741824.0, (double) physical / 1073741824.0,
|
||||
(double) headroom_bytes / 1073741824.0, (double) clamped / 1073741824.0);
|
||||
if (what_fits)
|
||||
std::fprintf(stderr, "FileExpertSource: RAM room for the complement: %.2f GiB (%.2f GiB available "
|
||||
"minus %.0f GiB headroom and a 0.25 GiB margin)\n",
|
||||
(double) clamped / 1073741824.0, (double) physical / 1073741824.0,
|
||||
(double) headroom_bytes / 1073741824.0);
|
||||
else
|
||||
std::fprintf(stderr, "FileExpertSource: --resident-budget-gib %.2f is more than the RAM has room for "
|
||||
"(%.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) clamped / 1073741824.0);
|
||||
budget_bytes = clamped;
|
||||
}
|
||||
std::vector<uint64_t> ranked(offsets.size(), kNoComplement);
|
||||
@@ -1061,6 +1083,10 @@ bool FileExpertSource::pin_cache_complement(
|
||||
at += b;
|
||||
++held;
|
||||
}
|
||||
if (what_fits && held == 0) { // #467: nothing to keep - the caller's plain mmap fallback, not an empty copy
|
||||
err = "FileExpertSource: the RAM has no room for any expert of the complement";
|
||||
return false;
|
||||
}
|
||||
std::fprintf(stderr, "FileExpertSource: RAM budget %.2f GiB: %lld of the %.2f GiB of experts the GPU cache does "
|
||||
"not hold, by profile rank; the rest are read from the files\n",
|
||||
(double) budget_bytes / 1073741824.0, (long long) held, (double) bytes / 1073741824.0);
|
||||
|
||||
+72
-16
@@ -3788,8 +3788,26 @@ int main(int argc, char** argv) {
|
||||
const int64_t k = plan_lend(chunk);
|
||||
if (k > 0) lend_from = xcache.slots() - k;
|
||||
}
|
||||
if (src.pin_cache_complement(xcache, err, o.resident_pin, {}, lend_from, o.resident_headroom,
|
||||
o.resident_budget, &profile)) {
|
||||
bool resident_ok = src.pin_cache_complement(xcache, err, o.resident_pin, {}, lend_from, o.resident_headroom,
|
||||
o.resident_budget, &profile);
|
||||
std::string whole_err;
|
||||
if (!resident_ok && o.resident_soft) {
|
||||
// #467: the whole complement does not fit - keep what does, the hottest by the profile, through the #403
|
||||
// budget path (sized by the RAM alone) instead of none: the misses outside it read the same file bytes
|
||||
// the mmap fallback reads, so the answers are unchanged. Nothing pinned: the old fallback below.
|
||||
whole_err = err;
|
||||
resident_ok = src.pin_cache_complement(xcache, err, o.resident_pin, {}, -1, o.resident_headroom,
|
||||
strata::core::FileExpertSource::kResidentWhatFits, &profile);
|
||||
if (resident_ok)
|
||||
std::fprintf(stderr, "strata generate: WARNING: the whole resident RAM mode does not fit (%s); %.2f "
|
||||
"GiB of the experts the GPU does not hold, the hottest by the expert profile, are "
|
||||
"kept in RAM and the rest are read from the model folder through the OS file "
|
||||
"cache\n",
|
||||
whole_err.c_str(), (double) src.resident_bytes() / 1073741824.0);
|
||||
else
|
||||
err = whole_err + "; " + err;
|
||||
}
|
||||
if (resident_ok) {
|
||||
if (o.adapt_every > 0 && o.adapt_swaps > 0 &&
|
||||
!src.reserve_exchanges(std::min<int64_t>(o.adapt_swaps, 96), err)) {
|
||||
std::fprintf(stderr, "strata generate: CPU expert residency: %s\n", err.c_str());
|
||||
@@ -3895,24 +3913,62 @@ int main(int argc, char** argv) {
|
||||
// 128-slot floor. The percentage cap is an AUTO-chunk rule and only the auto scan applies it - an
|
||||
// explicit --prefill is the operator's number, and a loan of it only has to fit. With one participant
|
||||
// (no split) this reduces to plan_lend exactly, so the single-GPU loan is unchanged from main.
|
||||
auto fits = [&](int64_t c, bool cap) -> bool {
|
||||
for (const PfPart& p : pf_parts) {
|
||||
const int64_t k = part_slots(p, c);
|
||||
if (k <= 0 || k + 128 > p.cache->slots()) return false;
|
||||
if (cap && k * 100 > kAutoLendPct * p.cache->slots()) return false;
|
||||
}
|
||||
auto fits_one = [&](const PfPart& p, int64_t c, bool cap) -> bool {
|
||||
const int64_t k = part_slots(p, c);
|
||||
if (k <= 0 || k + 128 > p.cache->slots()) return false;
|
||||
return !(cap && k * 100 > kAutoLendPct * p.cache->slots());
|
||||
};
|
||||
// `only`: CUDA0's cache alone (#448: what one GPU would choose, for the log below); null: every one
|
||||
auto fits = [&](int64_t c, bool cap, const PfPart* only = nullptr) -> bool {
|
||||
if (only != nullptr) return fits_one(*only, c, cap);
|
||||
for (const PfPart& p : pf_parts)
|
||||
if (!fits_one(p, c, cap)) return false;
|
||||
return true;
|
||||
};
|
||||
static constexpr int64_t kAutoChunks[] = {32768, 16384, 8192, 6144, 4096, 3072, 2048, 1024, 512, 256};
|
||||
int64_t chunk = 0;
|
||||
if (o.prefill_auto) {
|
||||
for (const int64_t c : kAutoChunks) {
|
||||
if (c > 8192 && (c > o.prefill_auto_max || c > o.max_context)) continue; // #282, as plan_lend
|
||||
if (fits(c, true)) { chunk = c; break; }
|
||||
auto pick = [&](const PfPart* only) -> int64_t {
|
||||
if (o.prefill_auto) {
|
||||
for (const int64_t c : kAutoChunks) {
|
||||
if (c > 8192 && (c > o.prefill_auto_max || c > o.max_context)) continue; // #282, as plan_lend
|
||||
if (fits(c, true, only)) return c;
|
||||
}
|
||||
} else {
|
||||
for (int64_t c = o.prefill_chunk; c >= 256; c /= 2)
|
||||
if (fits(c, false, only)) return c;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
const int64_t chunk = pick(nullptr);
|
||||
// #448: a small card in a layer split caps every stage's chunk (an RTX 3080's 512-slot cache held a
|
||||
// 32 GB card's split to 512 tokens: prompts 6.2x slower, decode the same). Named when it bites, so the
|
||||
// regression is one log line: each stage that cannot fund the chunk CUDA0 alone would read in.
|
||||
if (pf_parts.size() > 1) {
|
||||
const int64_t alone = pick(&pf_parts[0]);
|
||||
if (alone > chunk) {
|
||||
for (size_t i = 1; i < pf_parts.size(); ++i) {
|
||||
const PfPart& p = pf_parts[i];
|
||||
if (fits_one(p, alone, o.prefill_auto)) continue;
|
||||
const int dev = p.dev < 0 ? 0 : p.dev;
|
||||
cudaDeviceProp prop{};
|
||||
if (cudaGetDeviceProperties(&prop, dev) != cudaSuccess) {
|
||||
(void) cudaGetLastError();
|
||||
prop.name[0] = 0;
|
||||
}
|
||||
const std::string pct =
|
||||
o.prefill_auto ? ", and lend at most " + std::to_string(kAutoLendPct) + "%" : "";
|
||||
std::fprintf(stderr, "strata serve: WARNING: prompt chunk %lld tokens, not %lld: CUDA%d (%s) "
|
||||
"has %lld expert-cache slots, and a %lld-token chunk borrows %lld of them "
|
||||
"(it must keep 128%s) - prompts read slower than on CUDA0 alone (#448)\n",
|
||||
(long long) chunk, (long long) alone, dev, prop.name,
|
||||
(long long) p.cache->slots(), (long long) alone,
|
||||
(long long) part_slots(p, alone), pct.c_str());
|
||||
// the helper tiers start at CUDA1 without a split (and are enabled in order)
|
||||
std::fprintf(stderr, "strata serve: a card this small can serve as a helper expert cache "
|
||||
"instead of a split stage: without --layer-split, with %s "
|
||||
"(docs/SECOND_GPU.md)\n",
|
||||
dev == 1 ? "--expert-cache-device1 N" : "--expert-cache-device1..3 N, in order");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int64_t c = o.prefill_chunk; c >= 256; c /= 2)
|
||||
if (fits(c, false)) { chunk = c; break; }
|
||||
}
|
||||
if (chunk > 0) {
|
||||
if (o.prefill_auto)
|
||||
|
||||
Reference in new issue
Block a user