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

DeepSeek-V4.1-Flash in the catalog, setup and strata launch

Niko1221f7c645c06541
diff --git a/setup.py b/setup.py
index af4d1e340..6f7eb0c0a 100644
--- a/setup.py
+++ b/setup.py
@@ -95,6 +95,7 @@ HF_REVISIONS = {
"unsloth/Qwen3.8-Flash-Next-GGUF": "38bb39ee97821de2c9009abb7e93950eec396e66", # 2026-09-30
"unsloth/Qwen3.6-35B-A3B-MTP-GGUF": "5bc3e238d916f48a861bac2f8a1990a0e9b7e98d", # 2026-10-12
"agentionai/Qwen3.8-Flash-Next-Gyro-GGUF": "1ada08422e404aca51ab9df665f089f34c419c6b", # 2026-10-13
+ "unsloth/DeepSeek-V4.1-Flash-1017-GGUF": "f924b94f19c1fea02c06a65c8475b0a45e2b88b1", # 2026-10-20 (the port's reference)
}
@@ -650,6 +651,42 @@ OWN_PATH_FAMILIES = {
}
PREVIEW_FAMILIES = OWN_PATH_FAMILIES # the earlier name (tools and tests that import it)
+# DeepSeek-V4.1-Flash (GGUF architecture deepseek41), Unsloth's UD-Q8_K_XL at the revision the port was checked against: a
+# family with an engine of its own (strata-dsv41, src/dsv41, ported from Project Maya's maya-ds4, MIT) that is not a
+# Flash-Next pack and not a single GGUF: nine shards (508.4 GB, the routed experts as MXFP4, the dense weights in BF16, and
+# in shard 8 the 202.8 GB n-gram table that stays on the SSD), the engine's pack folder (tools/dsv41/pack_gguf.py: hash
+# tables, tensor map, the tokenizer and the GGUF's own chat template, a few MB) beside them. MULTI_FILE_FAMILIES, offered
+# in the same menu and installed by install_dsv41. Where it fits: strata_control/dsv41_fit.py (real numbers). The DSpark
+# drafter (dspark-...-Q8_0.gguf, 8.0 GB) and the picture reader (mmproj-BF16.gguf, 1.0 GB) are pinned here but not fetched: the
+# engine does not use them yet.
+DSV41_REPO = "unsloth/DeepSeek-V4.1-Flash-1017-GGUF"
+DSV41_SHARD = "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-{i:05d}-of-00009.gguf"
+DSV41_FILES = {
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00001-of-00009.gguf": (5780589, "cc15d470afcb030558bbc4d8e2ccd840182e2e95de1a95198138efe63a5fd99f"),
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00002-of-00009.gguf": (50536121984, "9cb2047676bd20e448be2377b480080c97fb38fae117f4846e07de2c65bb8522"),
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00003-of-00009.gguf": (50536121984, "17d398dd327e7ff1991b382677814db75d970b074661757564b6f2ac3d0c8d95"),
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00004-of-00009.gguf": (50536122016, "7ea8da1143b9a6bf1424a361eb1b0d6f66c7ce79eac9711162f212cc4f39c319"),
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00005-of-00009.gguf": (50536122016, "1952da19a841176b46f9681c99ea57c674f8a8861e16d76fb35cec4befe039b2"),
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00006-of-00009.gguf": (50536122016, "d6711781d8effab79b410af9c40920bffcc0c28976e509bc1227ff0c6669c33a"),
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00007-of-00009.gguf": (36097230048, "2ebc8d198d03a14865e8a85df637285ceb5dd79b1ffc78424bd3c3e06df57823"),
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00008-of-00009.gguf": (202758032592, "12df293355efbd104b088a77e13ee22410fb1ec3f7ab3863947f09896e64bec7"),
+ "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00009-of-00009.gguf": (16835109952, "df33722d1dcf5ffe0347ed8406f7acb3b18061f4ded2c13c2b0a184b8d41c9ea"),
+ "dspark-DeepSeek-V4.1-Flash-1017-Q8_0.gguf": (7976914240, "6ba6ac1b331c540691a209e7fc97dec2a24e295acb1e755c84c7d24a4373927a"),
+ "mmproj-BF16.gguf": (972208288, "9a1ef7c40d0d702c7ed8c5f863f60abae64091387ba3fce0ad19ce9beeda3bf9"),
+}
+DSV41_CONTEXT = 8192 # the context the engine was checked at (4096 and 8192; 64K is not tried yet)
+MULTI_FILE_FAMILIES = {
+ "deepseek41": {"title": "DeepSeek-V4.1-Flash", "by": "DeepSeek; GGUFs by Unsloth", "arch": "deepseek41",
+ "about": "40 layers of 384 experts (6 used for each word) and a 203 GB n-gram table: a 508 GB download that "
+ "runs on several graphics cards with the experts they cannot hold computed on the CPU",
+ "hf": hf(DSV41_REPO) + "UD-Q8_K_XL/", "tag": "deepseek-v4.1-flash-", "name": "deepseek-v4.1-flash",
+ "license": "DeepSeek's model license: https://huggingface.co/unsloth/DeepSeek-V4.1-Flash-1017-GGUF",
+ "models": {"UD-Q8_K_XL": {"about": "Unsloth Dynamic 8-bit: the experts in MXFP4 as DeepSeek made them, the rest "
+ "in BF16 (the checkpoint's own precision)",
+ "ram_gb": 306, "shards": [DSV41_SHARD.format(i=i) for i in range(1, 10)]}},
+ "sha256": DSV41_FILES, "vision": False}
+}
+
# Every model file Strata downloads has a fixed size and SHA-256: (repository, file name) -> (bytes, sha256). download()
# checks the file against it as soon as it is whole (a wrong file is deleted and setup stops), and stops before the
# download when the server's size is not the pinned one. The files are fetched from the commits in HF_REVISIONS.
@@ -660,6 +697,7 @@ REPO_PINS = {
"unsloth/Qwen3.8-Flash-Next-GGUF": {**UNSLOTH_SHARDS, **UNSLOTH_IQ4_XS_SHARDS, **UNSLOTH_BIG_SHARDS},
"unsloth/Qwen3.6-35B-A3B-MTP-GGUF": QWEN36_FILES,
"agentionai/Qwen3.8-Flash-Next-Gyro-GGUF": GYRO_FILES,
+ "unsloth/DeepSeek-V4.1-Flash-1017-GGUF": DSV41_FILES,
}
# EXPERIMENTAL, off by default (setup asks): a control vector shipped with the repository, see its README
ESP_VECTOR = ROOT / "data" / "experimental-speed-projection" / "Qwen3.8-Flash-Next-experimental-speed-projection.gguf"
@@ -5842,6 +5880,15 @@ def choices_from_config(cfg_path: Path) -> dict:
"""The setup answers a config was written with (family, size, context, KV, images, projection, network)."""
cfg = json.loads(cfg_path.read_text(encoding="utf-8-sig"))
tag = cfg_path.stem[len("strata-"):]
+ big = next((f for f, d in MULTI_FILE_FAMILIES.items() if tag.startswith(d["tag"])), None)
+ if big is not None: # DeepSeek-V4.1-Flash: its own size; no KV / images / projection settings
+ d = MULTI_FILE_FAMILIES[big]
+ size = next((m for m in d["models"] if m.lower() == tag[len(d["tag"]):].lower()), None)
+ a = cfg.get("args", [])
+ ctx = a[a.index("--max-context") + 1] if "--max-context" in a and a.index("--max-context") + 1 < len(a) else None
+ return {"family": big, "model": size, "context": int(ctx) if ctx and ctx.isdigit() else None, "kv": None,
+ "vision": "none", "esp": "off", "host": cfg.get("host"), "api_key": cfg.get("api_key"),
+ "port": cfg.get("port"), "gpu": cfg.get("gpu"), "layer_split": None, "cuda": None, "vram_reserve_mib": None}
own = next((f for f, d in OWN_PATH_FAMILIES.items() if tag.startswith(d["tag"])), None)
if own is not None: # Qwen3.6: its own sizes; no KV / images / projection settings
d = OWN_PATH_FAMILIES[own]
@@ -5877,11 +5924,11 @@ def choices_from_config(cfg_path: Path) -> dict:
def calibration_targets(have: list, model: str | None, family: str | None) -> list:
"""#2036: the installed configs `--calibrate --model X` (and/or --family) means; every config with neither."""
if not (model or family):
- return [c for c in have if choices_from_config(c)["family"] not in OWN_PATH_FAMILIES]
+ return [c for c in have if choices_from_config(c)["family"] not in (*OWN_PATH_FAMILIES, *MULTI_FILE_FAMILIES)]
out = []
for c in have:
ch = choices_from_config(c)
- if ch["family"] in OWN_PATH_FAMILIES: # the tuning measures Flash-Next's engine settings
+ if ch["family"] in OWN_PATH_FAMILIES or ch["family"] in MULTI_FILE_FAMILIES: # the tuning measures Flash-Next's engine settings
continue
if (not model or ch["model"] == model) and (not family or ch["family"] == family):
out.append(c)
@@ -7180,6 +7227,159 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopte
return start(cfg_path, port)
+def dsv41_exe(eng: Path) -> Path | None:
+ """The DeepSeek-V4.1 engine (strata-dsv41) beside the engine in `eng`, or STRATA_DSV41_EXE (a build of your own); None when
+ there is none."""
+ own = (os.environ.get("STRATA_DSV41_EXE") or "").strip()
+ if own:
+ return Path(own) if Path(own).is_file() else None
+ exe = Path(eng) / ("strata-dsv41.exe" if WIN else "strata-dsv41")
+ return exe if exe.is_file() else None
+
+
+def dsv41_folder(a, fam: dict, tag: str) -> Path:
+ """Where the nine shards are: --gguf-dir (a folder with the shards, or the repository's folder with UD-Q8_K_XL inside), else the
+ models folder's own."""
+ if a.gguf_dir:
+ folder = Path(a.gguf_dir)
+ return folder / "UD-Q8_K_XL" if (folder / "UD-Q8_K_XL").is_dir() and not (folder / DSV41_SHARD.format(i=1)).exists() else folder
+ return Path(a.models_dir) / tag
+
+
+def dsv41_cards(gpu: dict, all_cards: list | None, asked: bool) -> list:
+ """The cards the model runs on: the ones asked for (--gpu / --gpus), else every card setup can use (recommend: the model is
+ larger than any one card, so the more graphics memory the more of its experts stay off the CPU)."""
+ if asked or not all_cards:
+ return list(gpu.get("cards") or [gpu])
+ return list(all_cards)
+
+
+def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted, all_cards=None):
+ """Steps 2-7 for DeepSeek-V4.1-Flash (MULTI_FILE_FAMILIES): where it fits (strata_control/dsv41_fit.py, said plainly: a 508 GB
+ download and a model larger than most computers' memory are warnings, never a refusal), the engine (strata-dsv41), the nine
+ pinned shards (or your own, --gguf-dir), the engine's pack folder, the tokenizer and chat template from the GGUF, the config. The
+ engine places the experts itself (as many as the cards hold in graphics memory, the rest computed on the CPU from the files)."""
+ from strata_control import dsv41_fit
+ fam = MULTI_FILE_FAMILIES[family]
+ say()
+ say(f" {fam['title']} - {fam['by']}: {fam['about']}")
+ ok(f"model: {fam['title']}")
+ if fam.get("license"):
+ say(f" Its license: {fam['license']}")
+ names = list(fam["models"])
+ if a.model and a.model not in names:
+ fail(f"{fam['title']} has no {a.model} model file", "choose: " + ", ".join(names))
+ model = a.model or names[0]
+ ok(f"size: {model}")
+ tag = fam["tag"] + model
+ cards = dsv41_cards(gpu, all_cards, bool(a.gpu is not None or a.gpus))
+ ctx = a.context or DSV41_CONTEXT
+ folder = dsv41_folder(a, fam, tag)
+ shards = [folder / n for n in fam["models"][model]["shards"]]
+
+ def partial(f: Path) -> int:
+ p = f.with_name(f.name + ".part")
+ return p.stat().st_size if p.is_file() else 0
+
+ left = sum(0 if f.exists() and (done(f) or a.gguf_dir) else fam["sha256"][f.name][0] - partial(f) for f in shards) / 1e9
+ probe = folder if folder.exists() else (folder.parent if folder.parent.exists() else Path(a.models_dir))
+ free = free_gb(probe)
+ plan = dsv41_fit.plan([{**c, "vram_gb": float(c.get("vram_gb") or 0)} for c in cards], ram, free if left else None, ctx)
+ say()
+ for line in plan["lines"]:
+ say(" " + line)
+ if left:
+ say(f" Download: {left:.0f} GB to fetch (checked against pinned sizes and SHA-256; it resumes if it stops). At 50 MB/s that "
+ f"is {left * 1e9 / 50e6 / 3600:.1f} hours. Files you already have: --gguf-dir DIR.")
+ for w in plan["warnings"]:
+ if "free disk space" in w:
+ continue # the disk is a hard limit, said below
+ warn(w)
+ if plan["verdict"] == "spills":
+ confirm_risk(f"{model} needs about {plan['ram_needed_gb']:.0f} GB of RAM beside this PC's graphics memory and this PC has "
+ f"{ram:.0f} GB: part of its experts are read from the SSD while it answers (slow)", bool(a.model), a.yes,
+ f"{model} needs about {plan['ram_needed_gb']:.0f} GB of RAM", f"more RAM or cards fix it; --model {model} --yes "
+ "installs it anyway", " Install it anyway?")
+ warn(f"installing {model} with {ram:.0f} GB of RAM, as you chose")
+ if left and free < left:
+ fail(f"not enough free disk space in {folder}: need ~{left:.0f} GB, {free:.0f} GB free",
+ "use --models-dir on a bigger drive (an NVMe drive is best: the n-gram table is read from it while the model "
+ "answers), or --gguf-dir for files you already have")
+ if left and free < left + dsv41_fit.DISK_HEADROOM_GB:
+ warn(f"little free disk space in {folder}: {free:.1f} GB free for about {left:.1f} GB. Setup goes on and should fit")
+ if ctx > 65536:
+ warn(f"{ctx // 1024}K tokens of context: the engine was checked at 4K and 8K; longer is kept as you chose, but untested")
+ if a.vision in ("yes", "gpu", "cpu"):
+ warn(f"{fam['title']} cannot read pictures in this Strata version (its picture reader is in development): images off")
+ if a.rope_scaling or a.rope_scale or a.kv or a.resident_budget_gib is not None or a.low_ram not in (None, "auto"):
+ warn(f"--rope-scaling / --kv / --resident-budget-gib / --low-ram are Flash-Next settings: {fam['title']} does not use them")
+
+ step(3, "Python packages")
+ pip_install(requirement_lines() if REQUIREMENTS.exists() else PY_PACKAGES,
+ "numpy, jinja2, regex, pyyaml, tqdm, requests, cmake, ninja, pillow, psutil")
+
+ step(4, "the Strata engine")
+ llama, eng, meta, lib_dirs, gpu, _vision = engine_step(a, gpu, hip, amd, cuda_tk, "none")
+ exe = dsv41_exe(eng)
+ if exe is None:
+ fail(f"this engine ({meta.get('version')}) has no DeepSeek-V4.1 engine (strata-dsv41) yet",
+ "update Strata, or compile it with cmake -DSTRATA_BUILD_DSV41=ON and point STRATA_DSV41_EXE at it, then run setup again "
+ "(nothing has been downloaded)")
+ ok(f"engine: {exe}")
+
+ step(5, f"downloading {fam['title']} {model}")
+ for f in shards:
+ if f.exists() and done(f):
+ ok(f"{f.name} already downloaded")
+ else:
+ if a.gguf_dir and not f.exists():
+ fail(f"{f} is missing", f"put {f.name} in {folder}, or drop --gguf-dir to download it")
+ if not a.gguf_dir:
+ download(fam["hf"] + f.name, f)
+ verify_sha256(f, *fam["sha256"][f.name], own=bool(a.gguf_dir))
+ ok(f"model files: {folder} ({len(shards)} shards)")
+
+ step(6, "preparing the model for Strata")
+ data, _ = data_folder_for(a)
+ pack = data / "packs" / tag.lower() # the engine's map of the shards, the hash tables, the tokenizer: a few MB
+ if not (pack / "tokenizer" / "vocab.json").exists() or not (pack / "tensors.txt").exists():
+ run([sys.executable, str(ROOT / "tools" / "dsv41" / "pack_gguf.py"), "--model", str(folder), "--out", str(pack)])
+ ok(f"pack: {pack}")
+
+ step(7, "writing the start script")
+ args = ["--pack", str(pack), "--max-context", str(ctx), "--eos", "1", *plan["args"]]
+ cfg = {"exe": str(exe), "args": args, "cwd": str(ROOT), "tokenizer": str(pack / "tokenizer"),
+ "model_name": fam["name"], "arch": fam["arch"], "log": str(home() / f"strata-{tag.lower()}.log"),
+ "lib_dirs": lib_dirs, "port": port}
+ if cuda_tk == 12:
+ cfg["cuda"] = 12
+ if hip:
+ cfg["backend"] = "hip"
+ idx = [c["index"] for c in cards]
+ if len(idx) > 1 or a.gpu is not None or a.gpus:
+ cfg["gpu"] = idx if len(idx) > 1 else idx[0]
+ cfg["gpus_asked"] = True
+ if a.host:
+ cfg["host"] = a.host
+ if a.api_key:
+ cfg["api_key"] = a.api_key
+ if a.browser is not None:
+ cfg["open_browser"] = a.browser
+ cfg_path = home() / f"strata-{tag.lower()}.json"
+ write_setup_config(cfg_path, cfg, adopted if adopted is not None and adopted.name == cfg_path.name else None, explicit_args(a))
+ script = write_run_script(tag, cfg_path, port, cfg.get("open_browser") is not False)
+ ok(f"start script: {script.name}")
+ say()
+ say("All set.")
+ say(f" API (OpenAI): http://127.0.0.1:{port}/v1 (any API key; model name: anything)")
+ say(f" API (Anthropic): http://127.0.0.1:{port}/v1/messages")
+ say(f" Next time: just run {'START-HERE.bat' if WIN else './setup.sh'} (or {script.name}) - it starts right away")
+ say(" Loading takes a few minutes: the CPU's share of the experts is read from the files first.")
+ if a.no_start:
+ return 0
+ return start(cfg_path, port)
+
+
def preview_family(a) -> int:
"""--family qwen36: a family setup knows but the engine does not run yet (PREVIEW_FAMILIES). Downloads the chosen
size (pinned revision, size and SHA-256 checked) and, with --vision, the image encoder - and says plainly that
@@ -7425,11 +7625,13 @@ def main() -> int:
if sys.platform == "darwin" and not CONTROL: # a Mac: metal/setup_mac.py (the Metal engine); the app (Control mode) goes on below
return mac_setup(sys.argv[1:])
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
- ap.add_argument("--family", choices=list(FAMILIES) + list(PREVIEW_FAMILIES),
+ ap.add_argument("--family", choices=list(FAMILIES) + list(PREVIEW_FAMILIES) + list(MULTI_FILE_FAMILIES),
help="qwen = Qwen3.8-Flash-Next, swift = Swift 1.5, qwen36 = Qwen3.6-35B-A3B (pictures with --vision, "
- "several requests at once with --parallel; docs/QWEN36.md)")
+ "several requests at once with --parallel; docs/QWEN36.md), deepseek41 = DeepSeek-V4.1-Flash "
+ "(a 508 GB download for several graphics cards; docs/DEEPSEEK41.md)")
ap.add_argument("--model", choices=list(dict.fromkeys([*MODELS, *(m for f in PREVIEW_FAMILIES.values()
- for m in f["models"])])))
+ for m in f["models"]),
+ *(m for f in MULTI_FILE_FAMILIES.values() for m in f["models"])])))
ap.add_argument("--context", type=int)
ap.add_argument("--rope-scaling", choices=["none", "linear", "yarn"],
help="the RoPE extension for a context past the model's trained 262144: linear (position "
@@ -7552,8 +7754,8 @@ def main() -> int:
"sycl = Intel Arc, EXPERIMENTAL: Linux, built from source (docs/INTEL_ARC.md)")
ap.add_argument("--skip-build", action="store_true", help=argparse.SUPPRESS)
a = ap.parse_args()
- if a.model and a.model not in MODELS and a.family not in PREVIEW_FAMILIES:
- ap.error(f"--model {a.model} is a size of " + ", ".join(f"--family {f}" for f, d in PREVIEW_FAMILIES.items()
+ if a.model and a.model not in MODELS and a.family not in PREVIEW_FAMILIES and a.family not in MULTI_FILE_FAMILIES:
+ ap.error(f"--model {a.model} is a size of " + ", ".join(f"--family {f}" for f, d in {**PREVIEW_FAMILIES, **MULTI_FILE_FAMILIES}.items()
if a.model in d["models"]))
if a.source:
os.environ["STRATA_SOURCE"] = a.source
@@ -7861,6 +8063,17 @@ def main() -> int:
else:
any_fits = any_fits or (not verdict.startswith("does not fit") and not d.get("mem_total"))
say(f" {m:8s} needs ~{d['ram_gb']} GB {'of VRAM + RAM' if d.get('mem_total') else 'RAM'}: {verdict}")
+ try: # DeepSeek-V4.1-Flash: a line, from the real numbers (strata_control/dsv41_fit.py)
+ from strata_control import dsv41_fit
+ ds = dsv41_fit.plan(amd_ok if hip else [g for g in found if gpu_problem(g) is None], ram, None)
+ tail = {"fits": f"fits ({ds['experts_in_vram']:,} of {ds['experts_total']:,} experts in graphics memory, the rest on the CPU)",
+ "tight": "fits, but RAM is tight",
+ "spills": f"about {ds['spill_gb']:.0f} GB of its experts would be read from the SSD (slow)",
+ "no_card": "needs one or more graphics cards"}.get(ds["verdict"], "not checked")
+ say(f" {'DeepSeek-V4.1-Flash':8s} needs ~{ds['weights_gb']:.0f} GB of VRAM + RAM (a {ds['download_gb']:.0f} GB download): {tail}"
+ " (--family deepseek41)")
+ except Exception: # noqa: BLE001 - a line for information: never break the check
+ pass
if not any_fits:
# #977: every size says "does not fit", so the verdict says so too (and the exit code, for scripts). It only
# reports: --model NAME --yes still installs one anyway.
@@ -7883,16 +8096,20 @@ def main() -> int:
say(f" {i}) {d['title']:20s} {d['by']} - {d['about']}" + (" [experimental]" if d.get("experimental") else "")
+ family_menu_note(f, hip, gpu, avx2, avx512)
+ (f" (recommended for Strix Halo: {STRIX_HALO_MODEL})" if f == rec_fam and rec_fam != fams[0] else ""))
- for j, f in enumerate(OWN_PATH_FAMILIES, len(fams) + 1): # families with an engine path of their own
- d = OWN_PATH_FAMILIES[f]
+ for j, f in enumerate([*OWN_PATH_FAMILIES, *MULTI_FILE_FAMILIES], len(fams) + 1): # families with an engine path of their own
+ d = {**OWN_PATH_FAMILIES, **MULTI_FILE_FAMILIES}[f]
say(f" {j}) {d['title']:20s} {d['by']} - {d['about']} [new]")
- allf = fams + list(OWN_PATH_FAMILIES)
+ allf = fams + list(OWN_PATH_FAMILIES) + list(MULTI_FILE_FAMILIES)
if tier_note(ram, low_ram_vram(gpu)) and rec_fam == "swift":
say(" " + tier_note(ram, low_ram_vram(gpu)))
family = allf[int(ask("Which model?", [str(i) for i in range(1, len(allf) + 1)],
str(allf.index(rec_fam) + 1), a.yes)) - 1]
if family in OWN_PATH_FAMILIES: # Qwen3.6: its own engine path, its own steps 2-7
return install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted)
+ if family in MULTI_FILE_FAMILIES: # DeepSeek-V4.1-Flash: nine shards, its own engine, several cards
+ all_cards = amd_ok if hip else [g for g in found if gpu_problem(g) is None]
+ gpu = {**gpu, "cards": chosen}
+ return install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted, all_cards)
fam = FAMILIES[family]
if fam.get("ready") and hip:
# not a risk the user could take: the HIP engine has no NVFP4 expert kernels at all, so it would not start
diff --git a/strata_cli/launch/catalog.py b/strata_cli/launch/catalog.py
index efd52685b..69fef59ba 100644
--- a/strata_cli/launch/catalog.py
+++ b/strata_cli/launch/catalog.py
@@ -313,11 +313,16 @@ class Catalog:
rec = self.recommendation(hw)
out: list[ModelRow] = []
own = self.strata.own_families() # Qwen3.6 is listed for the app; the Terminal's launch list is Flash-Next's
+ dsv41 = None
for fam in self.strata.model_table(hw):
- if fam["family"] in own:
+ if fam["family"] in own and not own[fam["family"]].get("multi_file"):
continue
for size in fam["sizes"]:
f = fit_on(size, hw.get("ram_gb"), vram)
+ if size.get("multi_file"): # DeepSeek-V4.1-Flash: shared over every card (strata_control/dsv41_fit.py)
+ dsv41 = dsv41 or self.strata.dsv41_plan(hw)
+ f = {"vramUseGb": _round1(dsv41["vram_experts_gb"] + sum(c["dense_gb"] for c in dsv41["cards"])),
+ "ramUseGb": _round1(dsv41.get("ram_needed_gb") or dsv41["cpu_experts_gb"]), "spillGb": _round1(dsv41.get("spill_gb") or 0.0)}
cat, words = verdict(size.get("on_this_pc"))
out.append(ModelRow(
family=fam["family"], family_title=fam["title"], model=size["model"], id=size["id"],
@@ -333,6 +338,9 @@ class Catalog:
"""`iq3_xxs` or `IQ3_XXS` (and an optional family) -> (family, model); raises ValueError with the closest match."""
models, families, _ctx, _src = self.tables()
names = list(models)
+ for fam_name, fam_d in families.items(): # DeepSeek-V4.1-Flash's size is not one of setup's MODELS
+ if fam_d.get("multi_file"):
+ names += [m for m in self.strata.sizes_of(models, fam_name) if m not in names]
match = next((n for n in names if n.lower() == model.lower()), None)
if match is None:
near = S.closest(model, names)
@@ -365,6 +373,8 @@ class Catalog:
def max_context(self, family: str, model: str, hw: dict | None = None) -> int | None:
"""The recommended context for this computer and model (setup.py: VRAM rule, then the RAM rule)."""
hw = hw or self.hardware()
+ if self.strata.multi_family(family): # DeepSeek-V4.1-Flash: the context the engine was checked at
+ return int(getattr(self.strata.setup_module(), "DSV41_CONTEXT", 8192))
if hw.get("mac") and hw.get("ram_gb"): # a Mac: the context by unified memory (strata_control/mac_fit.py)
mac = self.strata.mac()
if mac is not None:
diff --git a/strata_cli/launch/cmd.py b/strata_cli/launch/cmd.py
index bd401cd3f..3eb04e714 100644
--- a/strata_cli/launch/cmd.py
+++ b/strata_cli/launch/cmd.py
@@ -240,6 +240,24 @@ def settings_from_args(a: argparse.Namespace, catalog=None) -> tuple[S.LaunchSet
return s, notices
+def _placement_lines(placement: dict | None) -> None:
+ """DeepSeek-V4.1-Flash's plan: the cards, the experts in graphics memory and on the CPU, the n-gram table on the SSD, the warnings."""
+ if not placement:
+ return
+ import textwrap
+ _say(" placement")
+ for line in placement.get("lines") or []:
+ wrapped = textwrap.wrap(line, 94) or [""]
+ _say(" - " + wrapped[0])
+ for w in wrapped[1:]:
+ _say(" " + w)
+ for line in placement.get("warnings") or []:
+ wrapped = textwrap.wrap(line, 90) or [""]
+ _say(" [!] " + wrapped[0])
+ for w in wrapped[1:]:
+ _say(" " + w)
+
+
def apply_defaults(s: S.LaunchSettings, catalog) -> tuple[S.LaunchSettings, list[S.Notice]]:
"""Fill what was left open with the recommendation for this computer, and collect warnings (never errors for a bad fit)."""
notices: list[S.Notice] = []
@@ -271,6 +289,16 @@ def apply_defaults(s: S.LaunchSettings, catalog) -> tuple[S.LaunchSettings, list
if s.vision == "off" and r.images and catalog.reader_state() == "missing":
notices.append(S.Notice("warn", "The engine installed here has no picture reader, so pictures are off.",
"Update the engine to read pictures, or add --vision off to silence this."))
+ if catalog.strata.multi_family(s.family): # DeepSeek-V4.1-Flash: one request at a time, no tuning, no pictures yet
+ if s.parallel and s.parallel > 1:
+ notices.append(S.Notice("warn", f"{s.model} answers one request at a time in this Strata version, so --parallel {s.parallel} is not used.", ""))
+ s.parallel = None
+ if s.vision not in (None, "off"):
+ notices.append(S.Notice("warn", "DeepSeek-V4.1-Flash cannot read pictures in this Strata version, so pictures are off.", ""))
+ s.vision = "off"
+ if s.tune not in (None, "skip"):
+ notices.append(S.Notice("warn", "Tuning is not offered for DeepSeek-V4.1-Flash yet; it starts with the engine's own settings.", ""))
+ s.tune = "skip"
notices += S.check_context(s, max_fit_tokens=None)
if s.access != "local" and not s.api_key and not s.no_key:
from strata_cli.launch import access
@@ -610,8 +638,9 @@ def run_launch(a: argparse.Namespace) -> int:
_say(f" model {m.get('title') or 'your model files'}{size} (your files in {s.model_path})")
else:
_say(f" model {m.get('title') or f'{s.family} {s.model}'}{size}")
- _say(f" context {S.context_label(s.context)} pictures {PICTURE_WORDS.get(s.vision or 'off', s.vision)} parallel {s.parallel or 'fit to your card'}")
+ _say(f" context {S.context_label(s.context)} pictures {PICTURE_WORDS.get(s.vision or 'off', s.vision)} parallel {('one at a time' if plan.get('placement') else s.parallel or 'fit to your card')}")
_say(f" download {(plan.get('download') or {}).get('text', '')}")
+ _placement_lines(plan.get("placement"))
_say(f" tuning {s.tune} access {S.ACCESS_WORDS[s.access]}, port {s.port}"
+ (" API key on" if s.api_key else ""))
for n in notes:
diff --git a/strata_cli/launch/runner.py b/strata_cli/launch/runner.py
index d8c223641..117f867b8 100644
--- a/strata_cli/launch/runner.py
+++ b/strata_cli/launch/runner.py
@@ -808,6 +808,38 @@ class Runner:
self.emit("model", f"Used your prepared model files and wrote the run settings ({path.name}); this card is not one the built-in downloader sets up.", 100, level="warn")
return path
+ def deepseek_files(self) -> bool:
+ """--model-path names DeepSeek-V4.1-Flash's shards (a folder, the repository's folder with UD-Q8_K_XL inside, or one shard): they are
+ that model, whatever the fingerprint table of the Flash-Next files says. True when it did (s.family / s.model / s.model_path set); a
+ shard missing from the folder is said now, in plain words, before an engine or a download is touched."""
+ s = self.s
+ try:
+ mod = self.catalog.strata.setup_module()
+ shard = getattr(mod, "DSV41_SHARD", None)
+ if shard is None or not s.model_path:
+ return False
+ p = Path(s.model_path)
+ folders = [p, p / "UD-Q8_K_XL"] if p.is_dir() else [p.parent]
+ first = shard.format(i=1)
+ others = [shard.format(i=i) for i in range(1, 10)]
+ folder = next((f for f in folders if any((f / n).exists() for n in others)), None)
+ except Exception: # noqa: BLE001 - not DeepSeek's: the usual check goes on
+ return False
+ if folder is None:
+ return False
+ if s.family and s.family != "deepseek41":
+ raise LaunchError(f"These are DeepSeek-V4.1-Flash's files, not {s.family} {s.model}'s.",
+ "Leave --model out, or use --model UD-Q8_K_XL.", 2)
+ missing = [n for n in others if not (folder / n).exists()]
+ if missing:
+ raise LaunchError(f"DeepSeek-V4.1-Flash is in nine parts and {len(missing)} of them are not in {folder} "
+ f"(first missing: {missing[0]}).",
+ "Put every part in the folder (or drop --model-path and let Strata download them: about 508 GB). "
+ "Nothing was downloaded or changed.", 5)
+ s.family, s.model, s.model_path = "deepseek41", s.model or "UD-Q8_K_XL", str(folder)
+ self.emit("model", "These files are DeepSeek-V4.1-Flash UD-Q8_K_XL; they are used where they are.", None)
+ return True
+
def check_own_files(self) -> None:
"""The person's own model files, looked at once: a path that is not there or holds no model is said in plain words first, and the
files are matched to the catalog model (resolve_own_files). Nothing else is done with a path that was already checked."""
@@ -824,6 +856,8 @@ class Runner:
problem = models.own_path_problem(s.model_path)
if problem: # before the engine or setup are touched, with the path as typed
raise LaunchError(problem[0], problem[1], 2)
+ if self.deepseek_files():
+ return
given = bool(s.family and s.model)
try:
plan = models.plan_import(models.absolute(s.model_path))
@@ -879,7 +913,16 @@ class Runner:
if cur.get("overrides") != want:
profiles.save(name, {**cur, "overrides": want}, expected_revision=rev)
+ def multi_file(self) -> bool:
+ """The chosen model is DeepSeek-V4.1-Flash (setup.py MULTI_FILE_FAMILIES): nine shards, its own engine; no tuning and no parallel slots."""
+ try:
+ return bool(self.s.family and self.catalog.strata.multi_family(self.s.family))
+ except Exception: # noqa: BLE001
+ return False
+
def catalog_parallel(self) -> int | None:
+ if self.multi_file(): # the DeepSeek engine answers one request at a time: no --batch to pass
+ return None
try:
comp = self.catalog.computer()
return S.fit_parallel(comp.main_vram_gb) if comp.usable_gpus else None
@@ -891,6 +934,9 @@ class Runner:
s = self.s
if s.tune == "skip":
return
+ if self.multi_file():
+ self.emit("tune", "Tuning is not offered for DeepSeek-V4.1-Flash yet: it starts with the engine's own settings.", 100)
+ return
from strata_control import presets
if not self.retune:
if s.tuned_preset:
@@ -1104,8 +1150,49 @@ class Runner:
title = row.title if row is not None else (f"{s.family} {s.model}" if s.model else None)
model = {"title": title, "family": s.family, "model": s.model, "model_gb": row.download_gb if row is not None else None,
"own_files": bool(s.model_path), "folder": s.model_path}
- return {"profile": self.profile, "settings": s.to_dict(with_key=False), "warnings": warns,
- "flags": S.flags_text(s), "steps": list(STAGES), "model": model, "download": download}
+ out = {"profile": self.profile, "settings": s.to_dict(with_key=False), "warnings": warns,
+ "flags": S.flags_text(s), "steps": list(STAGES), "model": model, "download": download}
+ if self.multi_file():
+ out["placement"] = self.placement()
+ return out
+
+ def dsv41_engine(self) -> bool | None:
+ """Whether the installed engine carries strata-dsv41 (True / False); None when no engine is installed yet or it cannot be told."""
+ own = (os.environ.get("STRATA_DSV41_EXE") or "").strip()
+ if own:
+ return Path(own).is_file()
+ try:
+ from strata_control import engine_component as ec
+ rep = ec.status()
+ exe = (rep.get("engine") or {}).get("exe") if rep.get("usable") else None
+ if not exe:
+ return None
+ folder = Path(str(exe)).parent
+ return any((folder / n).is_file() for n in ("strata-dsv41", "strata-dsv41.exe"))
+ except Exception: # noqa: BLE001
+ return None
+
+ def placement(self) -> dict:
+ """Where DeepSeek-V4.1-Flash would go on this computer's cards (strata_control/dsv41_fit.py): the cards this launch names, else every
+ card that counts; the real numbers in plain words, with the n-gram table's SSD note and the RAM / disk warnings (never a refusal)."""
+ s = self.s
+ hw = self.catalog.hardware()
+ try:
+ data = Path(s.data_dir) if s.data_dir else self.catalog.data_dir()
+ free = None if (s.model_path or self.model_state().remaining_gb < 1) else self.catalog.disk_free(data)
+ except Exception: # noqa: BLE001 - a plan that cannot read the disk still shows the rest
+ free = None
+ p = self.catalog.strata.dsv41_plan(hw, free, s.gpus)
+ warnings = list(p["warnings"])
+ engine = self.dsv41_engine()
+ if engine is False:
+ warnings.append("The engine installed here has no DeepSeek-V4.1 engine (strata-dsv41) yet: setup stops with a message before "
+ "anything is downloaded. Update Strata, or build it (cmake -DSTRATA_BUILD_DSV41=ON) and set STRATA_DSV41_EXE.")
+ return {"verdict": p["verdict"], "lines": p["lines"], "warnings": warnings, "cards": p["cards"], "args": p["args"],
+ "engine_has_dsv41": engine,
+ "experts_in_vram": p["experts_in_vram"], "experts_total": p["experts_total"], "vram_experts_gb": p["vram_experts_gb"],
+ "cpu_experts_gb": p["cpu_experts_gb"], "ram_needed_gb": p.get("ram_needed_gb"), "engram_gb": p["engram_gb"],
+ "download_gb": p["download_gb"], "measured": p["measured"]}
def run(self, *, start: bool = True) -> Result:
try:
diff --git a/strata_control/dsv41_fit.py b/strata_control/dsv41_fit.py
new file mode 100644
index 000000000..f9dcbaeb0
--- /dev/null
+++ b/strata_control/dsv41_fit.py
@@ -0,0 +1,228 @@
+"""Where DeepSeek-V4.1-Flash goes on a computer: the real numbers of the model and its engine, in one place.
+
+The model is 40 layers of 384 routed experts (top 6) beside dense attention weights. Unsloth's UD-Q8_K_XL (the
+file Strata runs, pinned in setup.py) is 508.4 GB in nine shards:
+
+ routed experts, MXFP4 288.8 GB 15,360 experts of 18.8 MB (40 layers x 384)
+ dense weights, BF16 / F32 16.8 GB attention, router, shared experts, the head (the embedding table stays on the CPU)
+ the n-gram table (Engram) 202.8 GB MXFP8, shard 8: read from the SSD, a few rows a token, never held in memory
+
+so the memory the model needs is the experts and the dense weights, 305.6 GB, with the n-gram table left out. strata-dsv41
+(src/dsv41) puts the dense weights and as many experts as the cards hold in graphics memory, one block of layers on each
+card, and computes the rest of the experts on the CPU, reading them in place from the model's files (the page cache).
+
+Measured (r9700, 4 x Radeon AI PRO R9700 32 GB, 251 GB RAM, 2026-10-20, f-dsv41-port 01389205e): per card 3.4-4.7 GB of dense
+weights, 28.5-29.8 GB of experts (1,505-1,575 of its 3,840), ~0.6 GB free; 6,197 experts (116.5 GB) in graphics memory and
+9,163 (172.3 GB) on the CPU lane; --tp 2: prompts 143-181 tokens/s (3K prompts), answers 25-31 tokens/s. Pure functions, no I/O:
+setup.py, tools/strata_mcp.py and strata_cli/launch import it. Recommend, never force: nothing here refuses a computer.
+"""
+
+from __future__ import annotations
+
+from typing import Any
+
+from strata_control import gpu_fit
+
+GB = 1e9
+GIB = 2 ** 30
+MAIN_BYTES = 508_376_763_197 # the nine shards of UD-Q8_K_XL (setup.py DSV41_FILES)
+ENGRAM_BYTES = 202_758_032_592 # shard 8: the n-gram table
+EXPERT_BYTES = 288_777_830_400 # MXFP4: 543,581,798,400 values x 17/32 bytes
+LAYERS = 40
+EXPERTS_PER_LAYER = 384
+EXPERTS = LAYERS * EXPERTS_PER_LAYER # 15,360
+EXPERT_GB = EXPERT_BYTES / GB / EXPERTS # 18.8 MB each
+WEIGHTS_GB = (MAIN_BYTES - ENGRAM_BYTES) / GB # 305.6
+EXPERTS_GB = EXPERT_BYTES / GB # 288.8
+DENSE_GB = WEIGHTS_GB - EXPERTS_GB # 16.8
+DENSE_ON_GPU_GB = 15.5 # measured: 3.72 + 3.69 + 3.40 + 4.70 (the embedding table, ~1.3 GB, stays on the CPU)
+ENGRAM_GB = ENGRAM_BYTES / GB # 202.8
+DOWNLOAD_GB = MAIN_BYTES / GB # 508.4
+RESERVE_GB = 1.15 # per card: the 600 MiB the engine leaves free (--reserve-mib) and ~0.5 GB of its buffers
+ # (measured: dense weights + experts + free = 33.8 of an R9700's 34.4 GB)
+REST_RAM_GB = 9.0 # RAM the engine and the system keep besides the experts ("beside 9 GB for the rest")
+SPARE_FITS_GB = 4.0 # RAM left beyond the CPU lane's experts below which "fits" becomes "tight"
+DISK_HEADROOM_GB = 6.0 # the pack folder (hash tables, tokenizer) and room to work
+SMALLEST_CARD_GB = 8.0 # a card under this adds little: the dense weights alone are ~4 GB of it per card of four
+MEASURED = ("4 x Radeon AI PRO R9700 (32 GB) with 251 GB of RAM: prompts of 3,000 tokens read at 143-181 tokens/s, answers "
+ "at 25-31 tokens/s (--tp 2); one answer at a time")
+
+
+def _round1(x: float) -> float:
+ return round(float(x) * 10) / 10
+
+
+def _cap_gb(vram_gb: float) -> float:
+ """Decimal GB a card of `vram_gb` (as the catalogs state it, GiB: 32 for an R9700) has."""
+ return float(vram_gb) * GIB / GB
+
+
+def split_layers(weights: list[float], layers: int = LAYERS) -> list[tuple[int, int]]:
+ """The layer ranges (first, last) of consecutive cards, in proportion to `weights` (each card at least one layer).
+ The engine balances its own split; on cards of one size this is what it picked (0-9, 10-19, 20-29, 30-39)."""
+ n = len(weights)
+ if n <= 1:
+ return [(0, layers - 1)]
+ total = float(sum(weights)) or 1.0
+ raw = [w / total * layers for w in weights]
+ counts = [max(1, int(r)) for r in raw]
+ order = sorted(range(n), key=lambda i: raw[i] - int(raw[i]), reverse=True)
+ k = 0
+ while sum(counts) < layers:
+ counts[order[k % n]] += 1
+ k += 1
+ while sum(counts) > layers:
+ i = max(range(n), key=lambda j: counts[j])
+ counts[i] -= 1
+ out, first = [], 0
+ for c in counts:
+ out.append((first, first + c - 1))
+ first += c
+ return out
+
+
+def tp_for(n_cards: int) -> int:
+ """--tp for this many cards: pairs of cards share each layer's matrices (measured 2x faster prompts than a plain layer split).
+ The engine's own check refuses 4 (576 is not a multiple of 128) and drops to 2, so 2 is what is written for two or more cards."""
+ return 2 if n_cards >= 2 else 1
+
+
+def plan(cards: list[dict] | None, ram_gb: float | None, disk_free_gb: float | None = None, context: int = 8192,
+ vendor: str | None = None) -> dict[str, Any]:
+ """Where the model goes on this computer. `cards`: the graphics cards ({"index", "name", "vram_gb", ...}, as gpu_fit takes them),
+ `ram_gb` the RAM, `disk_free_gb` the free space where the files go (None: not checked).
+
+ Keys: cards (per card: index, name, vram_gb, layers, dense_gb, experts_gb, experts), experts_in_vram, experts_total, vram_experts_gb,
+ cpu_experts_gb, ram_needed_gb, spill_gb, spare_ram_gb, verdict (fits / tight / spills / unknown / no_card), tp, args,
+ download_gb, engram_gb, disk_need_gb, disk_ok, lines (plain words, one idea each), warnings (the risks, plainly), measured."""
+ keep, ignored = gpu_fit.usable_cards(gpu_fit.for_vendor(list(cards or []), vendor)[0]) if vendor else gpu_fit.usable_cards(list(cards or []))
+ keep = [c for c in keep if float(c.get("vram_gb") or 0) >= SMALLEST_CARD_GB]
+ keep.sort(key=lambda c: c.get("index", 0)) # the engine takes the layers in card order
+ n = len(keep)
+ out: dict[str, Any] = {"cards": [], "experts_total": EXPERTS, "experts_in_vram": 0, "vram_experts_gb": 0.0,
+ "cpu_experts_gb": EXPERTS_GB, "weights_gb": _round1(WEIGHTS_GB), "experts_gb": _round1(EXPERTS_GB),
+ "dense_gb": _round1(DENSE_GB), "engram_gb": _round1(ENGRAM_GB), "download_gb": _round1(DOWNLOAD_GB),
+ "tp": tp_for(n), "args": [], "measured": MEASURED, "lines": [], "warnings": [],
+ "ram_gb": ram_gb, "context": context}
+ need_disk = DOWNLOAD_GB + DISK_HEADROOM_GB
+ out["disk_need_gb"] = _round1(need_disk)
+ out["disk_ok"] = None if disk_free_gb is None else disk_free_gb >= need_disk
+ lines, warns = out["lines"], out["warnings"]
+ lines.append(f"DeepSeek-V4.1-Flash (UD-Q8_K_XL): a {DOWNLOAD_GB:.0f} GB download. In memory it needs {WEIGHTS_GB:.0f} GB: "
+ f"{EXPERTS_GB:.0f} GB of experts ({EXPERTS:,} of {EXPERT_GB * 1000:.1f} MB) and {DENSE_GB:.0f} GB of attention "
+ "and other dense weights.")
+ lines.append(f"Its n-gram table ({ENGRAM_GB:.0f} GB of the download) stays on the SSD and is read a few rows for each word "
+ "it writes: it is not counted in RAM, but a slow disk (SATA, a network drive, a USB disk) makes every word "
+ "slower. Use an NVMe drive for the model files.")
+ if n == 0:
+ out["verdict"] = "no_card"
+ warns.append("No graphics card Strata can use was found: this model needs one or more cards (it was run on AMD Radeon "
+ "AI PRO R9700 cards).")
+ else:
+ per_dense = DENSE_ON_GPU_GB / n
+ cap = []
+ for c in keep:
+ room = _cap_gb(float(c.get("vram_gb") or 0)) - per_dense - RESERVE_GB
+ cap.append(max(0.0, room))
+ vram_exp = min(EXPERTS_GB, sum(cap))
+ share = [x / sum(cap) if sum(cap) else 1.0 / n for x in cap]
+ ranges = split_layers([float(c.get("vram_gb") or 0) for c in keep])
+ in_vram = 0
+ for c, room, (a, b), s in zip(keep, cap, ranges, share):
+ gb = min(room, vram_exp * s) if sum(cap) else 0.0
+ ne = int(gb / EXPERT_GB)
+ ne = min(ne, (b - a + 1) * EXPERTS_PER_LAYER)
+ in_vram += ne
+ out["cards"].append({"index": c.get("index"), "name": c.get("name"), "vram_gb": float(c.get("vram_gb") or 0),
+ "layers": [a, b], "dense_gb": _round1(per_dense), "experts_gb": _round1(ne * EXPERT_GB),
+ "experts": ne})
+ out["experts_in_vram"] = in_vram
+ out["vram_experts_gb"] = _round1(in_vram * EXPERT_GB)
+ out["cpu_experts_gb"] = _round1(EXPERTS_GB - in_vram * EXPERT_GB)
+ out["tp"] = tp_for(n)
+ out["args"] = ["--tp", str(out["tp"])] if out["tp"] > 1 else []
+ if ram_gb:
+ needed = out["cpu_experts_gb"] + REST_RAM_GB
+ spare = float(ram_gb) - needed
+ out["ram_needed_gb"] = _round1(needed)
+ out["spare_ram_gb"] = _round1(max(0.0, spare))
+ out["spill_gb"] = _round1(max(0.0, -spare))
+ out["verdict"] = "spills" if spare < 0 else "tight" if spare < SPARE_FITS_GB else "fits"
+ else:
+ out["verdict"] = "unknown"
+ # the placement, in words
+ short = [c for c in keep if _cap_gb(float(c.get("vram_gb") or 0)) < per_dense + RESERVE_GB + 1.0]
+ if short:
+ warns.append(f"The dense weights need ~{per_dense:.0f} GB of graphics memory on {'each card' if n > 1 else 'the card'} "
+ f"and {short[0].get('name') or 'a card'} ({float(short[0].get('vram_gb') or 0):.0f} GB) has "
+ "hardly that: the engine may stop at the start (out of graphics memory). More or bigger cards fix it; "
+ "it is still allowed.")
+ if n == 1:
+ c = out["cards"][0]
+ lines.append(f"One card ({c['name'] or 'card ' + str(c['index'])}, {c['vram_gb']:.0f} GB): the dense weights ({c['dense_gb']:.0f} GB) "
+ f"and {c['experts']:,} of the {EXPERTS:,} experts ({c['experts_gb']:.0f} GB) go in its memory, the other "
+ f"{EXPERTS - c['experts']:,} experts ({out['cpu_experts_gb']:.0f} GB) are computed on the CPU from RAM.")
+ else:
+ blocks = " | ".join(f"card {c['index']}: layers {c['layers'][0]}-{c['layers'][1]}" for c in out["cards"])
+ lines.append(f"{n} cards, one block of layers on each ({blocks}); the engine balances the split. On each card "
+ f"~{out['cards'][0]['dense_gb']:.1f} GB of dense weights and ~{out['cards'][0]['experts_gb']:.0f} GB of experts "
+ f"(about {out['cards'][0]['experts']:,}); in all {in_vram:,} of {EXPERTS:,} experts ({out['vram_experts_gb']:.0f} GB) "
+ f"are in graphics memory.")
+ lines.append("Two cards share each layer's matrices (--tp 2): measured about twice as fast at reading prompts as a plain "
+ "split of the layers.")
+ lines.append(f"The other {EXPERTS - in_vram:,} experts ({out['cpu_experts_gb']:.0f} GB) are computed on the CPU, read in place "
+ "from the model's files: they need that much free RAM to stay cached "
+ f"({out.get('ram_needed_gb', out['cpu_experts_gb'] + REST_RAM_GB):.0f} GB with {REST_RAM_GB:.0f} GB for the system and the engine).")
+ if out["verdict"] == "spills":
+ warns.append(f"This computer has {ram_gb:.0f} GB of RAM and {out['ram_needed_gb']:.0f} GB would keep the CPU's share of the experts "
+ f"cached: about {out['spill_gb']:.0f} GB of them are read from the SSD while the model answers, which is slow "
+ "(a word can take seconds). More RAM or more graphics memory fixes it. It is still allowed.")
+ elif out["verdict"] == "tight":
+ warns.append(f"RAM is tight: {out['spare_ram_gb']:.0f} GB are left beside the experts; close other programs.")
+ elif out["verdict"] == "fits":
+ lines.append(f"That fits this computer ({ram_gb:.0f} GB of RAM, {out['spare_ram_gb']:.0f} GB to spare).")
+ if n >= 2 and any(abs(float(c.get("vram_gb") or 0) - float(keep[0].get("vram_gb") or 0)) > 1 for c in keep):
+ lines.append("The cards are not the same size: the layers are shared in proportion to their memory.")
+ if ignored:
+ lines.append("Not used: " + "; ".join(f"{c.get('name') or 'a card'} ({c.get('why_ignored')})" for c in ignored) + ".")
+ lines.append("Measured on " + MEASURED + ". Other computers are slower or faster by what their cards and RAM can hold; "
+ "this engine has been run on AMD cards.")
+ if disk_free_gb is not None and disk_free_gb < need_disk:
+ warns.append(f"The download needs about {need_disk:.0f} GB of free disk space and {disk_free_gb:.0f} GB are free where the "
+ "files go. Use --models-dir on a bigger drive, or --gguf-dir for files you already have.")
+ out["words"] = " ".join(lines)
+ return out
+
+
+def _option(key: str, cards: list[dict], ram_gb: float | None, ctx: int, vendor: str | None) -> dict[str, Any]:
+ p = plan(cards, ram_gb, None, ctx, vendor)
+ names = " + ".join(gpu_fit._name(c) for c in cards)
+ label = f"{names} + RAM" if len(cards) == 1 else f"{names} + RAM (layers shared, --tp {p['tp']})"
+ words = {"fits": f"fits: {p['experts_in_vram']:,} of {p['experts_total']:,} experts in graphics memory, the rest computed on the CPU "
+ f"({p.get('ram_needed_gb', 0):.0f} GB of RAM)",
+ "tight": f"fits, but tight: RAM left over is under {SPARE_FITS_GB:.0f} GB",
+ "spills": f"does not fit in memory: about {p.get('spill_gb', 0):.0f} GB of the experts are read from the SSD while answering (slow)",
+ "unknown": "memory of this computer unknown", "no_card": "no usable card"}[p["verdict"]]
+ return {"key": key, "cards": [c.get("index") for c in cards], "label": label, "verdict": p["verdict"], "summary": f"{label}: {words}",
+ "words": words, "vram_gb": _round1(sum(float(c.get("vram_gb") or 0) for c in cards)), "spill_gb": p.get("spill_gb", 0.0),
+ "ram_use_gb": p.get("cpu_experts_gb", 0.0), "spare_ram_gb": p.get("spare_ram_gb", 0.0),
+ "notes": [l for l in p["lines"] if l.startswith(("One card", f"{len(cards)} cards", "Two cards share"))],
+ "recommended": False, "plan": p}
+
+
+def options(cards: list[dict], ram_gb: float | None, vendor: str | None = None, context: int = 8192) -> dict[str, Any]:
+ """gpu_fit.options for this model: every card that counts (recommended: the model is bigger than any one card, so each card adds
+ experts that stay off the CPU), and the largest card alone. Same keys as gpu_fit.options."""
+ mine, others = gpu_fit.for_vendor(list(cards or []), vendor) if vendor else (list(cards or []), [])
+ keep, ignored = gpu_fit.usable_cards(mine)
+ keep = [c for c in keep if float(c.get("vram_gb") or 0) >= SMALLEST_CARD_GB]
+ out: dict[str, Any] = {"options": [], "recommended": None, "ignored": ignored, "cards": len(keep), "vendor": vendor,
+ "other_vendor_note": gpu_fit.other_vendor_note(list(cards or []), vendor)}
+ if not keep:
+ return out
+ opts = [_option("all", sorted(keep, key=lambda c: c.get("index", 0)), ram_gb, context, vendor)]
+ if len(keep) > 1:
+ opts.append(_option("single", [keep[0]], ram_gb, context, vendor))
+ opts[0]["recommended"] = True
+ out["options"], out["recommended"] = opts, "all"
+ return out
diff --git a/tests/terminal/test_launch.py b/tests/terminal/test_launch.py
index 18fd91bd8..f7a83280b 100644
--- a/tests/terminal/test_launch.py
+++ b/tests/terminal/test_launch.py
@@ -109,6 +109,9 @@ class CatalogRules(unittest.TestCase):
models, families, contexts, source = cat.tables()
self.assertEqual(source, "setup.py") # the same tables setup.py and the app read
for r in rows:
+ if r.family == "deepseek41": # its one size is in MULTI_FILE_FAMILIES (nine shards), not in MODELS
+ self.assertAlmostEqual(r.download_gb, 508.4)
+ continue
self.assertAlmostEqual(r.download_gb, models[r.model]["download_gb"])
rec = [r for r in rows if r.recommended]
self.assertEqual([(r.family, r.model) for r in rec], [("qwen", "IQ3_S")]) # 64 + 12 GB: the 64 GB tier
diff --git a/tests/terminal/test_launch_dsv41.py b/tests/terminal/test_launch_dsv41.py
new file mode 100644
index 000000000..0aae41d97
--- /dev/null
+++ b/tests/terminal/test_launch_dsv41.py
@@ -0,0 +1,166 @@
+"""`strata launch` for DeepSeek-V4.1-Flash: the model is in the list, `--plan` says where it goes on this computer's cards (the real
+numbers of strata_control/dsv41_fit.py), `--model-path` takes the nine shards where they are, and the settings that cannot apply
+(parallel requests, pictures, tuning) are said instead of passed to an engine that would refuse them. Nothing is downloaded or started."""
+
+from __future__ import annotations
+
+import json
+import os
+import unittest
+from pathlib import Path
+from unittest import mock
+
+from strata_cli.launch import settings as S
+from strata_cli.launch.catalog import Catalog
+from strata_cli.launch.runner import LaunchError, Runner
+from tests.terminal.launch_support import HW_12, Home, catalog, run_cli
+
+R9700 = {"name": "AMD Radeon AI PRO R9700", "vram_gb": 32.0, "usable": True, "vendor": "amd"}
+HW_4X32 = {**HW_12, "ram_gb": 251.0, "disk_free_gb": 900.0, "engine_vendor": "amd",
+ "gpus": [{**R9700, "index": i} for i in range(4)]}
+
+
+class LaunchDeepSeek(unittest.TestCase):
+ def setUp(self):
+ self.home = Home().__enter__()
+ self.addCleanup(self.home.__exit__, None, None, None)
+ self.hw = dict(HW_4X32)
+ p = mock.patch.object(Catalog, "hardware", lambda s, fresh=False: dict(self.hw))
+ p.start()
+ self.addCleanup(p.stop)
+
+ def plan(self, *args):
+ code, out, err = run_cli(["launch", "--plan", "--output", "json", *args])
+ self.assertEqual(code, 0, err + out)
+ return json.loads(out)["plan"]
+
+ def test_the_model_is_in_the_list(self):
+ rows = [r for r in catalog(self.hw).rows() if r.family == "deepseek41"]
+ self.assertEqual([r.model for r in rows], ["UD-Q8_K_XL"])
+ r = rows[0]
+ self.assertEqual((r.id, r.download_gb, r.verdict, r.images), ("deepseek-v4.1-flash-ud-q8_k_xl", 508.4, "fits", False))
+ self.assertEqual(catalog(self.hw).resolve("ud-q8_k_xl"), ("deepseek41", "UD-Q8_K_XL"))
+ self.assertEqual(catalog(self.hw).max_context("deepseek41", "UD-Q8_K_XL"), 8192)
+
+ def test_the_plan_places_the_model_on_the_four_cards(self):
+ p = self.plan("--model", "ud-q8_k_xl", "--no-tui")
+ pl = p["placement"]
+ self.assertEqual(p["settings"]["family"], "deepseek41")
+ self.assertEqual(p["settings"]["context"], 8192)
+ self.assertEqual(p["settings"]["tune"], "skip")
+ self.assertEqual(p["settings"]["vision"], "off")
+ self.assertEqual(pl["verdict"], "fits")
+ self.assertEqual([c["layers"] for c in pl["cards"]], [[0, 9], [10, 19], [20, 29], [30, 39]])
+ self.assertEqual(pl["args"], ["--tp", "2"])
+ # measured on this very computer: 6,197 experts (116.5 GB) in graphics memory, 9,163 (172.3 GB) on the CPU
+ self.assertAlmostEqual(pl["experts_in_vram"], 6197, delta=100)
+ self.assertAlmostEqual(pl["cpu_experts_gb"], 172.3, delta=2.5)
+ text = " ".join(pl["lines"])
+ self.assertIn("n-gram table", text)
+ self.assertIn("stays on the SSD", text)
+ self.assertIn("508 GB", text)
+
+ def test_the_human_plan_shows_the_placement(self):
+ code, out, err = run_cli(["launch", "--plan", "--model", "ud-q8_k_xl", "--no-tui"])
+ self.assertEqual(code, 0, err)
+ self.assertIn("placement", out)
+ self.assertIn("4 cards, one block of layers on each", out)
+ self.assertIn("n-gram table", out)
+ self.assertIn("Nothing was changed.", out)
+
+ def test_named_cards_are_the_ones_planned(self):
+ p = self.plan("--model", "ud-q8_k_xl", "--gpu", "0,1")
+ self.assertEqual([c["index"] for c in p["placement"]["cards"]], [0, 1])
+ self.assertLess(p["placement"]["experts_in_vram"], 3000)
+
+ def test_a_small_computer_gets_the_warnings_not_a_refusal(self):
+ self.hw = {**HW_12, "ram_gb": 64.0, "disk_free_gb": 100.0, "engine_vendor": "nvidia"}
+ code, out, err = run_cli(["launch", "--plan", "--model", "ud-q8_k_xl", "--no-tui"])
+ self.assertEqual(code, 0, err)
+ self.assertIn("read from the SSD", out)
+ self.assertIn("free disk space", out)
+ self.assertIn("It is still allowed", out)
+ row = next(r for r in catalog(self.hw).rows() if r.family == "deepseek41")
+ self.assertEqual(row.verdict, "no") # "too big (can still try)": the plan above is printed and nothing is refused
+
+ def test_no_card_is_said(self):
+ self.hw = {**HW_12, "gpus": []}
+ code, out, err = run_cli(["launch", "--plan", "--model", "ud-q8_k_xl", "--no-tui"])
+ self.assertEqual(code, 0, err)
+ self.assertIn("No graphics card", out)
+
+ def test_parallel_pictures_and_tuning_are_not_passed_on(self):
+ p = self.plan("--model", "ud-q8_k_xl", "--parallel", "4", "--vision", "on", "--tune", "quick")
+ s = p["settings"]
+ self.assertFalse(s.get("parallel"))
+ self.assertEqual((s["vision"], s["tune"]), ("off", "skip"))
+ text = " ".join(p["warnings"])
+ self.assertIn("one request at a time", text)
+ self.assertIn("cannot read pictures", text)
+ self.assertIn("Tuning is not offered", text)
+
+ def test_setup_is_asked_for_the_family_and_the_files(self):
+ s = S.LaunchSettings(family="deepseek41", model="UD-Q8_K_XL", context=8192, vision="off", tune="skip",
+ model_path="/data/ds")
+ args = Runner(s, catalog=catalog(self.hw)).setup_args()
+ self.assertEqual(args[:6], ["--yes", "--no-start", "--family", "deepseek41", "--model", "UD-Q8_K_XL"])
+ self.assertIn("--gguf-dir", args)
+ self.assertNotIn("--parallel", args)
+ self.assertIsNone(Runner(s, catalog=catalog(self.hw)).catalog_parallel())
+
+
+class OwnShards(unittest.TestCase):
+ def setUp(self):
+ self.home = Home().__enter__()
+ self.addCleanup(self.home.__exit__, None, None, None)
+ self.hw = dict(HW_4X32)
+ p = mock.patch.object(Catalog, "hardware", lambda s, fresh=False: dict(self.hw))
+ p.start()
+ self.addCleanup(p.stop)
+
+ def folder(self, shards=range(1, 10), nested=False):
+ base = Path(os.environ["STRATA_INSTALL_DIR"]) / "ds"
+ folder = base / "UD-Q8_K_XL" if nested else base
+ folder.mkdir(parents=True, exist_ok=True)
+ for i in shards:
+ (folder / f"DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-{i:05d}-of-00009.gguf").write_bytes(b"GGUF")
+ return base, folder
+
+ def runner(self, path):
+ return Runner(S.LaunchSettings(model_path=str(path)), catalog=catalog(self.hw))
+
+ def test_a_folder_of_the_nine_shards_is_the_model(self):
+ _base, folder = self.folder()
+ r = self.runner(folder)
+ r.check_own_files()
+ self.assertEqual((r.s.family, r.s.model, r.s.model_path), ("deepseek41", "UD-Q8_K_XL", str(folder)))
+
+ def test_the_repository_folder_with_the_size_inside(self):
+ base, folder = self.folder(nested=True)
+ r = self.runner(base)
+ r.check_own_files()
+ self.assertEqual((r.s.family, r.s.model, r.s.model_path), ("deepseek41", "UD-Q8_K_XL", str(folder)))
+
+ def test_one_shard_names_its_folder(self):
+ _base, folder = self.folder()
+ r = self.runner(folder / "DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00003-of-00009.gguf")
+ r.check_own_files()
+ self.assertEqual(r.s.model_path, str(folder))
+
+ def test_a_missing_shard_is_said_before_anything_is_downloaded(self):
+ _base, folder = self.folder(shards=[1, 2, 3, 5, 6, 7, 8, 9])
+ with self.assertRaises(LaunchError) as cm:
+ self.runner(folder).check_own_files()
+ self.assertIn("nine parts", cm.exception.text)
+ self.assertIn("00004-of-00009", cm.exception.text)
+
+ def test_the_plan_with_own_files_downloads_nothing(self):
+ _base, folder = self.folder()
+ code, out, err = run_cli(["launch", "--plan", "--model-path", str(folder), "--no-tui"])
+ self.assertEqual(code, 0, err + out)
+ self.assertIn("DeepSeek-V4.1-Flash", out)
+ self.assertIn("Nothing to download", out)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/strata_mcp.py b/tools/strata_mcp.py
index c863e3b41..3bb1c3a94 100644
--- a/tools/strata_mcp.py
+++ b/tools/strata_mcp.py
@@ -544,11 +544,25 @@ class Strata:
for f, d in (getattr(s, "OWN_PATH_FAMILIES", None) or {}).items():
out[f] = {"title": d["title"], "about": d.get("about"), "tag": d["tag"], "license": d.get("license"),
"vision": bool(d.get("vision", True)), "own_path": True}
+ for f, d in (getattr(s, "MULTI_FILE_FAMILIES", None) or {}).items(): # DeepSeek-V4.1-Flash: nine shards, its own engine
+ out[f] = {"title": d["title"], "about": d.get("about"), "tag": d["tag"], "license": d.get("license"),
+ "vision": bool(d.get("vision", False)), "own_path": True, "multi_file": True}
return out
+ def multi_family(self, family) -> dict | None:
+ """setup.py's MULTI_FILE_FAMILIES entry (DeepSeek-V4.1-Flash), else None."""
+ return (getattr(self.setup_module(), "MULTI_FILE_FAMILIES", None) or {}).get(family)
+
def own_size(self, family, model) -> dict | None:
"""One size of an own-path family as a model-table row for install_plan / model_table (None: not an own-path size).
The download is the GGUF; the picture reader (mmproj, ~0.9 GB) is counted by the plan when pictures are on."""
+ big = self.multi_family(family)
+ if big and model in big["models"]:
+ # nine shards; the memory the weights need is VRAM + RAM together WITHOUT the n-gram table (it stays on the SSD)
+ gb = sum(big["sha256"][n][0] for n in big["models"][model]["shards"]) / 1e9
+ return {"about": big["models"][model]["about"], "download_gb": round(gb, 1), "ram_gb": big["models"][model]["ram_gb"],
+ "arena_gb": round(float(big["models"][model]["ram_gb"]) - 17.0, 1), "mem_total": True, "vision": False,
+ "engine": None, "families": (family,), "multi_file": True}
d = (getattr(self.setup_module(), "OWN_PATH_FAMILIES", None) or {}).get(family)
if not d or model not in d["models"]:
return None
@@ -560,7 +574,7 @@ class Strata:
def sizes_of(self, models, family) -> list:
"""The family's sizes as setup lists them: an experimental one last (never the default)."""
- own = (getattr(self.setup_module(), "OWN_PATH_FAMILIES", None) or {}).get(family)
+ own = (getattr(self.setup_module(), "OWN_PATH_FAMILIES", None) or {}).get(family) or self.multi_family(family)
if own:
return list(own["models"])
return sorted((m for m in models if family in models[m].get("families", ("qwen", "swift"))),
@@ -1173,7 +1187,9 @@ class Strata:
have_gb = ram + vram if d.get("mem_total") else ram # Gyro: VRAM and RAM together
verdict = "fits" if have_gb >= d["ram_gb"] else "tight" if have_gb >= d["ram_gb"] - 8 else "does not fit"
try:
- if own: # its own engine path: no budget or low-RAM mode of Flash-Next's to judge by
+ if own and own.get("multi_file"): # DeepSeek-V4.1-Flash: strata_control/dsv41_fit.py (cards + RAM, the n-gram table on the SSD)
+ verdict = self.dsv41_words(hw)
+ elif own: # its own engine path: no budget or low-RAM mode of Flash-Next's to judge by
pass
elif d.get("budget") and S and hasattr(S, "unsloth_budget") and not S.unsloth_budget(m, ram):
verdict = ("experimental: " if d.get("experimental") else "") + "fits (all of its experts in RAM)"
@@ -1196,7 +1212,7 @@ class Strata:
"ram_needed_gb": d["ram_gb"], "experts_gb": d.get("arena_gb"),
# RAM + VRAM the weights need together, WITHOUT the n-gram table (that stays on the SSD): Gyro states it
# (mem_total), for the rest the experts plus ~1 GB for the dense part (Swift IQ2_XS: 35.5 + 1 = 36.5)
- "mem_total": bool(d.get("mem_total")),
+ "mem_total": bool(d.get("mem_total")), "multi_file": bool(own and own.get("multi_file")),
# the first engine that reads this size's files (setup.py "engine"); the app says "needs a newer engine"
# with the update step when the installed one is older. None: any engine that setup accepts.
"engine_min": ".".join(map(str, d["engine"])) if d.get("engine") else None,
@@ -1204,13 +1220,51 @@ class Strata:
"on_this_pc": verdict, "installed": tag in have, "id": tag,
# which graphics cards to use for it (strata_control/gpu_fit.py, the one rule app / Terminal / setup share):
# only with two or more cards that count; "recommended" names the pre-selected option
- "gpu_options": None if own else self.gpu_options(d, ram, hw)}) # Qwen3.6 runs on one card so far
+ "gpu_options": (self.dsv41_options(hw) if own and own.get("multi_file")
+ else None if own else self.gpu_options(d, ram, hw))}) # Qwen3.6 runs on one card so far
out.append({"family": f, "title": fd["title"], "about": fd.get("about"),
"experimental": bool(fd.get("experimental")),
"images": any(x["images"] for x in sizes) if sizes else fd.get("vision", True) is not False,
"sizes": sizes})
return out
+ def dsv41_plan(self, hw, disk_free=None, only=None) -> dict:
+ """strata_control/dsv41_fit.plan for this computer; `only`: the card numbers a launch names (else every card that counts)."""
+ from strata_control import dsv41_fit
+ cards = list((hw or {}).get("gpus", []))
+ if only:
+ cards = [c for c in cards if int(c.get("index", -1)) in {int(i) for i in only}]
+ return dsv41_fit.plan(cards, (hw or {}).get("ram_gb"), disk_free, vendor=(hw or {}).get("engine_vendor"))
+
+ def dsv41_words(self, hw) -> str:
+ """The catalog's `on_this_pc` text for DeepSeek-V4.1-Flash (strata_cli/launch/catalog.verdict reads its first words)."""
+ pl = self.dsv41_plan(hw)
+ v = pl["verdict"]
+ if v == "no_card":
+ return "does not fit: it needs one or more graphics cards"
+ if v == "spills" and pl["spill_gb"] >= 100: # most of the CPU's experts would come from the disk every word
+ return (f"does not fit: about {pl['spill_gb']:.0f} GB of its experts would be read from the SSD while it answers "
+ f"(slow: it needs ~{pl['ram_needed_gb']:.0f} GB of RAM beside {pl['vram_experts_gb']:.0f} GB of graphics memory; "
+ "it can still be installed)")
+ if v == "spills":
+ return (f"part of its experts are read from the SSD (slow here: needs ~{pl['ram_needed_gb']:.0f} GB of RAM beside "
+ f"{pl['vram_experts_gb']:.0f} GB of graphics memory; it can still be installed)")
+ if v == "tight":
+ return f"tight: RAM is close to the {pl['ram_needed_gb']:.0f} GB the CPU's share of the experts needs"
+ if v == "fits":
+ return (f"fits: {pl['experts_in_vram']:,} of {pl['experts_total']:,} experts in graphics memory, the rest on the CPU "
+ f"({pl['ram_needed_gb']:.0f} GB of RAM)")
+ return "not checked (this computer's memory could not be read)"
+
+ def dsv41_options(self, hw) -> dict | None:
+ """gpu_fit-shaped card choices for DeepSeek-V4.1-Flash: every card (recommended: the model is bigger than any one card), or the
+ largest alone; each with the placement words."""
+ from strata_control import dsv41_fit
+ try:
+ return dsv41_fit.options(list((hw or {}).get("gpus", [])), (hw or {}).get("ram_gb"), (hw or {}).get("engine_vendor"))
+ except Exception: # noqa: BLE001 - the choice is a convenience: never break the model list
+ return None
+
@staticmethod
def images_reader(vram) -> str:
try:
@@ -1362,6 +1416,10 @@ def expected_files(S, family: str, model: str, models_dir: Path, vision: bool) -
Empty when the setup module cannot say (the caller then falls back to the folder scan)."""
out = []
try:
+ big = (getattr(S, "MULTI_FILE_FAMILIES", None) or {}).get(family)
+ if big: # DeepSeek-V4.1-Flash: its nine shards in the model's folder
+ folder = Path(models_dir) / (big["tag"] + model)
+ return [{"path": str(folder / n), "bytes": big["sha256"][n][0], "role": "model"} for n in big["models"][model]["shards"]]
own = (getattr(S, "OWN_PATH_FAMILIES", None) or {}).get(family)
if own: # Qwen3.6: the GGUF and the picture reader in the model's folder
folder = Path(models_dir) / (own["tag"] + model)
@@ -2022,6 +2080,8 @@ class Tools:
raise ToolError(f"{model} does not fit this Mac: {rec['why']}")
gpu = gpus = kv = low_ram = None
context = context or (s.mac().recommend_context(hw.get("ram_gb") or 0) if s.mac() else 32768)
+ if context is None and md.get("multi_file"):
+ context = getattr(s.setup_module(), "DSV41_CONTEXT", 8192) # the context the engine was checked at
if context is None:
usable = s.engine_gpus(hw)
vram = max((g["vram_gb"] for g in usable), default=12)
@@ -2066,7 +2126,9 @@ class Tools:
args += ["--backend", backend]
fit = None
ram = hw.get("ram_gb")
- if ram is not None:
+ if ram is not None and md.get("multi_file"):
+ fit = s.dsv41_words(hw)
+ elif ram is not None:
need_ram = md["ram_gb"]
fit = "fits" if ram >= need_ram else f"needs ~{need_ram} GB of RAM, this PC has {ram:.0f} GB"
installed = (s.root / f"strata-{tag.lower()}.json").exists()
diff --git a/tools/test_setup_dsv41.py b/tools/test_setup_dsv41.py
new file mode 100644
index 000000000..7b403c89b
--- /dev/null
+++ b/tools/test_setup_dsv41.py
@@ -0,0 +1,311 @@
+"""Tests for DeepSeek-V4.1-Flash in setup.py (MULTI_FILE_FAMILIES: nine pinned shards, its own engine strata-dsv41, several cards) and
+for strata_control/dsv41_fit.py (where it fits, from the real numbers). Mocked engine, downloads and processes - nothing is built,
+fetched or started.
+
+ python -m unittest tools.test_setup_dsv41
+"""
+from __future__ import annotations
+
+import argparse
+import contextlib
+import io
+import json
+import re
+import sys
+import tempfile
+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 strata_control import dsv41_fit # noqa: E402
+
+SHA = re.compile(r"/resolve/[0-9a-f]{40}/")
+REPO = "unsloth/DeepSeek-V4.1-Flash-1017-GGUF"
+R9700 = {"name": "AMD Radeon AI PRO R9700", "vram_gb": 32.0, "vendor": "amd"}
+FOUR = [{**R9700, "index": i} for i in range(4)]
+
+
+def args(**kw):
+ base = dict(family="deepseek41", model=None, check=False, yes=True, vision=None, models_dir=None, gguf_dir=None, context=None,
+ rope_scaling=None, rope_scale=None, kv=None, resident_budget_gib=None, low_ram="auto", vram_reserve_mib=None,
+ host=None, api_key=None, browser=None, no_start=True, data_dir=None, gpu=None, gpus=None)
+ base.update(kw)
+ return argparse.Namespace(**base)
+
+
+def run(fn, *a, **kw):
+ out = io.StringIO()
+ with contextlib.redirect_stdout(out):
+ try:
+ return fn(*a, **kw), out.getvalue()
+ except SystemExit as e:
+ return e.code, out.getvalue()
+
+
+class Entries(unittest.TestCase):
+ def test_pinned_and_hashed(self):
+ fam = setup.MULTI_FILE_FAMILIES["deepseek41"]
+ self.assertEqual(setup.HF_REVISIONS[REPO], "f924b94f19c1fea02c06a65c8475b0a45e2b88b1")
+ self.assertRegex(fam["hf"], SHA)
+ self.assertTrue(fam["hf"].endswith(f"{REPO}/resolve/f924b94f19c1fea02c06a65c8475b0a45e2b88b1/UD-Q8_K_XL/"))
+ self.assertIs(setup.REPO_PINS[REPO], setup.DSV41_FILES)
+ shards = fam["models"]["UD-Q8_K_XL"]["shards"]
+ self.assertEqual(len(shards), 9)
+ self.assertEqual(sum(setup.DSV41_FILES[n][0] for n in shards), 508_376_763_197) # the nine shards: the pinned total
+ self.assertEqual(setup.DSV41_FILES[shards[7]][0], dsv41_fit.ENGRAM_BYTES) # shard 8 is the n-gram table
+ for n, (size, sha) in setup.DSV41_FILES.items():
+ self.assertRegex(sha, r"^[0-9a-f]{64}$", n)
+ self.assertGreater(size, 5e6)
+ self.assertEqual(setup.DSV41_FILES["mmproj-BF16.gguf"][0], 972_208_288)
+
+ def test_not_a_pack_or_single_file_family(self):
+ self.assertNotIn("deepseek41", setup.FAMILIES)
+ self.assertNotIn("deepseek41", setup.OWN_PATH_FAMILIES)
+ self.assertNotIn("UD-Q8_K_XL", setup.MODELS)
+
+ def test_config_read_back(self):
+ with tempfile.TemporaryDirectory() as d:
+ p = Path(d) / "strata-deepseek-v4.1-flash-ud-q8_k_xl.json"
+ p.write_text(json.dumps({"args": ["--pack", "x", "--max-context", "8192", "--tp", "2"], "port": 8080, "gpu": [0, 1, 2, 3]}))
+ ch = setup.choices_from_config(p)
+ self.assertEqual((ch["family"], ch["model"], ch["context"], ch["gpu"]), ("deepseek41", "UD-Q8_K_XL", 8192, [0, 1, 2, 3]))
+
+
+class Fit(unittest.TestCase):
+ def test_the_numbers_of_the_model(self):
+ self.assertAlmostEqual(dsv41_fit.WEIGHTS_GB, 305.6, delta=0.1)
+ self.assertAlmostEqual(dsv41_fit.EXPERTS_GB, 288.8, delta=0.1)
+ self.assertAlmostEqual(dsv41_fit.ENGRAM_GB, 202.8, delta=0.1)
+ self.assertAlmostEqual(dsv41_fit.DOWNLOAD_GB, 508.4, delta=0.1)
+ self.assertEqual(dsv41_fit.EXPERTS, 15360)
+
+ def test_four_r9700_match_the_measured_run(self):
+ # r9700, 2026-10-20: 1,558 + 1,559 + 1,575 + 1,505 = 6,197 experts in graphics memory, 9,163 (172.3 GB) on the CPU lane
+ p = dsv41_fit.plan(FOUR, 251.0, 900.0)
+ self.assertEqual(p["verdict"], "fits")
+ self.assertAlmostEqual(p["experts_in_vram"], 6197, delta=100)
+ self.assertAlmostEqual(p["cpu_experts_gb"], 172.3, delta=2.5)
+ self.assertEqual([c["layers"] for c in p["cards"]], [[0, 9], [10, 19], [20, 29], [30, 39]])
+ self.assertEqual(p["args"], ["--tp", "2"])
+ self.assertTrue(p["disk_ok"])
+
+ def test_one_card_and_little_ram_are_warnings(self):
+ p = dsv41_fit.plan([{**R9700, "index": 0}], 64.0, 100.0)
+ self.assertEqual(p["verdict"], "spills")
+ self.assertEqual(p["args"], [])
+ self.assertGreater(p["spill_gb"], 200)
+ text = " ".join(p["warnings"])
+ self.assertIn("read from the SSD", text)
+ self.assertIn("free disk space", text)
+ self.assertIn("still allowed", text)
+ self.assertFalse(p["disk_ok"])
+
+ def test_a_card_too_small_for_the_dense_weights_is_said(self):
+ p = dsv41_fit.plan([{"index": 0, "name": "RTX 3060", "vram_gb": 12.0}], 128.0)
+ self.assertTrue(any("dense weights" in w for w in p["warnings"]))
+
+ def test_no_card(self):
+ p = dsv41_fit.plan([], 128.0)
+ self.assertEqual(p["verdict"], "no_card")
+ self.assertTrue(any("No graphics card" in w for w in p["warnings"]))
+
+ def test_cards_of_two_sizes_share_the_layers_in_proportion(self):
+ cards = [{**R9700, "index": 0}, {"name": "RTX A4000", "vram_gb": 16.0, "index": 1}]
+ p = dsv41_fit.plan(cards, 256.0)
+ a, b = p["cards"]
+ self.assertGreater(a["layers"][1] - a["layers"][0], b["layers"][1] - b["layers"][0])
+ self.assertEqual(b["layers"][1], 39)
+ self.assertGreater(a["experts"], b["experts"])
+
+ def test_split_layers_covers_every_layer(self):
+ for w in ([1, 1, 1, 1], [32, 16], [8, 8, 8], [32, 32, 16, 12, 12]):
+ r = dsv41_fit.split_layers(w)
+ self.assertEqual(r[0][0], 0)
+ self.assertEqual(r[-1][1], 39)
+ self.assertTrue(all(a[1] + 1 == b[0] for a, b in zip(r, r[1:])))
+
+ def test_options_like_gpu_fit(self):
+ o = dsv41_fit.options(FOUR, 251.0, "amd")
+ self.assertEqual(o["recommended"], "all")
+ self.assertEqual([x["key"] for x in o["options"]], ["all", "single"])
+ self.assertEqual(o["options"][0]["cards"], [0, 1, 2, 3])
+ self.assertTrue(o["options"][0]["recommended"])
+
+
+class Install(unittest.TestCase):
+ def setUp(self):
+ self.tmp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.tmp.cleanup)
+ self.root = Path(self.tmp.name)
+ self.calls = []
+ self.cfg = {}
+ self.exe = self.root / "engine" / ("strata-dsv41.exe" if setup.WIN else "strata-dsv41")
+ eng = self.root / "engine"
+
+ def engine_step(a, gpu, hip, amd, cuda_tk, vision):
+ self.calls.append(("engine", vision))
+ eng.mkdir(parents=True, exist_ok=True)
+ return self.root / "llama", eng, {"version": "0.2.2"}, ["/libs"], gpu, vision
+
+ def write_cfg(path, cfg, source=None, explicit=None):
+ self.cfg = cfg
+ self.calls.append(("config", path.name))
+
+ patches = [mock.patch.object(setup, "download", lambda url, dst, what=None: self.calls.append(("get", url, dst))),
+ mock.patch.object(setup, "verify_sha256", lambda s, size, sha, own=False: self.calls.append(("sha", s.name, own))),
+ mock.patch.object(setup, "free_gb", lambda p: 900.0),
+ mock.patch.object(setup, "pip_install", lambda *a, **k: None),
+ mock.patch.object(setup, "engine_step", engine_step),
+ mock.patch.object(setup, "run", lambda cmd, **k: self.calls.append(("run", cmd))),
+ mock.patch.object(setup, "data_folder", lambda d, *a, **k: (self.root / "data", [])),
+ mock.patch.object(setup, "write_setup_config", write_cfg),
+ mock.patch.object(setup, "write_run_script", lambda tag, p, port, o=True: self.root / f"run-{tag}.sh"),
+ mock.patch.object(setup, "ROOT", self.root),
+ mock.patch.object(setup, "home", lambda: self.root)]
+ for p in patches:
+ p.start()
+ self.addCleanup(p.stop)
+ mock.patch.dict("os.environ", {"STRATA_DSV41_EXE": ""}).start()
+ self.addCleanup(mock.patch.stopall)
+
+ def install(self, ram=251.0, cards=None, engine=True, **kw):
+ if engine:
+ self.exe.parent.mkdir(parents=True, exist_ok=True)
+ self.exe.write_text("x")
+ cards = cards or FOUR
+ gpu = {"index": 0, "count": len(cards), "vram_gb": 32.0, "name": "R9700", "cards": cards}
+ return run(setup.install_dsv41, args(models_dir=str(self.root / "models"), **kw), "deepseek41", gpu, True, [], 13, [], 8080, ram,
+ None, cards)
+
+ def test_installs_the_nine_pinned_shards_and_writes_the_config(self):
+ rc, out = self.install()
+ self.assertEqual(rc, 0, out)
+ get = [c for c in self.calls if c[0] == "get"]
+ folder = self.root / "models" / "deepseek-v4.1-flash-UD-Q8_K_XL"
+ self.assertEqual([c[2] for c in get], [folder / setup.DSV41_SHARD.format(i=i) for i in range(1, 10)])
+ self.assertEqual(get[1][1], setup.hf(REPO) + "UD-Q8_K_XL/" + setup.DSV41_SHARD.format(i=2))
+ self.assertEqual(sum(1 for c in self.calls if c[0] == "sha"), 9)
+ pack = [c for c in self.calls if c[0] == "run"][-1][1]
+ self.assertIn("pack_gguf.py", " ".join(map(str, pack)))
+ self.assertEqual(self.cfg["arch"], "deepseek41")
+ self.assertEqual(self.cfg["exe"], str(self.exe))
+ self.assertEqual(self.cfg["model_name"], "deepseek-v4.1-flash")
+ a = self.cfg["args"]
+ self.assertEqual(a[a.index("--max-context") + 1], "8192")
+ self.assertEqual(a[a.index("--eos") + 1], "1")
+ self.assertEqual(a[a.index("--tp") + 1], "2")
+ self.assertTrue(Path(a[a.index("--pack") + 1]).match("*packs/deepseek-v4.1-flash-ud-q8_k_xl"))
+ self.assertEqual(self.cfg["gpu"], [0, 1, 2, 3])
+ self.assertEqual(self.cfg["backend"], "hip")
+ self.assertTrue(self.cfg["tokenizer"].endswith("tokenizer"))
+ self.assertNotIn("--vision", a)
+ self.assertNotIn("--mtp", a)
+ self.assertIn("4 cards, one block of layers on each", out)
+ self.assertIn("n-gram table", out)
+
+ def test_no_engine_stops_before_the_download(self):
+ rc, out = self.install(engine=False)
+ self.assertEqual(rc, 1, out)
+ self.assertIn("no DeepSeek-V4.1 engine (strata-dsv41)", out)
+ self.assertIn("nothing has been downloaded", out)
+ self.assertFalse([c for c in self.calls if c[0] == "get"])
+
+ def test_own_files_are_checked_not_downloaded(self):
+ own = self.root / "own"
+ own.mkdir()
+ for i in range(1, 10):
+ (own / setup.DSV41_SHARD.format(i=i)).write_bytes(b"GGUF")
+ rc, out = self.install(gguf_dir=str(own))
+ self.assertEqual(rc, 0, out)
+ self.assertFalse([c for c in self.calls if c[0] == "get"])
+ self.assertTrue(all(c[2] for c in self.calls if c[0] == "sha")) # own=True: setup never deletes the person's file
+ pack = [c for c in self.calls if c[0] == "run"][-1][1]
+ self.assertIn(str(own), pack)
+
+ def test_a_missing_own_shard_is_said(self):
+ own = self.root / "own"
+ own.mkdir()
+ for i in (1, 2, 3):
+ (own / setup.DSV41_SHARD.format(i=i)).write_bytes(b"GGUF")
+ rc, out = self.install(gguf_dir=str(own))
+ self.assertEqual(rc, 1, out)
+ self.assertIn("00004-of-00009.gguf is missing", out)
+
+ def test_the_repository_layout_is_found(self):
+ own = self.root / "repo"
+ (own / "UD-Q8_K_XL").mkdir(parents=True)
+ for i in range(1, 10):
+ (own / "UD-Q8_K_XL" / setup.DSV41_SHARD.format(i=i)).write_bytes(b"GGUF")
+ rc, out = self.install(gguf_dir=str(own))
+ self.assertEqual(rc, 0, out)
+ pack = [c for c in self.calls if c[0] == "run"][-1][1]
+ self.assertIn(str(own / "UD-Q8_K_XL"), pack)
+
+ def test_little_ram_is_asked_and_kept_with_an_explicit_model(self):
+ rc, out = self.install(ram=64.0, cards=FOUR[:1], model="UD-Q8_K_XL")
+ self.assertEqual(rc, 0, out)
+ self.assertIn("read from the SSD", out)
+ self.assertIn("installing UD-Q8_K_XL with 64 GB of RAM, as you chose", out)
+ self.assertEqual(self.cfg["args"][self.cfg["args"].index("--max-context") + 1], "8192")
+ self.assertNotIn("--tp", self.cfg["args"])
+
+ def test_little_ram_with_yes_alone_stops_where_the_rule_says(self):
+ rc, out = self.install(ram=64.0, cards=FOUR[:1])
+ self.assertEqual(rc, 1, out)
+ self.assertIn("more RAM or cards fix it", out)
+ self.assertFalse([c for c in self.calls if c[0] == "get"])
+
+ def test_a_disk_that_cannot_hold_the_files_is_the_one_hard_stop(self):
+ with mock.patch.object(setup, "free_gb", lambda p: 100.0):
+ rc, out = self.install()
+ self.assertEqual(rc, 1, out)
+ self.assertIn("not enough free disk space", out)
+ self.assertIn("an NVMe drive is best", out)
+ self.assertFalse([c for c in self.calls if c[0] == "get"])
+
+ def test_pictures_and_flash_next_settings_are_said(self):
+ rc, out = self.install(vision="yes", kv="int8", context=131072)
+ self.assertEqual(rc, 0, out)
+ self.assertIn("cannot read pictures in this Strata version", out)
+ self.assertIn("Flash-Next settings", out)
+ self.assertEqual(self.cfg["args"][self.cfg["args"].index("--max-context") + 1], "131072")
+ self.assertIn("checked at 4K and 8K", out)
+
+
+class Catalog(unittest.TestCase):
+ def test_the_mcp_catalog_lists_the_size(self):
+ import strata_mcp as M
+ s = M.Strata(ROOT)
+ fam = next(f for f in s.model_table({"ram_gb": 251.0, "gpus": [{**c, "usable": True} for c in FOUR], "engine_vendor": "amd"})
+ if f["family"] == "deepseek41")
+ (size,) = fam["sizes"]
+ self.assertEqual((size["model"], size["id"], size["download_gb"], size["images"]), ("UD-Q8_K_XL", "deepseek-v4.1-flash-ud-q8_k_xl", 508.4, False))
+ self.assertTrue(size["on_this_pc"].startswith("fits"))
+ self.assertTrue(size["mem_total"] and size["multi_file"])
+ self.assertEqual(size["gpu_options"]["recommended"], "all")
+ small = next(f for f in s.model_table({"ram_gb": 32.0, "gpus": []}) if f["family"] == "deepseek41")
+ self.assertTrue(small["sizes"][0]["on_this_pc"].startswith("does not fit"))
+
+ def test_the_install_plan(self):
+ import strata_mcp as M
+ s = M.Strata(ROOT)
+ s.hardware = lambda fresh=False: {"ram_gb": 251.0, "gpus": [{**c, "usable": True} for c in FOUR], "engine_vendor": "amd",
+ "cpu": {"avx2": True}}
+ s.disk_free = lambda p: 2000.0
+ plan, a = M.Tools(s).install_plan("deepseek41", "UD-Q8_K_XL", None, None, None, None, None, None, None, None, None)
+ self.assertEqual((plan["title"], plan["download_gb"], plan["context"], plan["images"]), ("DeepSeek-V4.1-Flash UD-Q8_K_XL", 508.4, 8192, "no"))
+ self.assertEqual(a[:6], ["--yes", "--no-start", "--family", "deepseek41", "--model", "UD-Q8_K_XL"])
+ self.assertTrue(plan["ram"].startswith("fits"))
+ for flag in ("--kv", "--low-ram", "--experimental-speed-projection"):
+ self.assertNotIn(flag, a)
+ files = M.expected_files(s.setup_module(), "deepseek41", "UD-Q8_K_XL", Path("/m"), False)
+ self.assertEqual(len(files), 9)
+ self.assertEqual(sum(f["bytes"] for f in files), 508_376_763_197)
+
+
+if __name__ == "__main__":
+ unittest.main()