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++

Fit rule for cards that are just short: lower context, reserve and prompt chunk until the start fits (Gyro-M on the 8 GB Arc A750)

Niko122134d7b2a3ba78
diff --git a/strata_cli/launch/adopt.py b/strata_cli/launch/adopt.py
index 0336b758f..83529fe2d 100644
--- a/strata_cli/launch/adopt.py
+++ b/strata_cli/launch/adopt.py
@@ -53,7 +53,7 @@ def find_shards(folder: Path) -> list[Path]:
def plan(*, family: str, model: str, model_dir: Path, data_dir: Path, src: Path, context: int, kv: str | None, model_name: str, family_def: dict,
- log: Path, backend: str | None) -> tuple[dict | None, list[str]]:
+ log: Path, backend: str | None, vram_gb: float = 0.0, notes: list | None = None) -> tuple[dict | None, list[str]]:
"""(config, problems): the config to write, or None with plain-words problems (what is missing)."""
problems: list[str] = []
if family not in FAMILIES:
@@ -89,6 +89,16 @@ def plan(*, family: str, model: str, model_dir: Path, data_dir: Path, src: Path,
# an Intel Arc, as sycl/setup_intel.py writes it: an A-series card on i915 loads the experts into a RAM arena and the CPU computes the misses
# (--ple-io ram); every other Arc (xe: the B70) streams the experts from the GGUF into VRAM (--stream-experts); both keep a VRAM reserve
reserve = "1024" if context <= 32768 else "2048"
+ if vram_gb: # 0.2.2: a card a few hundred MiB short gets a smaller context / reserve (vram_fit)
+ from strata_control import vram_fit
+ fr = vram_fit.plan(model, vram_gb, context, kv or "int8", int(reserve), "auto", "intel", title=model, ctx_fixed=True) # the context was settled by max_context or the person
+ if fr.changed:
+ args[args.index("--max-context") + 1] = str(fr.ctx)
+ reserve = str(fr.reserve_mib)
+ if fr.prefill:
+ args[args.index("--prefill") + 1] = fr.prefill
+ if notes is not None:
+ notes.append(fr.line)
if intel_driver() == "i915":
args += ["--ple-io", "ram", "--vram-reserve-mib", reserve]
else:
diff --git a/strata_cli/launch/catalog.py b/strata_cli/launch/catalog.py
index efd52685b..4d31076c4 100644
--- a/strata_cli/launch/catalog.py
+++ b/strata_cli/launch/catalog.py
@@ -387,6 +387,11 @@ class Catalog:
rec = min(rec, int(mod.ram_ctx(model, hw["ram_gb"], False)))
except Exception: # noqa: BLE001
pass
+ if usable: # 0.2.2: a model a few hundred MiB short on this card gets the next context down
+ from strata_control import vram_fit
+ best = max(usable, key=lambda g: float(g.get("vram_gb") or 0))
+ rec = vram_fit.fit_context(f"{family} {model}", float(best.get("vram_gb") or 0), rec, "int8", 300,
+ str(best.get("vendor") or ""))
return rec
# ---- pictures
diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.py
index ee0d1afe1..e318f567e 100644
--- a/strata_cli/launch/runner.py
+++ b/strata_cli/launch/runner.py
@@ -842,7 +842,8 @@ class Runner:
backend = None
cfg, problems = adopt.plan(family=s.family, model=s.model, model_dir=model_dir, data_dir=data_dir, src=cat.src,
context=s.context or 32768, kv=s.kv, model_name=f"{fam.get('name', s.family)}-{s.model.lower()}", family_def=fam,
- log=cat.root / f"strata-{tag}.log", backend=backend)
+ log=cat.root / f"strata-{tag}.log", backend=backend,
+ vram_gb=float(cat.computer().main_vram_gb or 0), notes=self.notices)
if cfg is None:
raise LaunchError("The installer cannot set up this graphics card yet, and the files Strata would need to write the settings itself are not all there: "
+ "; ".join(problems) + ".",
diff --git a/strata_control/vram_fit.py b/strata_control/vram_fit.py
new file mode 100644
index 000000000..7ae12dc26
--- /dev/null
+++ b/strata_control/vram_fit.py
@@ -0,0 +1,160 @@
+"""Will the default start fit the card? If it is just short, lower the context, the reserve and the prompt chunk until it does.
+
+Owner rule: fixes are automatic defaults, users never set flags. A model that is a few hundred MiB short of one expert-cache slot
+(Gyro-M on an 8 GB Arc A750: "no VRAM is left for the expert cache, about 744 MiB more than this card has free") must start on its own
+with a smaller context, never be refused. Pure functions, no I/O: sycl/setup_intel.py (setup), strata_cli/launch (strata launch and the
+app's recommended context) import it.
+
+The arithmetic (MiB), measured on the Arc A750 (8 GB, i915) with the SYCL engine of 0.2.2, Gyro-M and Gyro-S, 12 starts:
+
+ slack = card - gap - base - session(ctx) - head - reserve - prompt buffers(chunk) # what is left for the expert cache
+ fits = slack >= MIN_SLOTS * slot + MARGIN
+
+* gap: the part of the card the driver does not give (Arc: 471 MiB, the engine sees 7.54 GiB of 8; CUDA / HIP: the runtime's context, 250).
+* base: dense weights, the draft layer, the n-gram head's buffers and the engine's own allocations that do not depend on the context.
+ Gyro-M 5945 (measured "holds" 6.02 GiB at 8K minus the 234 MiB session), Gyro-S 4720; any other model: 2448 (1.4 GiB dense + 0.8 GiB
+ draft layer + slack), a figure that only a card under about 5 GB can get past, so a default that fits today is never changed.
+* session: 121 MiB + the KV cache. int8 KV measured 234 / 347 / 573 MiB at 8192 / 16384 / 32768 tokens (13.8 KiB per token).
+* head: the draft head (English subset) 110 MiB.
+* prompt buffers: 170 + 0.66 * chunk MiB, measured at chunks 256 .. 2048 (338 / 508 / 850 / 1525 MiB), independent of the context.
+ `--prefill auto` resolved to 2048 on that card.
+* slot: 1.243 MiB (0.50 GiB / 412 slots).
+
+Why these numbers and not the engine's own: the engine only finds out after it has loaded 30 GB of weights; setup has to choose before.
+It is an estimate; the engine still says what is short if it is off (and a user who asked for a context or a reserve keeps it).
+"""
+
+from __future__ import annotations
+
+from dataclasses import dataclass, field
+
+CTX_STEPS = (32768, 16384, 8192) # the ladder, biggest first: a context above 32K is never touched by this module
+CHUNK_STEPS = (1024,) # a smaller prompt chunk, tried after the default one (1024 is the value measured end to end)
+RESERVE_FLOOR_MIB = 100 # the lowest reserve the engine accepts without complaint (docs/INTEL.md); never raised
+AUTO_CHUNK = 2048 # what --prefill auto came to on the 8 GB card
+MIN_SLOTS = 128 # the engine wants 128 cache slots to lend the prompt path; below that it is slow
+SLOT_MIB = 1.243
+MARGIN_MIB = 64 # the estimate's error (the measurements agree to +-25 MiB)
+HEAD_MIB = 110
+SESSION_FIXED_MIB = 121
+KV_BYTES = {"fp16": 2112, "int8": 1056, "q4_0": 576, "k8v4": 816} # per token per attention layer (13) = setup.UD_FIT_KV_BYTES
+KV_MEASURED_FACTOR = 1.054 # the engine's session is 5.4% over the bare cache (scales)
+PROMPT_BASE_MIB = 170
+PROMPT_PER_TOKEN_MIB = 0.66
+GAP_MIB = {"intel": 471}
+GAP_OTHER_MIB = 250
+MIN_CARD_GB = 5.0 # under this nothing here is claimed (the engine lowers its own reserve there, #496)
+
+BASE_MIB = {"gyro-m": 5945, "gyro-s": 4720}
+BASE_GENERIC_MIB = 2448
+
+
+def base_mib(model: str) -> int:
+ low = str(model or "").lower().replace("_", "-")
+ for key, mib in BASE_MIB.items():
+ if key in low:
+ return mib
+ return BASE_GENERIC_MIB
+
+
+def known_model(model: str) -> bool:
+ low = str(model or "").lower().replace("_", "-")
+ return any(k in low for k in BASE_MIB)
+
+
+def session_mib(ctx: int, kv: str = "int8") -> float:
+ return SESSION_FIXED_MIB + ctx * 13 * KV_BYTES.get(kv, 1056) * KV_MEASURED_FACTOR / 2 ** 20
+
+
+def chunk_of(prefill) -> int:
+ """The prompt chunk in tokens: a number as given, `auto` (or nothing, or auto:N) is what auto came to on the 8 GB card."""
+ try:
+ return max(1, int(str(prefill)))
+ except (TypeError, ValueError):
+ return AUTO_CHUNK
+
+
+def slack_mib(model: str, vram_gb: float, ctx: int, kv: str = "int8", reserve_mib: int = 300, prefill="auto",
+ vendor: str = "intel") -> float:
+ """MiB the estimate leaves for the expert cache (negative: the engine would stop with "no VRAM is left for the expert cache")."""
+ gap = GAP_MIB.get(str(vendor or "").lower(), GAP_OTHER_MIB)
+ prompt = PROMPT_BASE_MIB + PROMPT_PER_TOKEN_MIB * chunk_of(prefill)
+ return (vram_gb * 1024 - gap - base_mib(model) - session_mib(ctx, kv) - HEAD_MIB - max(int(reserve_mib), 0) - prompt)
+
+
+def needed_mib() -> float:
+ return MIN_SLOTS * SLOT_MIB + MARGIN_MIB
+
+
+def fits(model: str, vram_gb: float, ctx: int, kv: str = "int8", reserve_mib: int = 300, prefill="auto", vendor: str = "intel") -> bool:
+ return slack_mib(model, vram_gb, ctx, kv, reserve_mib, prefill, vendor) >= needed_mib()
+
+
+def ctx_label(ctx: int) -> str:
+ return f"{ctx // 1024}K" if ctx % 1024 == 0 else f"{ctx} tokens"
+
+
+@dataclass
+class Fit:
+ ctx: int
+ reserve_mib: int
+ prefill: str | None = None # a new chunk size to write, or None to leave --prefill as it was
+ changed: bool = False
+ fits: bool = True
+ slack_mib: float = 0.0
+ line: str = "" # one plain sentence for the user, "" when nothing changed
+ changes: list = field(default_factory=list)
+
+
+def plan(model: str, vram_gb: float, ctx: int, kv: str = "int8", reserve_mib: int = 300, prefill="auto", vendor: str = "intel",
+ title: str = "", ctx_fixed: bool = False, reserve_fixed: bool = False, prefill_fixed: bool = False) -> Fit:
+ """The start that fits, as close to the one asked for as possible; the SAME values back when that one already fits (byte-identical).
+
+ Order of harm, mildest first: the context down the ladder 32K -> 16K -> 8K (the outer loop), at each step the prompt chunk (1024)
+ and then the reserve (down to RESERVE_FLOOR_MIB); a value the user chose (`*_fixed`) is not touched. Never refuses: when nothing on the
+ ladder fits, the smallest start is returned with fits=False and a line that says so."""
+ ctx = int(ctx)
+ reserve_mib = int(reserve_mib)
+ keep = Fit(ctx, reserve_mib, None, False, True, 0.0)
+ if not vram_gb or vram_gb < MIN_CARD_GB:
+ return keep
+ keep.slack_mib = slack_mib(model, vram_gb, ctx, kv, reserve_mib, prefill, vendor)
+ if keep.slack_mib >= needed_mib():
+ return keep
+ ctxs = [ctx] if ctx_fixed else [ctx] + [c for c in CTX_STEPS if c < ctx]
+ chunks = [prefill] if prefill_fixed else [prefill] + [c for c in CHUNK_STEPS if c < chunk_of(prefill)]
+ reserves = [reserve_mib] if reserve_fixed or reserve_mib <= RESERVE_FLOOR_MIB else [reserve_mib, RESERVE_FLOOR_MIB]
+ best = None
+ for c in ctxs:
+ for p in chunks:
+ for r in reserves:
+ s = slack_mib(model, vram_gb, c, kv, r, p, vendor)
+ best = (c, p, r, s)
+ if s >= needed_mib():
+ return _result(model, vram_gb, title, ctx, reserve_mib, prefill, c, p, r, s, True)
+ c, p, r, s = best
+ return _result(model, vram_gb, title, ctx, reserve_mib, prefill, c, p, r, s, False)
+
+
+def _result(model, vram_gb, title, ctx0, reserve0, prefill0, ctx, chunk, reserve, slack, ok) -> Fit:
+ changes = []
+ if ctx != ctx0:
+ changes.append(f"context set to {ctx_label(ctx)}")
+ if str(chunk) != str(prefill0):
+ changes.append(f"prompts read in chunks of {chunk}")
+ if reserve != reserve0:
+ changes.append(f"memory kept free for other programs {reserve} MiB")
+ name = title or "This model"
+ card = f"{vram_gb:.0f} GB card"
+ if ok:
+ line = f"{name} on this {card}: " + ", ".join(changes) + " so it fits"
+ else:
+ line = (f"{name} on this {card}: " + (", ".join(changes) + ", but " if changes else "")
+ + "it is still tight (the expert cache will get few slots); a smaller model or a card with more memory runs it better")
+ return Fit(ctx, reserve, str(chunk) if str(chunk) != str(prefill0) else None, bool(changes), ok, slack, line, changes)
+
+
+def fit_context(model: str, vram_gb: float, ctx: int, kv: str = "int8", reserve_mib: int = 300, vendor: str = "intel") -> int:
+ """The context to recommend: `ctx` when it fits (unchanged), else the biggest step of the ladder that does (the reserve and
+ chunk lowered the way plan() lowers them), else the smallest step."""
+ return plan(model, vram_gb, ctx, kv, reserve_mib, "auto", vendor).ctx
diff --git a/sycl/setup_intel.py b/sycl/setup_intel.py
index d7b66829c..420cb0f97 100644
--- a/sycl/setup_intel.py
+++ b/sycl/setup_intel.py
@@ -35,6 +35,7 @@ from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
import setup as S # noqa: E402
+from strata_control import vram_fit # noqa: E402
SYCL_WRAPPER = ROOT / "sycl" / "serve" / "strata-sycl.sh"
SYCL_IMAGE = "strata-sycl-dev"
@@ -254,14 +255,29 @@ def recommended_prefill(vram_gb: float, ctx: int, driver: str = "xe", devid: str
return 4096, ""
+def _model_title(model: str, args: list) -> str:
+ """The plain name for the fit line: Gyro-M / Gyro-S from the catalog name or the GGUF's file name, else the catalog name."""
+ low = (model + " " + (flag(args, "--native") or "")).lower()
+ for key, title in (("gyro-m", "Gyro-M"), ("gyro-s", "Gyro-S")):
+ if key in low:
+ return title
+ return model if model and "/" not in model and chr(92) not in model else ""
+
+
def to_sycl(cfg: dict, exe: Path, ram: float, keep: dict, vram_gb: float = 0.0, driver: str = "xe",
- devid: str = "") -> dict:
+ devid: str = "", fit_notes: list | None = None, model: str = "", ctx_asked: bool = False,
+ auto_reserve: bool = False, fit: bool = True) -> dict:
"""setup's config (written for its HIP path) -> the SYCL port's: the container's paths, experts streamed from the
GGUF into VRAM (--stream-experts: the engine reads them from the GGUF and keeps what does not fit in a pinned RAM
mirror; the VRAM reserve is the smallest that leaves the KV and the prompt buffers room - docs/INTEL.md), KV
streaming from 64K up when the RAM holds the KV (the B70 at 256K decodes at 40+ tok/s with it, 4-9 without).
A reserve the user asked for (--vram-reserve-mib) is kept.
+ 0.2.2: a model that does not fit the card at the default context (Gyro-M on the 8 GB A750 is ~750 MiB short of one cache
+ slot) gets a context down the ladder 32K -> 16K -> 8K, a smaller prompt chunk and a lower reserve until it does
+ (strata_control/vram_fit.py); one plain line per change goes to `fit_notes`. A config that fits comes back as it was.
+ `ctx_asked` / a reserve without `auto_reserve`: the user chose it, it is kept. `fit=False`: a layer split.
+
An Alchemist card (the A-series, i915 or xe) has no FP64 hardware, so its config carries the driver's FP64
emulation (a kernel on the sampled path declares double). On i915 (the A750) the experts load into a RAM arena
and the CPU computes the ones the card does not hold (--ple-io ram, STRATA_VERIFY_NO_HOST=0 - docs/INTEL.md,
@@ -290,13 +306,31 @@ def to_sycl(cfg: dict, exe: Path, ram: float, keep: dict, vram_gb: float = 0.0,
args[args.index(f) + 1] = sycl_path(path) + (f":{scale}" if scale else "")
ctx = int(flag(args, "--max-context") or 32768)
kv = flag(args, "--kv") or "int8"
- kv_ram = ctx * (13 * (576 if kv == "q4_0" else 1056)) / 1e9
- if kv != "k8v4" and ctx >= 65536 and ram >= kv_ram + 6:
- args += ["--kv-resident", "32768"]
asked_reserve = flag(args, "--vram-reserve-mib") # setup writes it only when the user gave it
drop(args, "--vram-reserve-mib", True)
reserve = asked_reserve or (str(SMALL_RESERVE_MIB) if small_card(vram_gb, driver) else
"1024" if ctx <= 32768 else "2048")
+ new_prefill = None
+ if fit and vram_gb:
+ pf = flag(args, "--prefill")
+ fr = vram_fit.plan(model or (flag(args, "--native") or ""), vram_gb, ctx, kv, int(reserve), pf or "auto", "intel",
+ title=_model_title(model, args), ctx_fixed=ctx_asked,
+ reserve_fixed=bool(asked_reserve) and not auto_reserve,
+ prefill_fixed=pf not in (None, "auto"))
+ if fr.changed:
+ if fr.ctx != ctx:
+ if "--max-context" in args:
+ args[args.index("--max-context") + 1] = str(fr.ctx)
+ else:
+ args += ["--max-context", str(fr.ctx)]
+ ctx = fr.ctx
+ reserve = str(fr.reserve_mib)
+ new_prefill = fr.prefill
+ if fit_notes is not None:
+ fit_notes.append(fr.line)
+ kv_ram = ctx * (13 * (576 if kv == "q4_0" else 1056)) / 1e9
+ if kv != "k8v4" and ctx >= 65536 and ram >= kv_ram + 6:
+ args += ["--kv-resident", "32768"]
alchemist = driver == "i915" or devid in ALCHEMIST_IDS
if driver == "i915":
# Arc A-series on i915 (the A750): the experts load into an ordinary RAM arena and the CPU computes the ones
@@ -317,6 +351,11 @@ def to_sycl(cfg: dict, exe: Path, ram: float, keep: dict, vram_gb: float = 0.0,
if flag(args, "--prefill") in (None, "auto", "2048", "4096", "8192"):
drop(args, "--prefill", True)
args += ["--prefill", str(recommended_prefill(vram_gb, ctx, driver, devid)[0])]
+ if new_prefill: # the fit rule's smaller prompt chunk (the card cannot spare 2048-token buffers)
+ if "--prefill" in args:
+ args[args.index("--prefill") + 1] = new_prefill
+ else:
+ args += ["--prefill", new_prefill]
out = {k: v for k, v in cfg.items() if k not in ("lib_dirs", "env", "gpus")} # "vision" stays: the CPU reader runs on the host
out.update({"backend": "sycl", "exe": str(SYCL_WRAPPER), "args": args, "sycl_root": str(MOUNT)})
env = {}
@@ -352,7 +391,10 @@ def install(argv) -> None:
S.fail(f"setup.py has no {name}() any more: sycl/setup_intel.py needs updating for this setup.py")
real_ram = S.ram_gb()
- keep = {} # hand-set keys setup does not write: kept across a rerun
+ # what the person chose on the command line is kept by the fit rule (vram_fit); the small-card reserve added below is not theirs
+ asked_ctx = any(a == "--context" or a.startswith("--context=") or a == "--max-context" for a in argv)
+ asked_reserve = any(a == "--vram-reserve-mib" or a.startswith("--vram-reserve-mib=") for a in argv)
+ keep = {} # hand-set keys setup does not write: kept across a rerun
for p in ROOT.glob("strata-*.json"):
try:
c = json.loads(p.read_text(encoding="utf-8-sig"))
@@ -433,8 +475,12 @@ def install(argv) -> None:
split = isinstance(gsel, list)
idx = gsel if isinstance(gsel, int) and 0 <= gsel < len(intel) else 0
sel = intel[idx]
+ fit_notes = []
cfg = to_sycl(cfg, exe, real_ram, keep.get(Path(cfg_path).name, {}), sel["vram_gb"], sel["driver"],
- sel.get("devid", ""))
+ sel.get("devid", ""), fit_notes=fit_notes, model=model, ctx_asked=asked_ctx,
+ auto_reserve=not asked_reserve, fit=not split)
+ for line in fit_notes: # one plain line: what was chosen and why (never a refusal)
+ S.say(" " + line)
if len(intel) > 1: # pin the SYCL device(s)
# the Level Zero order followed the sysfs card order on the tested machines; a machine where it does not
# needs an explicit ONEAPI_DEVICE_SELECTOR (kept if the user set one)
diff --git a/tests/terminal/test_vram_fit.py b/tests/terminal/test_vram_fit.py
new file mode 100644
index 000000000..6b84b2c93
--- /dev/null
+++ b/tests/terminal/test_vram_fit.py
@@ -0,0 +1,152 @@
+"""strata_control/vram_fit.py: the fit math with mock card sizes, and its use in setup (sycl/setup_intel.py) and strata launch."""
+
+from __future__ import annotations
+
+import importlib.util
+import sys
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+sys.path.insert(0, str(ROOT))
+
+from strata_control import vram_fit as V # noqa: E402
+
+
+class Measured(unittest.TestCase):
+ """The estimate against the 12 starts on the Arc A750 (8 GB): engine slots / MiB short, from /data/022-arcgyro/out/fa_*.txt."""
+
+ def slack(self, ctx, reserve, prefill):
+ return V.slack_mib("Gyro-M", 8.0, ctx, "int8", reserve, prefill, "intel")
+
+ def test_the_session_matches_the_engines_three_numbers(self):
+ for ctx, mib in ((8192, 234), (16384, 347), (32768, 573)):
+ self.assertAlmostEqual(V.session_mib(ctx), mib, delta=8)
+
+ def test_the_default_does_not_start_and_the_estimate_says_how_short(self):
+ self.assertAlmostEqual(self.slack(32768, 300, "auto"), -747, delta=40) # engine: about 748 MiB more
+ self.assertAlmostEqual(self.slack(16384, 300, "auto"), -497, delta=40) # 497
+ self.assertAlmostEqual(self.slack(8192, 100, "auto"), -171, delta=40) # 171
+
+ def test_the_known_good_start_has_room_for_its_slots(self):
+ self.assertAlmostEqual(self.slack(8192, 100, 1024), 412 * V.SLOT_MIB, delta=60) # 412 slots
+ self.assertAlmostEqual(self.slack(32768, 100, 1024), 107 * V.SLOT_MIB, delta=60) # 107 slots
+ self.assertAlmostEqual(self.slack(8192, 100, 512), 683 * V.SLOT_MIB, delta=60) # 683 slots
+ self.assertAlmostEqual(self.slack(8192, 100, 256), 820 * V.SLOT_MIB, delta=60) # 820 slots
+
+ def test_gyro_s_default_fits_as_it_did(self):
+ self.assertTrue(V.fits("Gyro-S", 8.0, 32768, "int8", 300, "auto", "intel")) # 410 slots measured
+
+
+class Plan(unittest.TestCase):
+ def test_gyro_m_on_8gb_is_lowered_until_it_fits_and_says_so(self):
+ f = V.plan("Gyro-M", 8.0, 32768, "int8", 300, "auto", "intel", title="Gyro-M")
+ self.assertTrue(f.changed and f.fits)
+ self.assertEqual((f.ctx, f.reserve_mib, f.prefill), (16384, 100, "1024"))
+ self.assertTrue(f.line.startswith("Gyro-M on this 8 GB card: context set to 16K"), f.line)
+ self.assertTrue(f.line.endswith("so it fits"))
+ self.assertGreaterEqual(f.slack_mib, V.needed_mib())
+
+ def test_a_chosen_context_is_kept_and_the_rest_is_lowered(self):
+ f = V.plan("Gyro-M", 8.0, 32768, "int8", 300, "auto", "intel", ctx_fixed=True)
+ self.assertEqual(f.ctx, 32768)
+ self.assertFalse(f.fits) # 32K cannot fit even with 100 / 512: said, not refused
+ self.assertIn("still tight", f.line)
+
+ def test_a_chosen_reserve_is_kept(self):
+ f = V.plan("Gyro-M", 8.0, 32768, "int8", 500, "auto", "intel", reserve_fixed=True)
+ self.assertEqual(f.reserve_mib, 500)
+ self.assertLess(f.ctx, 32768)
+
+ def test_a_chosen_chunk_is_kept(self):
+ f = V.plan("Gyro-M", 8.0, 32768, "int8", 300, "2048", "intel", prefill_fixed=True)
+ self.assertIsNone(f.prefill)
+
+ def test_the_smallest_start_is_returned_when_nothing_fits_never_a_refusal(self):
+ f = V.plan("Gyro-M", 6.0, 32768, "int8", 300, "auto", "intel")
+ self.assertEqual(f.ctx, 8192)
+ self.assertFalse(f.fits)
+ self.assertTrue(f.line)
+
+ def test_only_the_ladder_is_used(self):
+ for gb in (7.0, 7.5, 8.0, 8.5, 9.0, 10.0):
+ f = V.plan("Gyro-M", gb, 32768, "int8", 300, "auto", "intel")
+ self.assertIn(f.ctx, (32768, 16384, 8192))
+
+ def test_a_config_that_fits_comes_back_unchanged(self):
+ for model, gb, ctx in (("Gyro-M", 12.0, 32768), ("Gyro-M", 16.0, 65536), ("Gyro-S", 8.0, 32768), ("Gyro-S", 12.0, 131072),
+ ("Qwen3.8-Flash-Next-IQ3_XXS", 8.0, 32768), ("Qwen3.8-Flash-Next-IQ3_XXS", 12.0, 131072),
+ ("Qwen3.8-Flash-Next-IQ3_XXS", 16.0, 262144), ("Qwen3.8-Flash-Next-IQ2_XS", 24.0, 262144)):
+ f = V.plan(model, gb, ctx, "int8", 300, "auto", "nvidia")
+ self.assertEqual((f.ctx, f.reserve_mib, f.prefill, f.changed, f.line), (ctx, 300, None, False, ""), (model, gb, ctx))
+
+ def test_unknown_card_size_and_tiny_cards_are_left_alone(self):
+ for gb in (0, None, 4.0):
+ f = V.plan("Gyro-M", gb, 32768, "int8", 300, "auto", "intel")
+ self.assertFalse(f.changed)
+
+ def test_fit_context_is_the_ladder_step(self):
+ self.assertEqual(V.fit_context("Gyro-M", 8.0, 32768), 16384)
+ self.assertEqual(V.fit_context("Gyro-M", 12.0, 32768), 32768)
+ self.assertEqual(V.fit_context("Gyro-M", 8.0, 8192), 8192)
+
+ def test_generic_model_is_found_short_only_when_far_short(self):
+ self.assertFalse(V.plan("Qwen3.8-Flash-Next-IQ3_XXS", 8.0, 32768, "int8", 300, "auto", "intel").changed)
+ self.assertTrue(V.plan("Qwen3.8-Flash-Next-IQ3_XXS", 6.0, 131072, "int8", 300, "auto", "intel").changed)
+
+
+class SetupIntel(unittest.TestCase):
+ @staticmethod
+ def mod():
+ spec = importlib.util.spec_from_file_location("setup_intel_fit", ROOT / "sycl" / "setup_intel.py")
+ m = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(m)
+ return m
+
+ def cfg(self, m, native="Gyro-M-TQ2_0.gguf", extra=()):
+ base = m.MOUNT
+ return {"exe": "x", "cwd": "y", "args": ["--pack", str(base / "d" / "pack"), "--native", str(base / "d" / native),
+ "--expert-cache", "auto", "--prefill", "auto", "--max-context", "32768",
+ "--kv", "int8", "--vram-reserve-mib", "300", *extra]}
+
+ def val(self, c, flag):
+ return c["args"][c["args"].index(flag) + 1]
+
+ def run_it(self, m, cfg, vram, drv="i915", **kw):
+ notes = []
+ c = m.to_sycl(cfg, m.ROOT / "build-sycl" / "strata", 64.0, {}, vram, drv, "56a1", fit_notes=notes, **kw)
+ return c, notes
+
+ def test_gyro_m_on_the_a750_gets_a_config_that_starts_and_one_line(self):
+ m = self.mod()
+ c, notes = self.run_it(m, self.cfg(m), 8.0, auto_reserve=True)
+ self.assertEqual(self.val(c, "--max-context"), "16384")
+ self.assertEqual(self.val(c, "--vram-reserve-mib"), "100")
+ self.assertEqual(self.val(c, "--prefill"), "1024")
+ self.assertEqual(c["args"].count("--vram-reserve-mib"), 1)
+ self.assertEqual(len(notes), 1)
+ self.assertIn("Gyro-M on this 8 GB card: context set to 16K", notes[0])
+
+ def test_a_reserve_the_user_asked_for_is_kept(self):
+ m = self.mod()
+ c, notes = self.run_it(m, self.cfg(m), 8.0, auto_reserve=False)
+ self.assertEqual(self.val(c, "--vram-reserve-mib"), "300")
+ self.assertIn(self.val(c, "--max-context"), ("16384", "8192"))
+
+ def test_a_context_the_user_asked_for_is_kept(self):
+ m = self.mod()
+ c, notes = self.run_it(m, self.cfg(m), 8.0, auto_reserve=True, ctx_asked=True)
+ self.assertEqual(self.val(c, "--max-context"), "32768")
+
+ def test_configs_that_fit_are_byte_identical(self):
+ m = self.mod()
+ for vram, drv in ((8.0, "i915"), (12.0, "xe"), (16.0, "i915"), (24.0, "xe"), (32.0, "xe")):
+ for native in ("a.gguf", "Gyro-S-TQ1_0.gguf"):
+ off, _ = self.run_it(m, self.cfg(m, native), vram, drv, fit=False)
+ on, notes = self.run_it(m, self.cfg(m, native), vram, drv, auto_reserve=True)
+ self.assertEqual(off, on, (vram, drv, native))
+ self.assertEqual(notes, [])
+
+
+if __name__ == "__main__":
+ unittest.main()