Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
setup: UD-Q4_K_XL across GPUs without the RAM budget when the RAM holds it; no budget on a --gpus start (#498)
Niko122118b9c1845460
diff --git a/docs/UNSLOTH_Q4.md b/docs/UNSLOTH_Q4.mdindex cf8d2ac39..12d4d1997 100644--- a/docs/UNSLOTH_Q4.md+++ b/docs/UNSLOTH_Q4.md@@ -25,8 +25,16 @@ What setup does differently for this model:- It needs 48 GB of RAM or more (with less it asks, default no; `--model UD-Q4_K_XL --yes` installs it anyway) andengine 0.1.32 or newer (checked before anything is downloaded), and an NVIDIAGPU: it has not been run on AMD cards (its prompt kernels for the Q4_K / Q5_K experts are NVIDIA-only), so with- `--backend hip` setup says so and asks before the download (#429; `--model UD-Q4_K_XL --yes` tries it). One GPU only: with `--gpus` it uses the first one and says so. No images (the vision encoder is not wired to- this file yet) and no experimental speed projection (not tested with it).+ `--backend hip` setup says so and asks before the download (#429; `--model UD-Q4_K_XL --yes` tries it). One GPU+ by default: the RAM budget below has no layer split (the engine refuses `--resident-budget-gib` with one). No+ images (the vision encoder is not wired to this file yet) and no experimental speed projection (not tested with it).+- Several GPUs (#498): when the RAM holds the GGUF files and 24 GB more (~135 GB of RAM) and two or more cards can+ share it, setup asks (one GPU stays the default; `--gpus 0,1` takes the split). The split runs **without** the RAM budget: all 77 GB of experts are loaded into RAM from the GGUFs at+ start, the files pass through the OS file cache while they load, and the config gets `"gpu": [0, 1]` and+ `"layer_split": "auto"`. Measured on 2x RTX 3090 with 165 GiB (#498): decode 31 tok/s on one card with the budget,+ 64-78 tok/s split (55 tok/s at a 128K prompt), with `MemAvailable` never under 68 GiB. With less RAM, `--gpus`+ keeps one GPU and says so, and `START-HERE.bat --gpus 0,1` on an installed UD-Q4_K_XL stops with the reason+ (it used to keep the budget, and the engine exited with code 2).- It downloads the four shards below from the pinned revision `38bb39e` (resumable, like the other models), thenchecks each one's size and SHA-256 against the table below; the check takes a few minutes once and is rememberedin the file's finish mark. A file with the wrong hash is deleted, so the next run downloads it again.diff --git a/setup.py b/setup.pyindex 0ecfcb5f5..e1a31409c 100644--- a/setup.py+++ b/setup.py@@ -607,6 +607,33 @@ def split_mmap(cfg: dict) -> bool:return True+def unsloth_split_need_gb(model="UD-Q4_K_XL") -> float:+ """#498: the RAM UD-Q4_K_XL needs on several GPUs, where it has no RAM budget (the engine refuses+ --resident-budget-gib with a layer split): its GGUF files and UNSLOTH_RAM_LEFT_GB more (~135 GB). Measured safe+ at 165 GiB (2x RTX 3090: MemAvailable never under 68 GiB); the 0-free case of #384 was 47 GB with a 70 GB model."""+ return MODELS[model]["download_gb"] + UNSLOTH_RAM_LEFT_GB+++def split_budget(cfg: dict) -> bool:+ """#498: a UD-Q4_K_XL config (its RAM budget, --resident-budget-gib) started on several GPUs. The engine refuses+ the budget with a layer split (it exited with code 2), so the split runs without it - all the experts loaded into+ RAM at start - where the RAM holds the GGUFs and 24 GB more; else setup stops, before the config is saved. True+ when the config changed."""+ a = cfg.get("args", [])+ if "--resident-budget-gib" not in a:+ return False+ need, ram = unsloth_split_need_gb(), ram_gb()+ if ram < need:+ fail(f"UD-Q4_K_XL cannot share its RAM budget across GPUs (the engine has no layer split with it), and without "+ f"the budget it needs ~{need:.0f} GB of RAM (its GGUF files and {UNSLOTH_RAM_LEFT_GB} GB more); this PC "+ f"has {ram:.0f} GB", "start it on one GPU: START-HERE.bat --gpu N (Linux: ./setup.sh --gpu N)")+ i = a.index("--resident-budget-gib")+ del a[i:i + 2]+ ok("UD-Q4_K_XL on several GPUs: no RAM budget (the engine has none with a layer split) - all its experts are "+ "loaded into RAM from the model files at start, and the files pass through the OS file cache (#498)")+ return True++def offer_together(cfg_path: Path, cfg: dict, yes: bool) -> dict:"""Starting a model set up for one card on a PC with two or more that can share it: asked once (the answer issaved in its config)."""@@ -616,6 +643,10 @@ def offer_together(cfg_path: Path, cfg: dict, yes: bool) -> dict:can = together_ok(found)if not can:return cfg+ # #498: UD-Q4_K_XL's RAM budget has no layer split; without it the RAM must hold the GGUFs and 24 GB more+ budget = "--resident-budget-gib" in cfg.get("args", [])+ if budget and ram_gb() < unsloth_split_need_gb():+ return cfgpair = can[:2]cfg["gpus_asked"] = True# #364 #384: the resident low-RAM variant stays on one card unless the user says otherwise (its RAM use is steady)@@ -627,6 +658,10 @@ def offer_together(cfg_path: Path, cfg: dict, yes: bool) -> dict:say(" This model runs in the low-RAM mode with its experts kept in RAM, on one GPU (recommended: steady RAM")say(" use). On both, the experts the GPUs do not hold are read through the OS file cache instead: faster in")say(" two reports (#364, #384), but RAM can fill up to 0 free during long prompts.")+ if budget:+ say(" This model (UD-Q4_K_XL) runs on one GPU with a RAM budget of its experts (recommended: the tested")+ say(" setup). On both it has no budget: all its experts are loaded into RAM at start, which this PC's RAM")+ say(" holds - about twice as fast in #498 (2x RTX 3090: 31 -> 64-78 tokens/s).")short = split_short(pair) # #448: one card recommended (asked "n" by default), as for --residentfor g in short:say(f" {split_short_note(g)}.")@@ -635,10 +670,11 @@ def offer_together(cfg_path: Path, cfg: dict, yes: bool) -> dict:say(" The installed engine has no code for " + ", ".join(g["name"] for g in missing) + ": to use them ""together, run START-HERE.bat --setup --gpus " + ",".join(str(g["index"]) for g in pair))elif ask(" Use both from now on? (you can change it later: START-HERE.bat --gpu N for one card)",- ["y", "n"], "n" if resident or short else "y", yes) == "y":+ ["y", "n"], "n" if resident or short or budget else "y", yes) == "y":cfg["gpu"] = [g["index"] for g in pair]cfg["layer_split"] = cfg.get("layer_split") or "auto"split_mmap(cfg)+ split_budget(cfg)ok("from now on this model runs on " + " + ".join(gpu_name(g) for g in pair))else:ok("staying on one GPU (START-HERE.bat --gpus " + ",".join(str(g["index"]) for g in pair) + " switches)")@@ -2077,6 +2113,43 @@ def low_ram_together(a, model, ram, gpu, chosen) -> bool:return False+def unsloth_together(a, model, ram, gpu, chosen) -> bool:+ """#498: UD-Q4_K_XL with several GPUs chosen. Its RAM budget (--resident-budget-gib) has no layer split, so a+ split runs without it: all its experts loaded into RAM from the GGUFs at start, as with the 2-3-bit models - only+ where the RAM holds the GGUF files and 24 GB more (unsloth_split_need_gb; 165 GiB, 2x RTX 3090: 31 -> 64-78+ tok/s). An explicit --gpus is honoured there; otherwise asked, one GPU by default (--yes: one GPU, as before); an+ explicit --resident-budget-gib keeps one GPU. True: all of them."""+ names = " + ".join(gpu_name(g) for g in chosen)+ need = unsloth_split_need_gb(model)+ if ram < need:+ warn(f"{model} runs on one GPU here: on several it has no RAM budget and needs ~{need:.0f} GB of RAM (its GGUF "+ f"files and {UNSLOTH_RAM_LEFT_GB} GB more), this PC has {ram:.0f} - using {gpu_name(gpu)} only")+ return False+ if a.resident_budget_gib is not None:+ warn(f"--resident-budget-gib has no layer split: {model} runs on one GPU with it - using {gpu_name(gpu)} only "+ f"(leave the budget out to use {names} together)")+ return False+ note = (f"no RAM budget - all of its experts (~{MODELS[model]['arena_gb']:.0f} GB) are loaded into RAM from the "+ f"model files at start, and the files pass through the OS file cache (needs ~{need:.0f} GB of RAM, this "+ f"PC has {ram:.0f})")+ if a.gpus:+ ok(f"{model} on {names}, as you chose (--gpus): {note}")+ return True+ if not a.yes:+ say()+ say(f" {model} can run on one GPU with a RAM budget of its experts, or on {names} together without one:")+ say(f" 1) {gpu_name(gpu)} only: the most-used experts kept in RAM, the rest read from the SSD (recommended: "+ "the tested setup)")+ say(f" 2) {names} together: {note};")+ say(" about twice as fast in #498 (2x RTX 3090: 31 -> 64-78 tokens/s)")+ if ask(f"{model}: which GPUs?", ["1", "2"], "1", a.yes) == "2":+ ok(f"{model} on {names}: {note}")+ return True+ warn(f"{model} runs on one GPU: using {gpu_name(gpu)} only (--gpus " + ",".join(str(g["index"]) for g in chosen) ++ f" shares it across {names} without the RAM budget: this PC's RAM holds it)")+ return False++def confirm_risk(msg, explicit, yes, stop, hint=None, question=" Go on anyway?", default="n") -> None:"""The owner's rule: setup recommends, it never forces. A choice setup expects to fail or run badly is saidplainly (msg), then asked (default n; `default` keeps an older question's own default), or with --yes taken as@@ -2522,6 +2595,7 @@ def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_"set it up for these cards: ./setup.sh --setup --backend hip --gpus " + ",".join(map(str, gpu)))cfg["gpu"], cfg["gpus_asked"] = gpu, Truecfg["layer_split"] = layer_split or cfg.get("layer_split") or "auto"+ split_budget(cfg) # #498: before it is saved (it stops when the RAM is short)write_config(cfg_path, cfg)gpu = Noneelif gpu is not None:@@ -2545,6 +2619,7 @@ def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_check_gpus(gpu, found, yes=yes, named=True)cfg["gpu"], cfg["gpus_asked"] = gpu, Truecfg["layer_split"] = layer_split or cfg.get("layer_split") or "auto"+ split_budget(cfg) # #498: before it is saved (it stops when the RAM is short)write_config(cfg_path, cfg)gpu = Noneelif gpu is not None: # --gpu N: this start only, on that card@@ -2553,7 +2628,8 @@ def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_else:cfg = offer_together(cfg_path, cfg, yes)use = gpu if gpu is not None else cfg.get("gpu")- if isinstance(use, list) and split_mmap(cfg): # #364 #384: a resident low-RAM config on several GPUs+ # #364 #384: a resident low-RAM config on several GPUs; #498: a UD-Q4_K_XL config with its RAM budget (by hand)+ if isinstance(use, list) and (split_mmap(cfg) | split_budget(cfg)):write_config(cfg_path, cfg)if cfg.get("backend") == "hip":pass@@ -3035,10 +3111,11 @@ def main() -> int:say(f" {i}) {m:8s} {d['about']}; download {d['download_gb']:.0f} GB, uses ~{d['arena_gb']:.0f} GB of RAM{fit}")rec = str(names.index("IQ3_XXS") + 1) if ram >= 60 and "IQ3_XXS" in names else "1"model = a.model or names[int(ask("Which size?", [str(i) for i in range(1, len(names) + 1)], rec, a.yes)) - 1]- budget = None+ budget, q4_split = None, Falseif MODELS[model].get("budget"):# Unsloth's UD-Q4_K_XL: a RAM budget of experts, the rest from the GGUF on the SSD - not the low-RAM mode (no- # experts.bin: it would be another 77 GB on the disk), and one GPU (the budget mode has no layer split)+ # experts.bin: it would be another 77 GB on the disk), and one GPU (the budget mode has no layer split) unless+ # the RAM holds the GGUFs and 24 GB more: then several, without the budget, if asked for (#498)warn(f"{model} is EXPERIMENTAL (docs/UNSLOTH_Q4.md): most of its experts are read from the SSD while it ""answers, so it is several times slower than the 2-3-bit models; quality checked against llama.cpp")if hip:@@ -3058,12 +3135,13 @@ def main() -> int:"install it anyway", " Install it anyway?")warn(f"installing {model} with {ram:.0f} GB of RAM, as you chose")budget = budget_choice(model, ram, a.resident_budget_gib)- ok(f"RAM budget: {budget:g} GiB of {model}'s experts in RAM, the rest read from the model files on the SSD")+ if multi and not unsloth_together(a, model, ram, gpu, chosen):+ multi, sel, chosen = [], [gpu["index"]], [gpu]+ q4_split = bool(multi) # #498: on several GPUs without the RAM budget+ if not q4_split:+ ok(f"RAM budget: {budget:g} GiB of {model}'s experts in RAM, the rest read from the model files on the SSD")if a.low_ram not in ("auto", "off"):warn(f"--low-ram {a.low_ram} does not apply to {model}: it always reads part of its experts from the files")- if multi:- warn(f"{model} runs on one GPU: using " + gpu_name(gpu) + " only")- multi, sel, chosen = [], [gpu["index"]], [gpu]elif a.resident_budget_gib is not None:warn(f"--resident-budget-gib is for UD-Q4_K_XL: {model} keeps all of its experts in RAM or in the low-RAM mode")low_ram = budget is None and (a.low_ram in ("on", "resident", "mmap") or@@ -3402,7 +3480,9 @@ def main() -> int:warn(f"KV streaming needs ~{kv_ram_gb:.1f} GB of RAM beside the ~{MODELS[model]['ram_gb']} GB {model} "f"uses; this PC has {ram:.0f}. Kept as you chose (--kv-streaming on): it may page or run out of RAM ""under load")- if budget is not None and a.resident_budget_gib is None: # its RAM comes out of the experts' budget+ if q4_split: # #498: no budget to take it out of+ pass+ elif budget is not None and a.resident_budget_gib is None: # its RAM comes out of the experts' budgetbudget = resident_budget_gib(model, ram, kv_ram_gb)ok(f"RAM budget: {budget} GiB (less the KV cache's RAM)")elif budget is not None and budget > resident_budget_gib(model, ram, kv_ram_gb):@@ -3410,8 +3490,8 @@ def main() -> int:f"would take them out of it: {resident_budget_gib(model, ram, kv_ram_gb)} GiB); kept as you chose")elif a.kv_streaming == "on":warn("--kv-streaming on: a context under 64K is not streamed (the attention's window holds all of it): off")- if budget is not None: # UD-Q4_K_XL: the experts read from the GGUF in place, the most-used N GiB kept in RAM- args += ["--resident-budget-gib", f"{budget:g}"]+ if budget is not None and not q4_split: # UD-Q4_K_XL: the experts read from the GGUF in place, the most-used N+ args += ["--resident-budget-gib", f"{budget:g}"] # GiB kept in RAM (#498: a layer split has no budget)if vision != "none":args += ["--vision", "--vram-reserve-mib", str(VISION[vision]["reserve_mib"])]if esp is not None:diff --git a/tools/test_setup_unsloth.py b/tools/test_setup_unsloth.pyindex e6bd13fe6..a010b5e8f 100644--- a/tools/test_setup_unsloth.py+++ b/tools/test_setup_unsloth.py@@ -319,6 +319,117 @@ class Main(unittest.TestCase):self.assertNotIn("--mmap-experts", cfg["args"])self.assertFalse(any("--experts-bin" in r for r in self.runs))+ def test_split_when_the_ram_holds_it(self):+ # #498: 165 GiB and --gpus 0,1: the split without the RAM budget (the engine refuses the pair)+ code, out, cfg = self.main(["--context", "8192", "--gpus", "0,1"], n_gpus=2, ram=165.0)+ self.assertEqual(code, 0, out)+ self.assertEqual(cfg["gpu"], [0, 1])+ self.assertEqual(cfg["layer_split"], "auto")+ for flag in ("--resident-budget-gib", "--mmap-experts", "--resident-experts"):+ self.assertNotIn(flag, cfg["args"])+ self.assertIn("as you chose (--gpus): no RAM budget", out)+ self.assertIn("OS file cache", out)+ self.assertNotIn("RAM budget: ", out)++ def test_split_refused_without_the_ram(self):+ need = setup.unsloth_split_need_gb()+ self.assertAlmostEqual(need, setup.MODELS[M]["download_gb"] + setup.UNSLOTH_RAM_LEFT_GB)+ code, out, cfg = self.main(["--context", "8192", "--gpus", "0,1"], n_gpus=2, ram=127.8)+ self.assertEqual(code, 0, out)+ self.assertIn("runs on one GPU here", out)+ self.assertNotIn("layer_split", cfg)+ self.assertEqual(cfg["args"][cfg["args"].index("--resident-budget-gib") + 1], "71") # all of them++ def test_an_explicit_budget_keeps_one_gpu(self):+ code, out, cfg = self.main(["--context", "8192", "--gpus", "0,1", "--resident-budget-gib", "60"], n_gpus=2,+ ram=165.0)+ self.assertEqual(code, 0, out)+ self.assertIn("--resident-budget-gib has no layer split", out)+ self.assertNotIn("layer_split", cfg)+ self.assertEqual(cfg["args"][cfg["args"].index("--resident-budget-gib") + 1], "60")++ def test_yes_alone_keeps_one_gpu(self):+ code, out, cfg = self.main(["--context", "8192"], n_gpus=2, ram=165.0)+ self.assertEqual(code, 0, out)+ self.assertIn("runs on one GPU: using", out)+ self.assertIn("--gpus 0,1 shares it", out)+ self.assertNotIn("layer_split", cfg)+ self.assertIn("--resident-budget-gib", cfg["args"])+++class LayerSplit(unittest.TestCase):+ """#498: UD-Q4_K_XL across GPUs - asked at setup (one GPU by default), and a start with --gpus no longer keeps+ the RAM budget the engine refuses with a split (it exited with code 2)."""++ def setUp(self):+ sys.path.insert(0, str(ROOT / "tools"))+ from test_setup_golden import card+ self.found = [card(i, "NVIDIA GeForce RTX 3090", 24.0, "86") for i in range(2)]++ def test_asked_one_gpu_by_default(self):+ from test_setup_golden import install+ argv = ["--family", "unsloth", "--model", M, "--context", "32768", "--no-start"]+ code, out, cfg, asked = install(165.0, self.found, argv, answers={"which GPUs?": "1", "Which GPUs?": "1"})+ self.assertEqual(code, 0, out)+ self.assertTrue(any(f"{M}: which GPUs?" in q and "[1]" in q for q in asked), asked)+ self.assertEqual(cfg["gpu"], 0)+ self.assertIn("--resident-budget-gib", cfg["args"])+ code, out, cfg, asked = install(165.0, self.found, argv, answers={f"{M}: which GPUs?": "2"})+ self.assertEqual(code, 0, out)+ self.assertEqual(cfg["gpu"], [0, 1])+ self.assertEqual(cfg["layer_split"], "auto")+ self.assertNotIn("--resident-budget-gib", cfg["args"])++ def start(self, ram, gpu=(0, 1), offered=None):+ from test_setup_risk import run+ with tempfile.TemporaryDirectory() as d:+ exe = Path(d) / "strata.exe"+ exe.write_bytes(b"")+ p = Path(d) / "strata-unsloth-ud-q4_k_xl.json"+ before = {"exe": str(exe), "args": ["--pack", "p", "--resident-budget-gib", "40", "--kv", "int8"],+ "gpu": 0, "gpus_asked": offered is None}+ p.write_text(json.dumps(before))+ call = mock.Mock(return_value=0)+ with mock.patch.object(setup, "gpus", lambda: self.found), \+ mock.patch.object(setup, "ram_gb", lambda: ram), \+ mock.patch.object(setup, "engine_runs_on", lambda g: True), \+ mock.patch.object(setup, "ensure_engine_for", lambda cards, path, cfg, yes: cfg), \+ mock.patch.object(setup, "is_wsl", lambda: False), \+ mock.patch.object(setup.subprocess, "call", call):+ code, out, asked = run(setup.start, p, None, list(gpu) if gpu else None, False, offered is None,+ stdin=offered)+ return code, out, json.loads(p.read_text()), call.called++ def test_start_with_gpus_drops_the_budget(self):+ code, out, cfg, started = self.start(165.0)+ self.assertIsNone(code, out)+ self.assertTrue(started)+ self.assertEqual(cfg["gpu"], [0, 1])+ self.assertEqual(cfg["args"], ["--pack", "p", "--kv", "int8"])+ self.assertIn("no RAM budget", out)++ def test_start_with_gpus_refused_without_the_ram(self):+ code, out, cfg, started = self.start(63.7)+ self.assertEqual(code, 1)+ self.assertFalse(started)+ self.assertIn("cannot share its RAM budget across GPUs", out)+ self.assertIn("--gpu N", out)+ self.assertEqual(cfg["gpu"], 0) # nothing saved+ self.assertIn("--resident-budget-gib", cfg["args"])++ def test_offered_at_a_start(self):+ code, out, cfg, _ = self.start(165.0, gpu=None, offered="") # Enter: one GPU (the default here)+ self.assertIsNone(code, out)+ self.assertEqual(cfg["gpu"], 0)+ self.assertIn("--resident-budget-gib", cfg["args"])+ self.assertIn("about twice as fast in #498", out)+ code, out, cfg, _ = self.start(165.0, gpu=None, offered="y")+ self.assertEqual(cfg["gpu"], [0, 1])+ self.assertNotIn("--resident-budget-gib", cfg["args"])+ code, out, cfg, _ = self.start(63.7, gpu=None, offered="y") # not offered: the RAM does not hold it+ self.assertEqual(cfg["gpu"], 0)+ self.assertNotIn("Use both", out)+if __name__ == "__main__":unittest.main()