Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
setup: DeepSeek's engine comes from the signed feed's dsv41 member (strata_control/dsv41_engine.py: same download, resume and verification as an engine update) into engine-dsv41/, beside the engine; the flat-zip route is dropped; tests
Niko12211d0a8051d593
diff --git a/setup.py b/setup.pyindex 5b23caf9b..569a9d42e 100644--- a/setup.py+++ b/setup.py@@ -7687,20 +7687,10 @@ def install_own_path(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adoptereturn start(cfg_path, port)-# DeepSeek's engine is its own package, downloaded when DeepSeek is chosen and unpacked in engine-dsv41/ beside the engine: the Qwen engine's-# files are never touched. Same places as the engine packages (--prebuilt / STRATA_PREBUILT_URL: a release folder, a mirror, a local folder),-# one asset for each kind of computer, and a <asset>.sha256 beside it (checked when it is there; a GitHub release without one is checked-# against the digest GitHub publishes, like the engine).+# DeepSeek's engine is its own package (feed member "dsv41", strata_control/dsv41_engine.py), downloaded when DeepSeek is chosen and unpacked in+# <data>/engine-dsv41/<version>-<platform>-<backend>/ beside the engine: the Qwen engine's files are never touched. Fetched, verified and+# resumed like an engine update (the signed feed; --feed / STRATA_UPDATE_FEED name another one, as for `strata update`).DSV41_ENGINE_DIR = "engine-dsv41"-DSV41_ENGINE_ASSETS = {"windows-cuda": "strata-dsv41-windows-x64-cuda13.zip", "linux-cuda": "strata-dsv41-linux-x64-cuda13.zip",- "linux-hip": "strata-dsv41-linux-x64-hip-gfx120x.zip"}---def dsv41_engine_asset(hip: bool) -> str | None:- """The DeepSeek engine package for this computer, None where there is none (Windows AMD, Mac, Intel)."""- if hip:- return None if WIN else DSV41_ENGINE_ASSETS["linux-hip"]- return DSV41_ENGINE_ASSETS["windows-cuda" if WIN else "linux-cuda"]def dsv41_engine_dir(eng: Path) -> Path:@@ -7708,63 +7698,22 @@ def dsv41_engine_dir(eng: Path) -> Path:return (home() if CONTROL else Path(eng).parent) / DSV41_ENGINE_DIR-def get_dsv41_engine(url_base, eng: Path, hip: bool) -> Path | None:- """Download, check and unpack the DeepSeek engine package next to the engine `eng`; the folder, or None when it cannot be had (no package- for this computer or version, no internet). Resumes like the model files (download()); the engine in `eng` is not touched."""- asset = dsv41_engine_asset(hip)- dest = dsv41_engine_dir(eng)- if asset is None or not url_base:- return None+def get_dsv41_engine(eng: Path, hip: bool) -> Path | None:+ """Download, check and unpack the DeepSeek engine package next to the engine `eng`; its strata-dsv41, or None when it cannot be had."""acquisition.require("the DeepSeek engine")- base = prebuilt_bases(url_base)[-1] if url_base != PREBUILT_URL else prebuilt_bases(url_base)[0]- work = dest.parent / (DSV41_ENGINE_DIR + ".download")- work.mkdir(parents=True, exist_ok=True)- z, side = work / asset, work / (asset + ".sha256")+ from strata_control import dsv41_engine+ from strata_cli import update_cmd+ root = dsv41_engine_dir(eng)+ source = update_cmd._feed_source(argparse.Namespace(feed=None), root.parent)say(" Downloading the DeepSeek engine (its own package, separate from the Strata engine) ...")- try:- download(base + asset, z, "DeepSeek engine")- except SystemExit:- warn(f"no DeepSeek engine package at {base} ({asset})")- return None- want = None- try:- download(base + asset + ".sha256", side, "its SHA-256")- want = side.read_text(encoding="utf-8", errors="replace").split()[0].lower()- except (SystemExit, OSError, IndexError):- side.unlink(missing_ok=True)- if want:- h = hashlib.sha256()- with open(z, "rb") as f:- for b in iter(lambda: f.read(8 << 20), b""):- h.update(b)- if h.hexdigest() != want:- drop_archive(z)- side.unlink(missing_ok=True)- fail(f"the downloaded {asset} does not match its SHA-256 (it was deleted)", "run setup again; if it keeps failing, the mirror's file is damaged")- ok(f"{asset} matches its SHA-256")- else:- try:- verify_engine_archive(z, asset, base)- except UnverifiedEngine as e:- drop_archive(z)- fail(f"the DeepSeek engine package was refused: {e}", "run setup again later")- tmp = work / "_unpack"- shutil.rmtree(tmp, ignore_errors=True)- with zipfile.ZipFile(z) as f:- f.extractall(tmp)- exe_name = "strata-dsv41.exe" if WIN else "strata-dsv41"- inner = tmp if (tmp / exe_name).is_file() else next((d for d in tmp.iterdir() if d.is_dir() and (d / exe_name).is_file()), None)- if inner is None:- shutil.rmtree(tmp, ignore_errors=True)- drop_archive(z)- fail(f"{asset} has no {exe_name}", "tell us: the package is wrong")- if not WIN:- (inner / exe_name).chmod(0o755)- shutil.rmtree(dest, ignore_errors=True)- shutil.move(str(inner), str(dest))- shutil.rmtree(work, ignore_errors=True)- ok(f"DeepSeek engine installed: {dest}")- return dest+ hw = None+ if hip:+ from strata_control import updater+ hw = {**updater.detect_hardware(), "backend": "hip", "backend_source": "requested"}+ exe = dsv41_engine.install(root, source, hardware=hw, emit=lambda m: say(" " + m))+ if exe is None:+ warn("no DeepSeek engine package could be fetched (see above)")+ return exedef dsv41_exe(eng: Path) -> Path | None:@@ -7774,9 +7723,8 @@ def dsv41_exe(eng: Path) -> Path | None:if own:return Path(own) if Path(own).is_file() else Nonename = "strata-dsv41.exe" if WIN else "strata-dsv41"- exe = dsv41_engine_dir(eng) / name- if not exe.is_file():- exe = Path(eng) / name+ from strata_control import dsv41_engine+ exe = dsv41_engine.find(dsv41_engine_dir(eng)) or (Path(eng) / name)if exe.is_file() and not WIN and not os.access(exe, os.X_OK): # a package copied without its modes (scp / tar from Windows): fix it, do not stoptry:exe.chmod(0o755)@@ -7972,7 +7920,7 @@ def install_dsv41(a, family, gpu, hip, amd, cuda_tk, multi, port, ram, adopted,llama, eng, meta, lib_dirs, gpu, _vision = engine_step(a, gpu, hip, amd, cuda_tk, "none")exe = dsv41_exe(eng)if exe is None and not getattr(a, "build", False):- get_dsv41_engine(getattr(a, "prebuilt", None), eng, hip)+ get_dsv41_engine(eng, hip)exe = dsv41_exe(eng)if exe is not None and exe.parent != Path(eng):lib_dirs = [*lib_dirs, str(exe.parent)] # its own package carries the libraries it needsdiff --git a/strata_control/dsv41_engine.py b/strata_control/dsv41_engine.pynew file mode 100644index 000000000..ecd247137--- /dev/null+++ b/strata_control/dsv41_engine.py@@ -0,0 +1,72 @@+"""DeepSeek-V4.1's engine as its own package (feed member ``dsv41``), downloaded when DeepSeek is chosen.++It goes in ``<data>/engine-dsv41/<version>-<platform>-<backend>[-<variant>]/``, beside the Strata engine and never inside it, so the Qwen+engine's files are not touched. The package is picked, downloaded (resumable), unpacked and checked with the same code as an engine update+(strata_control/updater.py: the signed feed, the archive's SHA-256, the manifest hash the feed names, the package signature, every file's hash);+there is no test start here (setup's own 16-token question follows the pack).+"""+from __future__ import annotations++import os+import shutil+from pathlib import Path+from typing import Callable++NAME = "strata-dsv41"+DIR = "engine-dsv41"+++def exe_name() -> str:+ return NAME + (".exe" if os.name == "nt" else "")+++def find(dest: Path) -> Path | None:+ """The newest installed package's strata-dsv41 in `dest` (engine-dsv41/), or None."""+ try:+ folders = sorted((d for d in Path(dest).iterdir() if d.is_dir() and (d / exe_name()).is_file()), key=lambda d: d.name)+ except OSError:+ return None+ return folders[-1] / exe_name() if folders else None+++def install(dest: Path, source: str, *, hardware: dict | None = None, emit: Callable[[str], None] = print, cancel=None) -> Path | None:+ """Fetch the DeepSeek engine package for this PC from the signed feed at `source` (a URL or a folder) into `dest`.+ Returns the new strata-dsv41, or None with a plain line through `emit` when there is none (not in the feed, nothing for this PC)."""+ from strata_control import feed as feedmod, signing, updater++ dest = Path(dest)+ work = dest.parent / (DIR + ".work")+ hw = hardware or updater.detect_hardware()+ state_dir = work / "state"+ state_dir.mkdir(parents=True, exist_ok=True)+ ctx = updater.Context(components=work, source=source, trusted=signing.load_trusted_keys(), hardware=hw, cancel=cancel,+ emit=lambda event: emit(event["message"]) if event.get("event") == "phase" and event.get("message") else None)+ state = updater.State(work)+ try:+ feed = updater.open_feed(ctx, state)+ pkg, reasons = feedmod.select_engine(list(feed.dsv41), hw)+ if pkg is None:+ emit("There is no DeepSeek engine package for this computer in the update feed"+ + (": " + "; ".join(reasons[:2]) if reasons else "") + ".")+ return None+ archive = updater._download(ctx, "dsv41", pkg.url, pkg.size, pkg.sha256, "the DeepSeek engine", feed)+ stage_root, component = updater.stage_engine(ctx, feed, pkg, archive)+ try:+ folder = stage_root / "engine" / updater.folder_name(pkg)+ dest.mkdir(parents=True, exist_ok=True)+ target = dest / folder.name+ shutil.rmtree(target, ignore_errors=True)+ shutil.move(str(folder), str(target))+ finally:+ shutil.rmtree(stage_root, ignore_errors=True)+ if os.name != "nt":+ (target / exe_name()).chmod(0o755)+ for old in dest.iterdir(): # one generation: the older folders of this engine go+ if old.is_dir() and old.name != target.name:+ shutil.rmtree(old, ignore_errors=True)+ emit(f"DeepSeek engine {pkg.version} installed: {target}")+ shutil.rmtree(work, ignore_errors=True) # (on a failure the partial download stays in `work`: the next try resumes it)+ return target / exe_name()+ except (updater.UpdateError, feedmod.FeedError, signing.SignatureError) as e:+ emit(f"The DeepSeek engine could not be fetched: {e}")+ return Nonediff --git a/tests/terminal/test_dsv41_engine.py b/tests/terminal/test_dsv41_engine.pynew file mode 100644index 000000000..634803260--- /dev/null+++ b/tests/terminal/test_dsv41_engine.py@@ -0,0 +1,134 @@+"""DeepSeek's engine as its own signed package (feed member ``dsv41``): fetched with resume, verified, unpacked beside the engine, and the+engine's own files are not touched. A local signed feed on a loopback server, a stub strata-dsv41, a throwaway key."""+from __future__ import annotations++import hashlib+import json+import os+import shutil+import sys+import tempfile+import unittest+from pathlib import Path+from unittest import mock++sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "packaging"))+import feed_tool # noqa: E402+import package_engine # noqa: E402+from strata_control import components, dsv41_engine, engine_component as ec, signing # noqa: E402+from strata_control.targets import host_platform # noqa: E402+from tests.terminal import update_fixture as fx # noqa: E402++EXE = dsv41_engine.exe_name()+++def build(parent: Path, version: str, key: dict, padding: int = 0) -> Path:+ src = parent / f"src-{version}"+ src.mkdir(parents=True)+ (src / EXE).write_bytes(b"stub strata-dsv41 " + (os.urandom(padding) if padding else b"x" * 100))+ library = "cudart64_13.dll" if os.name == "nt" else "libcudart.so.13"+ (src / library).write_bytes(b"a runtime library " * 50)+ out = parent / "built"+ out.mkdir(exist_ok=True)+ folder = package_engine.build(src, "cuda", version, components.host_platform(), out, entry=EXE, archs=("sm_86",),+ min_driver={"nvidia": "580.65"}, build_id=f"dsv41-{version}", variant="cuda13")+ feed_tool.sign_package(folder, key)+ return folder+++class Dsv41Engine(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory(prefix="strata-dsv41-eng-")+ self.addCleanup(self.tmp.cleanup)+ self.root = Path(self.tmp.name)+ self.key = fx.make_key()+ trust = self.root / "trust.json"+ trust.write_text(json.dumps({"keys": [signing.public_part(self.key)]}))+ for p in (mock.patch.dict(os.environ, {"STRATA_UPDATE_TRUSTED_KEYS": str(trust), "STRATA_COMPONENTS_DIR": str(self.root / "c")}),+ mock.patch.object(signing, "BUILTIN_KEYS", self.root / "none.json"),+ mock.patch.object(ec, "cuda_archs_present", return_value=["sm_86"]),+ mock.patch.object(ec, "nvidia_driver_version", return_value="610.47")):+ p.start()+ self.addCleanup(p.stop)+ self.addCleanup(ec.register_signature_verifier, None)+ self.hw = {"platform": host_platform(), "backend": "cuda", "runtime": None, "nvidia_driver": "610.47", "cuda_archs": ["sm_86"], "gfx": []}+ self.release = self.root / "release"+ self.release.mkdir()+ self.server = fx.FeedServer(self.release)+ self.server.__enter__()+ self.addCleanup(self.server.__exit__)+ self.eng = self.root / "data" / "engine" # a stand-in Qwen engine folder: its hash must not change+ self.eng.mkdir(parents=True)+ for n in ("strata", "BUILD.json"):+ (self.eng / n).write_bytes(os.urandom(500))+ self.before = self.tree(self.eng)++ @staticmethod+ def tree(d: Path) -> str:+ h = hashlib.sha256()+ for p in sorted(Path(d).rglob("*")):+ if p.is_file():+ h.update(p.name.encode() + p.read_bytes())+ return h.hexdigest()++ def publish(self, version="0.1.49", padding=0):+ shutil.rmtree(self.release, ignore_errors=True)+ (self.release / "dsv41").mkdir(parents=True)+ folder = build(self.root / f"pub-{version}", version, self.key, padding)+ feed_tool.pack_engine(folder, self.release / "dsv41", url_prefix="dsv41/")+ feed_tool.build_feed(self.release, key=self.key, sequence=1, dsv41_dir=self.release / "dsv41")++ def install(self, lines=None):+ out = [] if lines is None else lines+ return dsv41_engine.install(self.root / "data" / "engine-dsv41", self.server.url + "/strata-feed.json", hardware=self.hw, emit=out.append)++ def test_downloads_verifies_installs_beside_the_engine(self):+ self.publish()+ lines = []+ exe = self.install(lines)+ self.assertIsNotNone(exe, lines)+ self.assertEqual(exe.parent.parent, self.root / "data" / "engine-dsv41")+ self.assertTrue(exe.is_file())+ self.assertEqual(dsv41_engine.find(self.root / "data" / "engine-dsv41"), exe)+ self.assertEqual(self.tree(self.eng), self.before, "the Qwen engine's files must not change")+ self.assertFalse((self.root / "data" / "engine-dsv41.work").exists())++ def test_a_cut_download_resumes(self):+ self.publish(padding=3_000_000)+ name = next((self.release / "dsv41").glob("*.tar.gz")).name+ self.server.cut[name] = 800_000+ lines = []+ self.assertIsNone(self.install(lines)) # the connection broke part-way: said plainly, the partial file is kept+ self.assertIn("resumes", " ".join(lines))+ exe = self.install(lines) # the next try continues from the byte it reached+ self.assertIsNotNone(exe, lines)+ ranges = [r for r in self.server.requests if r[1].endswith(".tar.gz") and r[2] and r[2] != "bytes=0-"]+ self.assertTrue(ranges, self.server.requests)+ self.assertEqual(self.tree(self.eng), self.before)++ def test_no_package_for_this_pc_is_a_plain_line_not_a_crash(self):+ self.publish()+ self.hw = {**self.hw, "cuda_archs": ["sm_61"], "gfx": []}+ lines = []+ with mock.patch.object(ec, "cuda_archs_present", return_value=["sm_61"]):+ self.assertIsNone(self.install(lines))+ self.assertTrue(lines)+ self.assertEqual(self.tree(self.eng), self.before)++ def test_a_feed_signed_with_another_key_is_refused(self):+ self.publish()+ self.key = fx.make_key() # (the trust file still names the first key)+ shutil.rmtree(self.release / "dsv41")+ self.publish_other = None+ folder = build(self.root / "other", "0.1.50", self.key)+ (self.release / "dsv41").mkdir()+ feed_tool.pack_engine(folder, self.release / "dsv41", url_prefix="dsv41/")+ feed_tool.build_feed(self.release, key=self.key, sequence=2, dsv41_dir=self.release / "dsv41")+ lines = []+ self.assertIsNone(self.install(lines))+ self.assertIn("could not be fetched", " ".join(lines))+ self.assertFalse((self.root / "data" / "engine-dsv41").exists() and any((self.root / "data" / "engine-dsv41").iterdir()))+++if __name__ == "__main__":+ unittest.main()diff --git a/tools/test_setup_dsv41.py b/tools/test_setup_dsv41.pyindex 58f64bc03..31cfbda6a 100644--- a/tools/test_setup_dsv41.py+++ b/tools/test_setup_dsv41.py@@ -385,13 +385,7 @@ class OfficialSets(unittest.TestCase):class EnginePackage(unittest.TestCase):"""DeepSeek's engine is its own package beside the engine; the Qwen engine folder is never written."""- def test_asset_names_and_folder(self):- with mock.patch.object(setup, "WIN", True):- self.assertEqual(setup.dsv41_engine_asset(False), "strata-dsv41-windows-x64-cuda13.zip")- self.assertIsNone(setup.dsv41_engine_asset(True)) # Windows AMD: no package- with mock.patch.object(setup, "WIN", False):- self.assertEqual(setup.dsv41_engine_asset(False), "strata-dsv41-linux-x64-cuda13.zip")- self.assertEqual(setup.dsv41_engine_asset(True), "strata-dsv41-linux-x64-hip-gfx120x.zip")+ def test_the_package_folder_is_beside_the_engine(self):self.assertEqual(setup.dsv41_engine_dir(Path("/d/engine")), Path("/d") / "engine-dsv41")def test_the_own_package_is_found_before_the_old_place(self):@@ -402,9 +396,9 @@ class EnginePackage(unittest.TestCase):self.assertIsNone(setup.dsv41_exe(eng))(eng / name).write_text("old")self.assertEqual(setup.dsv41_exe(eng), eng / name) # an all-in-one engine still works- (Path(d) / "engine-dsv41").mkdir()- (Path(d) / "engine-dsv41" / name).write_text("new")- self.assertEqual(setup.dsv41_exe(eng), Path(d) / "engine-dsv41" / name)+ (Path(d) / "engine-dsv41" / "0.1.49-x").mkdir(parents=True)+ (Path(d) / "engine-dsv41" / "0.1.49-x" / name).write_text("new")+ self.assertEqual(setup.dsv41_exe(eng), Path(d) / "engine-dsv41" / "0.1.49-x" / name)class InstallOfficial(Install):