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: the low-RAM and KV-streaming decisions as functions (low_ram_wanted, kv_streaming_wanted)
pipeob03b2e14cc11ae
diff --git a/setup.py b/setup.pyindex 886fe63b1..e9db821f7 100644--- a/setup.py+++ b/setup.py@@ -2587,6 +2587,33 @@ def low_ram_fits(model, ram, vram_gb) -> bool:return ram - 6 + max(0.0, vram_gb - 5) >= arena+def low_ram_wanted(model, ram, choice="auto") -> bool:+ """Does setup put this model in the low-RAM mode on this PC: its experts do not fit the RAM with the usual room+ beside them (`low_ram_needed`), or the user asked for it. Unsloth's 4-bit file is not the low-RAM mode at all:+ it always reads part of its experts from the files, through its RAM budget. Step 5 applies exactly this answer,+ and the launcher's preset diff asks it too - so a preset that says "auto" is compared with what auto decides,+ not with the word."""+ if MODELS[model].get("budget"):+ return False+ return choice in ("on", "resident", "mmap") or (choice == "auto" and low_ram_needed(model, ram))+++def kv_streaming_ram_gb(ctx, kv) -> float:+ """The RAM a streamed KV cache takes: ~13.7 KB per context token with 8-bit KV (1.7 GB at 128K), 7.5 KB with+ 4-bit - 12 QSA layers + the draft layer."""+ return ctx * (13 * KV_CELL_BYTES.get(kv, 1056)) / 1e9+++def kv_streaming_wanted(model, ctx, kv, ram, choice="auto") -> bool:+ """Will setup stream this model's KV cache on this PC: from 64K up, when the RAM holds the cache beside the+ model's experts (+1 GB); `--kv-streaming on|off` overrides the RAM test (the owner's rule), and hybrid K8/V4+ and WSL never stream. Step 7 writes `--kv-resident` on exactly this answer, and the launcher's preset diff+ asks it too: a config's `--kv-resident` and a preset's "auto" are the same setting when this says yes."""+ if kv == "k8v4" or is_wsl() or choice == "off":+ return False+ return ctx >= 65536 and (ram >= MODELS[model]["ram_gb"] + kv_streaming_ram_gb(ctx, kv) + 1 or choice == "on")++def low_ram_one_gpu_why(model, ram, choice, sel=None) -> list[str]:"""#250: why the low-RAM mode recommends one GPU, with the RAM math that turned it on; #364 #384: and how to useall of them (sel: the cards, for the --gpus example)."""@@ -4240,8 +4267,7 @@ def main() -> int:elif a.resident_budget_gib is not None:warn(f"--resident-budget-gib is for UD-Q4_K_XL and UD-IQ4_XS: {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- (a.low_ram == "auto" and low_ram_needed(model, ram)))+ low_ram = low_ram_wanted(model, ram, a.low_ram)# #642: the engines from RESIDENT_SPLIT_ENGINE run the low-RAM mode on the chosen cards as on one (decided below)if low_ram and multi and not resident_split() and not low_ram_together(a, model, ram, gpu, chosen):multi, sel, chosen = [], [gpu["index"]], [gpu]@@ -4586,7 +4612,7 @@ def main() -> int:# per layer) stays in VRAM; the VRAM it frees holds more experts (+6% at 128K, +23% at 262K with Q2_0). It# costs ~13.7 KB of RAM per context token with 8-bit KV (1.7 GB at 128K), 10.6 KB with K8V4, 7.5 KB with 4-bit, so only# when it fits.- kv_ram_gb = ctx * (13 * KV_CELL_BYTES.get(kv, 1056)) / 1e9 # 12 QSA layers + the draft layer+ kv_ram_gb = kv_streaming_ram_gb(ctx, kv) # the branches below are kv_streaming_wanted, with its messages# --kv-streaming on|off overrides the RAM test (the owner's rule); WSL stays off - it cannot stream.stream_fits = ram >= MODELS[model]["ram_gb"] + kv_ram_gb + 1if is_wsl() and ctx >= 65536:diff --git a/tools/test_setup_risk.py b/tools/test_setup_risk.pyindex 62267050b..9a0174d86 100644--- a/tools/test_setup_risk.py+++ b/tools/test_setup_risk.py@@ -9,6 +9,7 @@ from __future__ import annotationsimport contextlibimport io+import itertoolsimport jsonimport osimport sys@@ -476,5 +477,37 @@ class KvStreaming(unittest.TestCase):self.assertIn("--resident-budget-gib is for UD-Q4_K_XL", out)+class RulesAgreeWithTheWrittenConfig(unittest.TestCase):+ """The launcher's preset diff asks setup's rules (`kv_streaming_wanted`, `low_ram_wanted`) what "auto" decides on+ this PC, instead of comparing the word "auto" with a config's flags. That is only honest if those rules are+ exactly what setup writes into the model's config: the same PC, the same flags, every size and every+ --kv-streaming / --low-ram choice."""+ RAM64, CARDS64 = PROFILES["64GB-1x32GB"]+ RAM32, CARDS32 = PROFILES["32GB-2x24GB"]++ def go(self, ram, cards, model, *flags):+ return install(ram, cards, ["--family", "qwen", "--model", model, "--no-start", *flags])++ def test_the_streaming_rule_is_the_flag_setup_writes(self):+ for model, ctx, kv, choice in itertools.product(("Q2_0", "IQ3_XXS", "IQ3_S"), ("32768", "131072"),+ ("int8", "q4_0", "k8v4"), ("auto", "on", "off")):+ code, out, cfg, _ = self.go(self.RAM64, self.CARDS64, model, "--context", ctx, "--kv", kv,+ "--kv-streaming", choice)+ self.assertEqual(code, 0, out)+ self.assertEqual("--kv-resident" in cfg["args"],+ setup.kv_streaming_wanted(model, int(ctx), kv, self.RAM64, choice),+ f"{model} at {ctx} with {kv}, --kv-streaming {choice}: setup wrote {cfg['args']}")++ def test_the_low_ram_rule_is_the_flag_setup_writes(self):+ pcs = [(self.RAM64, self.CARDS64), (self.RAM32, self.CARDS32)] # auto is on here, off there+ for (ram, cards), model, choice in itertools.product(pcs, ("Q2_0", "IQ3_XXS", "IQ3_S"),+ ("auto", "on", "off", "mmap")):+ code, out, cfg, _ = self.go(ram, cards, model, "--low-ram", choice)+ self.assertEqual(code, 0, out)+ low = "--resident-experts" in cfg["args"] or "--mmap-experts" in cfg["args"]+ self.assertEqual(low, setup.low_ram_wanted(model, ram, choice),+ f"{model} on {ram:.0f} GB of RAM, --low-ram {choice}: setup wrote {cfg['args']}")++if __name__ == "__main__":unittest.main()