mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
[Engine] Strix Halo: the RAM cap with several requests at once has a way back and speaks only when it cuts
The cap on the pinned RAM copy of experts (--batch 2 or more, Windows HIP, integrated GPU) printed its line at 2 and 3 slots too, where the whole copy (12.47 and 16.40 GiB) is under the cap and nothing is cut: "18.1 GiB of experts are kept in RAM" was wrong there. Now the line comes after the pin and only when the RAM copy reached the cap (4 slots at 131,072 tokens: 15.0 GiB). STRATA_UMA_PIN_CAP=0 keeps the RAM budget as set (any other value, or unset, leaves the cap on); the line names it: "(STRATA_UMA_PIN_CAP=0 keeps the RAM budget as set)". The register entry is now status rollback with the measured points in its note, and docs/BATCHING.md has one sentence where the memory per slot is described.
This commit is contained in:
1 parent
b5dfe5beaf
commit
00807c9b30
5 files changed
+241
-204
No files matched your search
+193
-191
File diff suppressed because it is too large.
Load diff
+3
-1
@@ -147,7 +147,9 @@ KV, more with a longer context unless the KV cache streams (`--kv-resident`: the
|
||||
stays in VRAM, and each slot's whole KV cache takes pinned RAM - 1.6 GB at 128K). On a card whose experts mostly run
|
||||
on the CPU, a batch also reads about as many distinct experts as the requests one by one (different conversations
|
||||
route to different experts), so the gain is in **latency** (nobody waits for a whole answer), and a request alone
|
||||
runs slower (the smaller expert cache): 11-24 % on a 12 GB card, see the measurements below.
|
||||
runs slower (the smaller expert cache): 11-24 % on a 12 GB card, see the measurements below. With several requests at once
|
||||
on a Windows PC with integrated AMD graphics, the engine keeps less of the model's RAM copy so that every slot fits, and
|
||||
`STRATA_UMA_PIN_CAP=0` turns that off.
|
||||
|
||||
So setup recommends `"parallel"` **only where the experts mostly fit in VRAM**: the expert cache (each card's VRAM
|
||||
less ~5 GB, every card of a layer split counted) must still hold at least half of the model's experts beside the
|
||||
|
||||
@@ -50,10 +50,15 @@ inline int wddm_auto_reserve_mib(bool integrated, uint64_t total_bytes, int curr
|
||||
/// (-1834-6629) started. So the RAM copy is capped to what leaves complement + pinned K/V at the level of the largest start that worked, 22.75 GiB (the
|
||||
/// largest budget that started, 15 GiB, plus 4 slots' K/V). One bracket (15 works, 18 fails), not a derived limit. The experts left out are read from the SSD.
|
||||
inline uint64_t uma_pinned_complement_cap_bytes(uint64_t kv_pinned_bytes) {
|
||||
constexpr uint64_t GiB = 1ull << 30;
|
||||
constexpr uint64_t level = GiB * 2275 / 100; // 22.75 GiB
|
||||
const uint64_t cap = level > kv_pinned_bytes ? level - kv_pinned_bytes : 0;
|
||||
return cap > GiB ? cap : GiB; // never 0 (a budget of 0 means "no limit")
|
||||
constexpr uint64_t level = (1ull << 30) * 2275 / 100; // 22.75 GiB
|
||||
return level > kv_pinned_bytes ? level - kv_pinned_bytes : 0; // 0 = keep no expert in RAM: every expert outside the GPU cache is read from the SSD (a start, not a refusal)
|
||||
}
|
||||
|
||||
/// The cap as the budget that pin_cache_complement takes: a budget of 0 there means "no limit", so "nothing in RAM" is the smallest real budget, 1 byte (no expert's blob
|
||||
/// fits in it: the copy is empty and every expert the cache does not hold is read from the SSD). Never an error, never a negative size.
|
||||
inline uint64_t uma_pinned_complement_budget_bytes(uint64_t kv_pinned_bytes) {
|
||||
const uint64_t cap = uma_pinned_complement_cap_bytes(kv_pinned_bytes);
|
||||
return cap > 0 ? cap : 1;
|
||||
}
|
||||
|
||||
} // namespace strata::core
|
||||
@@ -49,7 +49,17 @@ int main() {
|
||||
// 4 slots (5 sessions): 22.75 - 7.75 = 15.0 GiB, the largest budget that started (job strix-20261112-1937-7dbd)
|
||||
CHECK(capped(5) >= 14 * GiB + GiB * 99 / 100 && capped(5) <= 15 * GiB + GiB / 100);
|
||||
CHECK(capped(5) < 18 * GiB); // 18 failed
|
||||
CHECK(uma_pinned_complement_cap_bytes(30 * GiB) == GiB); // never 0: 0 would mean "no limit"
|
||||
// many slots: the K/V alone is over the level (15 sessions x 1.55 GiB = 23.25 > 22.75): the cap is 0 = no RAM copy, and the budget handed to the pin is 1 byte
|
||||
// (0 would mean "no limit"): a start with every expert outside the GPU cache read from the SSD, never an error, never a wrapped (negative) size
|
||||
CHECK(uma_pinned_complement_cap_bytes(30 * GiB) == 0);
|
||||
CHECK(uma_pinned_complement_cap_bytes(kv * 15) == 0);
|
||||
CHECK(uma_pinned_complement_budget_bytes(30 * GiB) == 1);
|
||||
CHECK(uma_pinned_complement_budget_bytes(kv * 15) == 1);
|
||||
CHECK(uma_pinned_complement_budget_bytes(~0ull) == 1); // the largest input
|
||||
CHECK(uma_pinned_complement_cap_bytes(0) == GiB * 2275 / 100); // no session at all: the whole level
|
||||
CHECK(uma_pinned_complement_cap_bytes(kv * 9) > 8 * GiB + GiB * 50 / 100); // 8 slots + the main session (9 x 1.55 = 13.95): 8.8 GiB, still a copy
|
||||
CHECK(uma_pinned_complement_cap_bytes(kv * 14) > 0); // 14 sessions: 1.05 GiB left
|
||||
CHECK(uma_pinned_complement_budget_bytes(kv * 5) == uma_pinned_complement_cap_bytes(kv * 5)); // above zero the budget is the cap itself
|
||||
}
|
||||
if (fails == 0) std::printf("uma_cache_test: all checks passed\n");
|
||||
return fails == 0 ? 0 : 1;
|
||||
|
||||
@@ -10694,13 +10694,21 @@ int main(int argc, char** argv) {
|
||||
// that is the page-locked memory of the start. 4 slots at 131,072 tokens with the usual 38 GiB budget (20.33 GiB of complement) stopped inside the prompt
|
||||
// path, and with 18 GiB the OS ran out of page-locked memory; 15 GiB started and served. So here the RAM copy is cut to what leaves complement + pinned K/V
|
||||
// at the level of the largest start that worked (include/strata/core/uma_cache.hpp, with the job ids); the experts left out are read from the SSD. Context,
|
||||
// slot count and prompt chunk are untouched. Only with --batch 2 or more, so a single request is as before. STRATA_UMA_PIN_CAP set (any value): off, test only.
|
||||
if (o.batch >= 2 && o.prefill_own_keep_chunk && o.resident_budget > 0 && std::getenv("STRATA_UMA_PIN_CAP") == nullptr) {
|
||||
const uint64_t cap = strata::core::uma_pinned_complement_cap_bytes(strata::core::qsa_kv_host_bytes());
|
||||
if (o.resident_budget > cap) {
|
||||
std::fprintf(stderr, "strata: %d requests at once: %.1f GiB of experts are kept in RAM so that everything fits in this PC's memory; the rest are read from the SSD when needed\n",
|
||||
o.batch, (double) cap / 1073741824.0);
|
||||
o.resident_budget = cap;
|
||||
// slot count and prompt chunk are untouched. Only with --batch 2 or more, so a single request is as before. STRATA_UMA_PIN_CAP=0: the RAM budget stays as set (the way back).
|
||||
// The line below is printed after the pin, and only when the cap really left experts out (the RAM copy filled up to it): with 2 slots (12.47 GiB of complement) and
|
||||
// 3 slots (16.40 GiB) the whole complement is under the cap, nothing is cut and the start is as before (strix-20261112-1952-001f printed the line there).
|
||||
// The cap has no floor that turns into a refusal (owner, 11-12: "we should allow people to start, even if its read by ssd"): with so many slots that their K/V alone is over
|
||||
// the level the cap is 0 and the RAM copy is empty (budget 1 byte: 0 would mean "no limit"); every expert the GPU cache does not hold is read from the SSD, and the start goes on.
|
||||
bool uma_cap_applied = false;
|
||||
uint64_t uma_cap = 0;
|
||||
const char* const uma_pin_cap = std::getenv("STRATA_UMA_PIN_CAP");
|
||||
if (o.batch >= 2 && o.prefill_own_keep_chunk && o.resident_budget > 0 && !(uma_pin_cap != nullptr && uma_pin_cap[0] == '0')) {
|
||||
const uint64_t kv = strata::core::qsa_kv_host_bytes();
|
||||
uma_cap = strata::core::uma_pinned_complement_cap_bytes(kv);
|
||||
const uint64_t budget = strata::core::uma_pinned_complement_budget_bytes(kv);
|
||||
if (o.resident_budget > budget) {
|
||||
uma_cap_applied = true;
|
||||
o.resident_budget = budget;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -10708,6 +10716,16 @@ int main(int argc, char** argv) {
|
||||
src.budget_is_automatic(ram_fallback_resident); // its clamp line then names no flag
|
||||
bool resident_ok = src.pin_cache_complement(xcache, err, o.resident_pin, stage_pairs, lend_from,
|
||||
o.resident_headroom, o.resident_budget, &rank_all);
|
||||
#if defined(STRATA_USE_HIP) && defined(_WIN32)
|
||||
// cut = the RAM copy reached the cap (within 16 MiB: the ranked experts are taken while they fit, the last gap is under one expert's blob, about 4 MiB)
|
||||
if (uma_cap_applied && resident_ok && src.resident_bytes() + (16ull << 20) >= uma_cap) {
|
||||
if (uma_cap == 0)
|
||||
std::fprintf(stderr, "strata: %d requests at once: the experts are read from the SSD when needed so that everything fits in this PC's memory (STRATA_UMA_PIN_CAP=0 keeps the RAM budget as set)\n", o.batch);
|
||||
else
|
||||
std::fprintf(stderr, "strata: %d requests at once: %.1f GiB of experts are kept in RAM so that everything fits in this PC's memory; the rest are read from the SSD when needed (STRATA_UMA_PIN_CAP=0 keeps the RAM budget as set)\n",
|
||||
o.batch, (double) uma_cap / 1073741824.0);
|
||||
}
|
||||
#endif
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user