setup: a Strix Halo's BIOS carve-out holds expert slots of the Unsloth RAM-budget plans
uma_expert_cache counted only the RAM the OS sees, so UD-IQ4_XS (55 GiB of experts) and UD-Q4_K_XL (72 GiB) on a PC with a 64 GB carve-out and 64 GB seen by Windows got no cache slots beside the 40 GiB budget and read the rest from the SSD. The carve-out (less 14 GB for the dense weights and buffers) now adds its slots. Tests added.
This commit is contained in:
1 parent
2fef430202
commit
94fc01c6fd
2 files changed
+52
-7
No files matched your search
@@ -3331,16 +3331,31 @@ def flash_vision_encoder(asked: str, gpu: dict) -> str:
|
||||
UMA_EXPERTS = 24576 # the Flash-Next model's experts (48 layers x 512): the most an expert cache can hold
|
||||
|
||||
|
||||
def uma_expert_cache(model, ram, budget_gib, kv_ram_gb=0.0):
|
||||
UMA_CARVE_OTHER_GB = 14 # what stays in a BIOS carve-out besides experts: the dense weights (~5 GB), the draft layer, the KV cache,
|
||||
# the verify windows and the prompt path's own buffers (gfx1151 Windows: no borrowed slots)
|
||||
|
||||
|
||||
def uma_carveout_slots(model, dedicated_gb) -> int:
|
||||
"""Expert slots a BIOS carve-out holds beside the dense weights and buffers (UMA_CARVE_OTHER_GB). The carve-out is real
|
||||
VRAM that the OS does not have: RAM-budget placement of an Unsloth file put the whole cache in the OS's RAM, so a Strix Halo
|
||||
with a 64 GB carve-out and 64 GB seen by Windows read 55-72 GiB of experts from the SSD."""
|
||||
slot_gib = MODELS[model]["arena_gb"] * 1e9 / UMA_EXPERTS * 1.1 / 2**30
|
||||
return max(0, int((float(dedicated_gb or 0.0) - UMA_CARVE_OTHER_GB) / slot_gib))
|
||||
|
||||
|
||||
def uma_expert_cache(model, ram, budget_gib, kv_ram_gb=0.0, dedicated_gb=0.0):
|
||||
"""#1715: on a unified-memory APU (Strix Halo) the GPU's expert cache and the RAM budget of experts are both RAM.
|
||||
`--expert-cache auto` sizes the cache from the memory the OS can give back at start, which counts all the RAM the
|
||||
budget has not taken yet: a 128 GB box with a 55 GiB budget and the desktop open was killed by the OOM killer. So
|
||||
there setup writes a number, not `auto`: the RAM less UNSLOTH_RAM_LEFT_GB less the budget (and a KV cache streamed
|
||||
to RAM), in slots (an expert is priced at 1.1x the average one: the Q8_0 downs are bigger). None when no room is left
|
||||
(the config keeps `auto`). A recommendation: the number is in the config's args, and --expert-cache N there sets it."""
|
||||
to RAM), in slots (an expert is priced at 1.1x the average one: the Q8_0 downs are bigger). A BIOS carve-out
|
||||
(`dedicated_gb`) is memory the OS does not have, so its slots (uma_carveout_slots) come on top of those of the RAM.
|
||||
None when no room is left (the config keeps `auto`). A recommendation: the number is in the config's args, and
|
||||
--expert-cache N there sets it."""
|
||||
slot_gib = MODELS[model]["arena_gb"] * 1e9 / UMA_EXPERTS * 1.1 / 2**30
|
||||
room = ram - UNSLOTH_RAM_LEFT_GB - budget_gib - math.ceil(kv_ram_gb)
|
||||
slots = min(UMA_EXPERTS, int(room / slot_gib))
|
||||
slots = max(0, int(room / slot_gib)) + uma_carveout_slots(model, dedicated_gb)
|
||||
slots = min(UMA_EXPERTS, slots)
|
||||
return slots if slots >= 256 else None
|
||||
|
||||
|
||||
@@ -9959,12 +9974,15 @@ def main() -> int:
|
||||
args += ["--resident-budget-gib", f"{budget:g}"] # GiB kept in RAM (#498: a layer split had no budget)
|
||||
if gpu.get("uma") and "--expert-cache" in args:
|
||||
# #1715: the cache and the budget draw on the same RAM: a number that leaves the OS its room, not `auto`
|
||||
slots = uma_expert_cache(model, ram, budget, kv_ram_gb if "--kv-resident" in args else 0.0)
|
||||
slots = uma_expert_cache(model, ram, budget, kv_ram_gb if "--kv-resident" in args else 0.0,
|
||||
gpu.get("dedicated_gb", 0.0))
|
||||
if slots is not None:
|
||||
args[args.index("--expert-cache") + 1] = str(slots)
|
||||
carve = uma_carveout_slots(model, gpu.get("dedicated_gb", 0.0))
|
||||
ok(f"expert cache: {slots} slots (not auto): this GPU shares the RAM with the {budget:g} GiB budget, "
|
||||
f"so setup leaves {UNSLOTH_RAM_LEFT_GB} GB of the RAM for the OS and the desktop (#1715). "
|
||||
"--expert-cache N in the config's args sets it")
|
||||
f"so setup leaves {UNSLOTH_RAM_LEFT_GB} GB of the RAM for the OS and the desktop (#1715)"
|
||||
+ (f"; {carve} of the slots sit in the {gpu.get('dedicated_gb', 0.0):.0f} GB BIOS carve-out" if carve else "")
|
||||
+ ". --expert-cache N in the config's args sets it")
|
||||
else:
|
||||
warn(f"this GPU shares the RAM, and the {budget:g} GiB RAM budget leaves almost none for the expert "
|
||||
"cache: it stays on auto, which may take the room the OS needs (#1715). A smaller "
|
||||
|
||||
@@ -613,6 +613,33 @@ class StrixHaloCache(Base):
|
||||
self.assertEqual(args[args.index("--expert-cache") + 1], "auto")
|
||||
self.assertIn("leaves almost none for the expert cache", out)
|
||||
|
||||
def test_a_big_carveout_holds_experts_too(self):
|
||||
"""A Strix Halo with a 64 GB BIOS carve-out and 64 GB seen by Windows: the RAM leaves no room for a cache after the
|
||||
40 GiB budget, but the carve-out is VRAM the OS does not have, so its slots come on top."""
|
||||
slot_gib = 59.5e9 / setup.UMA_EXPERTS * 1.1 / 2**30
|
||||
carve = int((64.0 - setup.UMA_CARVE_OTHER_GB) / slot_gib)
|
||||
self.assertEqual(setup.uma_carveout_slots("UD-IQ4_XS", 64.0), carve)
|
||||
self.assertEqual(setup.uma_expert_cache("UD-IQ4_XS", 64.0, 40, 0.0, 64.0), carve)
|
||||
self.assertIsNone(setup.uma_expert_cache("UD-IQ4_XS", 64.0, 40, 0.0, 2.0)) # a 2 GB carve-out adds nothing
|
||||
big = [dict(self.HALO[0], vram_gb=64.0, dedicated_gb=64.0, shared_gb=32.0)]
|
||||
code, out, cfg = self.run_halo(64.0, ("--context", "8192"), amd=big)
|
||||
self.assertEqual(code, 0, out)
|
||||
args = cfg["args"]
|
||||
self.assertEqual(args[args.index("--resident-budget-gib") + 1], "40")
|
||||
slots = int(args[args.index("--expert-cache") + 1])
|
||||
self.assertEqual(slots, carve)
|
||||
# the cache and the budget together hold every expert: 40 GiB budget + the carve-out's slots x the average expert
|
||||
self.assertGreaterEqual(40 * 2**30 + slots * 59.5e9 / setup.UMA_EXPERTS, 59.5e9)
|
||||
self.assertIn("of the slots sit in the 64 GB BIOS carve-out", out)
|
||||
|
||||
def test_carveout_slots_for_the_q4_k_xl_and_never_past_all_experts(self):
|
||||
q4 = setup.uma_carveout_slots("UD-Q4_K_XL", 64.0)
|
||||
self.assertTrue(10000 < q4 < setup.UMA_EXPERTS)
|
||||
self.assertLess(q4, setup.uma_carveout_slots("UD-IQ4_XS", 64.0)) # bigger experts, fewer slots
|
||||
self.assertEqual(setup.uma_expert_cache("UD-IQ4_XS", 512.0, 55, 0.0, 96.0), setup.UMA_EXPERTS)
|
||||
self.assertEqual(setup.uma_carveout_slots("UD-IQ4_XS", 0.0), 0)
|
||||
self.assertEqual(setup.uma_carveout_slots("UD-IQ4_XS", setup.UMA_CARVE_OTHER_GB), 0)
|
||||
|
||||
def test_a_discrete_card_keeps_auto(self):
|
||||
r9700 = [{"index": 0, "name": "AMD Radeon AI PRO R9700", "vram_gb": 31.9, "arch": "gfx1201",
|
||||
"driver": "amdgpu"}]
|
||||
|
||||
Reference in new issue
Block a user