Skip to content

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-* on a card of about 8 GB - estimate the VRAM the engine needs, write the least harmful config that starts (4-bit KV, smaller context, then no draft layer on the GPU), say so, warn that UD-Q4 is very slow there and suggest IQ3_XXS / IQ3_S; tests

Niko1221caac711395dc
diff --git a/setup.py b/setup.py
index e2dd0a199..aac1bc1b8 100644
--- a/setup.py
+++ b/setup.py
@@ -5072,6 +5072,64 @@ def small_card_note(ctx: int, draft_vocab: str | None) -> list[str]:
return lines
+# Unsloth's files on a card of about 8 GB. The dense side is Q8_0 (~3 GB) and the draft layer binds ~0.8 GB, so little is
+# left for the expert cache. Measured on an 8 GB Arc A750 (the Intel worker, 2026-10-13): setup's 8192 / int8 / reserve 400
+# start stopped with "no VRAM is left for the expert cache, short 473 MiB"; --max-context 4608 --kv q4_0 --vram-reserve-mib 0
+# started with 3 cache slots (4.4 tok/s). UD_FIT_FIXED_MIB is that measurement turned into a constant (everything but the
+# session's KV, the reserve and the draft layer); an ESTIMATE for CUDA and HIP cards of the same size, whose engine says what
+# is short if it is off. The engine itself lowers its default reserve to 300 MiB on such a card.
+UD_FIT_FIXED_MIB = 7356
+UD_FIT_MTP_MIB = 802
+UD_FIT_MIN_SLACK_MIB = 64 # at least a few cache slots beside the estimate's error
+UD_FIT_CARD_GB = 9.5 # the check is for cards up to here
+UD_FIT_RUNTIME_MIB = 250 # CUDA / HIP: the runtime's own context (the SYCL measurement above has none of it)
+UD_FIT_ENGINE_RESERVE_MIB = 300 # the reserve the engine settles on when none is given and the card is tight
+UD_FIT_KV_BYTES = {"fp16": 2112, "int8": 1056, "q4_0": 576, "k8v4": 816} # per token per attention layer (13)
+UD_FIT_CTX_STEPS = (8192, 6144, 4608)
+
+
+def unsloth_runtime_mib(gpu: dict) -> int:
+ return 0 if (gpu or {}).get("driver") in ("xe", "i915") else UD_FIT_RUNTIME_MIB
+
+
+def unsloth_vram_slack_mib(vram_gb: float, ctx: int, kv: str, reserve_mib: int, mtp: bool = True,
+ runtime_mib: int = 0) -> float:
+ """MiB left for the expert cache by setup's estimate (negative: the engine would refuse to start)."""
+ session = ctx * 13 * UD_FIT_KV_BYTES.get(kv, 1056) / 2 ** 20
+ return vram_gb * 1024 - UD_FIT_FIXED_MIB - (UD_FIT_MTP_MIB if mtp else 0) - session - max(reserve_mib, 0) - runtime_mib
+
+
+def unsloth_small_card_plan(vram_gb: float, ctx: int, kv: str, reserve_mib: int | None, ctx_fixed=False, kv_fixed=False,
+ runtime_mib: int = 0):
+ """(ctx, kv, mtp, slack_mib) of the least harmful start that the estimate says fits, or None when none does.
+ Order of harm: the KV in 4 bits, then a smaller context (down to 4608), then no draft layer on the GPU (decode
+ up to 2x slower, but 0.8 GB for the cache); a value the user chose (--context, --kv) is not changed."""
+ reserve = UD_FIT_ENGINE_RESERVE_MIB if reserve_mib is None else reserve_mib
+ ctxs = [ctx] if ctx_fixed else [ctx] + [c for c in UD_FIT_CTX_STEPS if c < ctx]
+ kvs = [kv] if kv_fixed or kv == "q4_0" else [kv, "q4_0"]
+ for mtp in (True, False):
+ for c in ctxs:
+ for k in kvs:
+ slack = unsloth_vram_slack_mib(vram_gb, c, k, reserve, mtp, runtime_mib)
+ if slack >= UD_FIT_MIN_SLACK_MIB:
+ return c, k, mtp, slack
+ return None
+
+
+def unsloth_small_card_lines(model: str, vram_gb: float, plan, start_ok: bool) -> list[str]:
+ """The words for a ~8 GB card: that UD-* is very slow here and what to pick instead (always), and when the start
+ would have stopped, that and what setup changed instead. Recommend, never force."""
+ lines = [f"{model} on a {vram_gb:.0f} GB card is very slow: the dense side and the draft layer fill the card, the expert "
+ "cache gets a few slots, and nearly every expert comes from RAM or the SSD (3-5 tok/s measured on an 8 GB "
+ "Arc A750). IQ3_XXS or IQ3_S of the Qwen3.8-Flash-Next family fit such a card far better; run setup again "
+ "and pick one of them."]
+ if not start_ok and plan is None:
+ lines.append("By setup's estimate even a 4608 context with a 4-bit KV cache and no draft layer leaves no room "
+ "for the expert cache on this card: the start will probably stop with \"no VRAM is left for the "
+ "expert cache\".")
+ return lines
+
+
PARALLEL_MAX = 8 # #465: the engine's batch window holds at most 8 requests
PARALLEL_SHARE = 0.2 # #465: the slots' sessions may take this share of the VRAM the expert cache would hold
PARALLEL_HELD = 0.5 # #465: ... and only where the cache still holds this share of the experts beside them
@@ -6589,6 +6647,42 @@ def main() -> int:
args += ["--vram-reserve-mib", str(a.vram_reserve_mib)]
ok(f"VRAM kept free for other programs: {a.vram_reserve_mib} MiB (--vram-reserve-mib; the expert cache takes "
"that much less)")
+ if not multi and family == "unsloth" and 0 < gpu.get("vram_gb", 0.0) <= UD_FIT_CARD_GB:
+ # a card of about 8 GB: the config setup would write may not start (measured on an A750). Pick the least
+ # harmful one that fits and say so; what the user chose with --context / --kv / --vram-reserve-mib is kept
+ res_arg = int(args[args.index("--vram-reserve-mib") + 1]) if "--vram-reserve-mib" in args[:-1] else None
+ vg = gpu["vram_gb"]
+ rt_mib = unsloth_runtime_mib(gpu)
+ fits = unsloth_vram_slack_mib(vg, ctx, kv, UD_FIT_ENGINE_RESERVE_MIB if res_arg is None else res_arg, True,
+ rt_mib) >= UD_FIT_MIN_SLACK_MIB
+ plan = None
+ if not fits:
+ plan = unsloth_small_card_plan(vg, ctx, kv, res_arg, ctx_fixed=bool(a.context), kv_fixed=bool(a.kv),
+ runtime_mib=rt_mib)
+ if plan is not None:
+ nctx, nkv, nmtp, slack = plan
+ changes = []
+ if nctx != ctx:
+ args[args.index("--max-context") + 1] = str(nctx)
+ changes.append(f"context {ctx} -> {nctx}")
+ ctx = nctx
+ if nkv != kv:
+ if "--kv" in args[:-1]:
+ args[args.index("--kv") + 1] = nkv
+ else:
+ args += ["--kv", nkv]
+ changes.append(f"KV cache {kv} -> {nkv}")
+ kv = nkv
+ if not nmtp and "--mtp" in args[:-1]:
+ i = args.index("--mtp")
+ del args[i:i + 2]
+ changes.append("no MTP draft layer on the GPU (about 0.8 GB more for the expert cache; decode is slower)")
+ warn(f"with the usual settings {model} would not start on this {vg:.0f} GB card (setup's estimate: no VRAM "
+ "left for the expert cache). Setup chose the least harmful start that fits: " + ", ".join(changes)
+ + ". A bigger context, 8-bit KV or the draft layer need a card with more VRAM (or "
+ "--vram-reserve-mib 0, which leaves nothing for other programs).")
+ for line in unsloth_small_card_lines(model, vg, plan, fits):
+ warn(line)
if not multi and 0 < gpu.get("vram_gb", 0.0) < SMALL_CARD_GB:
# #496: on a 6 GB card the expert cache can get no room at all; the engine lowers its own reserve when that
# is what it takes, and says what is short when even that is not enough. Setup only says what helps.
diff --git a/tools/test_setup_small_card.py b/tools/test_setup_small_card.py
new file mode 100644
index 000000000..b63ba63e4
--- /dev/null
+++ b/tools/test_setup_small_card.py
@@ -0,0 +1,131 @@
+"""Tests for setup's UD-* start on a card of about 8 GB (0.1.44): the VRAM estimate, the plan that picks the least harmful
+config that starts, and the words (UD-Q4 is slow here: pick IQ3_XXS / IQ3_S). Measured on an 8 GB Arc A750: setup's
+8192 / int8 / reserve 400 start stopped with "no VRAM is left for the expert cache, short 473 MiB".
+
+ python -m unittest tools.test_setup_small_card
+"""
+from __future__ import annotations
+
+import sys
+import unittest
+from pathlib import Path
+from unittest import mock
+
+ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT))
+sys.path.insert(0, str(ROOT / "tools"))
+import setup # noqa: E402
+from test_setup_unsloth import Base # noqa: E402
+
+
+class Estimate(unittest.TestCase):
+ def test_the_a750_measurement(self):
+ # 8192 / int8 / reserve 400 was 473 MiB short; 4608 / q4_0 / reserve 0 started (without the draft layer's slack)
+ self.assertAlmostEqual(setup.unsloth_vram_slack_mib(8.0, 8192, "int8", 400), -473, delta=2)
+ self.assertGreaterEqual(setup.unsloth_vram_slack_mib(8.0, 4608, "q4_0", 0), 0)
+
+ def test_a_bigger_card_has_room(self):
+ self.assertGreater(setup.unsloth_vram_slack_mib(12.0, 32768, "int8", 700), setup.UD_FIT_MIN_SLACK_MIB)
+
+ def test_cuda_and_hip_pay_for_the_runtime_sycl_does_not(self):
+ self.assertEqual(setup.unsloth_runtime_mib({"driver": "i915"}), 0)
+ self.assertEqual(setup.unsloth_runtime_mib({"driver": "xe"}), 0)
+ self.assertEqual(setup.unsloth_runtime_mib({"driver": "580.97"}), setup.UD_FIT_RUNTIME_MIB)
+ self.assertEqual(setup.unsloth_runtime_mib({"driver": "amdgpu"}), setup.UD_FIT_RUNTIME_MIB)
+
+
+class Plan(unittest.TestCase):
+ def test_a_card_that_fits_is_not_changed(self):
+ self.assertEqual(setup.unsloth_small_card_plan(10.0, 8192, "fp16", None)[:3], (8192, "fp16", True))
+
+ def test_8gb_drops_the_draft_layer_first(self):
+ # nothing else frees enough on 8 GB: the context and the KV alone do not fit with the draft layer
+ for kv in ("fp16", "int8"):
+ plan = setup.unsloth_small_card_plan(8.0, 8192, kv, 300)
+ self.assertIsNotNone(plan)
+ self.assertFalse(plan[2])
+ self.assertEqual(plan[:2], (8192, kv)) # the context and the KV the user would get are kept
+ self.assertGreaterEqual(plan[3], setup.UD_FIT_MIN_SLACK_MIB)
+
+ def test_a_card_just_short_changes_the_kv_before_the_context_before_the_draft(self):
+ # ~8.9 GB: the 4-bit KV is enough with the draft layer
+ vg = (setup.UD_FIT_FIXED_MIB + setup.UD_FIT_MTP_MIB + 8192 * 13 * 576 / 2 ** 20 + 300 + 80) / 1024
+ plan = setup.unsloth_small_card_plan(vg, 8192, "fp16", 300)
+ self.assertEqual(plan[:3], (8192, "q4_0", True))
+ # ... and a smaller context when the user fixed the KV
+ vg = (setup.UD_FIT_FIXED_MIB + setup.UD_FIT_MTP_MIB + 4608 * 13 * 2112 / 2 ** 20 + 300 + 80) / 1024
+ plan = setup.unsloth_small_card_plan(vg, 8192, "fp16", 300, kv_fixed=True)
+ self.assertEqual(plan[:3], (4608, "fp16", True))
+
+ def test_what_the_user_chose_is_not_changed(self):
+ plan = setup.unsloth_small_card_plan(8.0, 32768, "int8", 300, ctx_fixed=True, kv_fixed=True)
+ self.assertEqual(plan[:2], (32768, "int8"))
+
+ def test_a_6gb_card_has_no_plan(self):
+ self.assertIsNone(setup.unsloth_small_card_plan(6.0, 8192, "int8", None))
+
+ def test_a_reserve_the_user_gave_is_counted(self):
+ a = setup.unsloth_small_card_plan(8.0, 8192, "int8", 0)
+ b = setup.unsloth_small_card_plan(8.0, 8192, "int8", 1500)
+ self.assertGreater(a[3], b[3] if b else -1e9)
+
+
+class Words(unittest.TestCase):
+ def test_always_says_to_pick_iq3(self):
+ lines = setup.unsloth_small_card_lines("UD-Q4_K_XL", 8.0, (8192, "int8", False, 400.0), False)
+ text = " ".join(lines)
+ self.assertIn("very slow", text)
+ self.assertIn("IQ3_XXS or IQ3_S", text)
+
+ def test_no_plan_says_the_start_will_probably_stop(self):
+ lines = setup.unsloth_small_card_lines("UD-Q4_K_XL", 6.0, None, False)
+ self.assertTrue(any("will probably" in x for x in lines))
+
+
+class Main8GB(Base):
+ """setup.main() for UD-Q4_K_XL on an 8 GB NVIDIA card: the written config is the one that starts."""
+
+ def arg(self, cfg, name):
+ return cfg["args"][cfg["args"].index(name) + 1]
+
+ def test_nvidia_8gb_writes_a_config_that_fits_and_says_so(self):
+ code, out, cfg = self.main(["--context", "8192"], vram=8.0)
+ self.assertEqual(code, 0, out)
+ self.assertNotIn("--mtp", cfg["args"]) # no draft layer on the GPU
+ self.assertEqual(self.arg(cfg, "--max-context"), "8192") # the context the user asked for
+ self.assertIn("would not start on this 8 GB card", out)
+ self.assertIn("no MTP draft layer", out)
+ self.assertIn("IQ3_XXS or IQ3_S", out)
+ self.assertIn("very slow", out)
+
+ def test_a_context_and_kv_the_user_chose_are_kept(self):
+ code, out, cfg = self.main(["--context", "16384", "--kv", "int8"], vram=8.0)
+ self.assertEqual(code, 0, out)
+ self.assertEqual(self.arg(cfg, "--max-context"), "16384")
+ self.assertEqual(self.arg(cfg, "--kv"), "int8")
+
+ def test_the_default_context_on_8gb_starts_without_asking(self):
+ code, out, cfg = self.main([], vram=8.0)
+ self.assertEqual(code, 0, out)
+ self.assertEqual(self.arg(cfg, "--max-context"), "8192")
+ self.assertNotIn("--mtp", cfg["args"])
+
+ def test_a_12gb_card_is_untouched(self):
+ code, out, cfg = self.main(["--context", "8192"], vram=11.9)
+ self.assertEqual(code, 0, out)
+ self.assertIn("--mtp", cfg["args"])
+ self.assertNotIn("would not start", out)
+ self.assertNotIn("very slow", out)
+
+ def test_amd_8gb(self):
+ r = [{"index": 0, "name": "AMD Radeon RX 7600", "vram_gb": 8.0, "arch": "gfx1102", "driver": "amdgpu"}]
+ with mock.patch.object(setup, "get_prebuilt_hip", lambda *a, **k: self.t / "engine"), \
+ mock.patch.object(setup, "build_engine_hip", lambda *a, **k: self.t / "engine"), mock.patch.object(setup, "hip_card", lambda eng, gpu, listed: gpu):
+ code, out, cfg = self.main(["--context", "8192", "--backend", "hip", "--vision", "no"], amd=r)
+ self.assertEqual(code, 0, out)
+ self.assertNotIn("--mtp", cfg["args"])
+ self.assertIn("IQ3_XXS or IQ3_S", out)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/test_setup_unsloth.py b/tools/test_setup_unsloth.py
index 89d11b5c2..775794851 100644
--- a/tools/test_setup_unsloth.py
+++ b/tools/test_setup_unsloth.py
@@ -148,7 +148,7 @@ class Base(unittest.TestCase):
self.tmp.cleanup()
def main(self, argv, ram=63.7, version="0.1.32", n_gpus=1, model=True, amd=(), free=500.0, m=M, answers=None,
- family=True):
+ family=True, vram=11.9):
"""answers: None = --yes; else {words of a question: its answer} (Enter for the others), and every question
asked is kept in self.asked. family=False: no --family (the first menu is shown)."""
self.asked = []
@@ -162,7 +162,7 @@ class Base(unittest.TestCase):
eng = self.t / "engine"
eng.mkdir(exist_ok=True)
(eng / "BUILD.json").write_text(json.dumps({"version": version, "source": "local"}))
- found = [{"index": i, "name": "NVIDIA GeForce RTX 5070", "vram_gb": 11.9, "arch": "120", "driver": "580.97"}
+ found = [{"index": i, "name": "NVIDIA GeForce RTX 5070", "vram_gb": vram, "arch": "120", "driver": "580.97"}
for i in range(n_gpus)]
def fake_download(url, dst, what=None):