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

pack_gguf: an Engram file ('engram' or 'deepseek41-engram') is never taken for a model shard or for the model's metadata; real header fixture and tests; setup test: the first release's files are packed as they are with no shard download

Niko12214ebba2676751
diff --git a/tests/fixtures/dsv41/engram-final-header.gguf b/tests/fixtures/dsv41/engram-final-header.gguf
new file mode 100644
index 000000000..1a0d28f4c
Binary files /dev/null and b/tests/fixtures/dsv41/engram-final-header.gguf differ
diff --git a/tests/terminal/test_pack_gguf_engram.py b/tests/terminal/test_pack_gguf_engram.py
new file mode 100644
index 000000000..17848fa22
--- /dev/null
+++ b/tests/terminal/test_pack_gguf_engram.py
@@ -0,0 +1,60 @@
+"""pack_gguf must never take an Engram file's metadata for the model's: ISTA-DASLab's final Engram says general.architecture 'deepseek41-engram'
+(the first release's said 'engram'). The fixture is the real header of DeepSeek-V4.1-Flash-Engram-IQ4_NL.gguf (its 416 bytes: metadata and the tensor
+directory, no data)."""
+from __future__ import annotations
+
+import struct
+import sys
+import tempfile
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[2]
+sys.path.insert(0, str(ROOT / "tools" / "dsv41"))
+import pack_gguf as PG # noqa: E402
+
+FIXTURE = ROOT / "tests" / "fixtures" / "dsv41" / "engram-final-header.gguf"
+
+
+def tiny_gguf(path: Path, arch: str, extra: dict | None = None) -> Path:
+ """A GGUF with only metadata (string and uint32 values), no tensors."""
+ kv = {"general.architecture": arch, **(extra or {})}
+ out = bytearray(b"GGUF" + struct.pack("<IQQ", 3, 0, len(kv)))
+ for k, v in kv.items():
+ out += struct.pack("<Q", len(k)) + k.encode()
+ if isinstance(v, str):
+ out += struct.pack("<I", 8) + struct.pack("<Q", len(v)) + v.encode()
+ else:
+ out += struct.pack("<I", 4) + struct.pack("<I", v)
+ out += b"\0" * (-len(out) % 32)
+ path.write_bytes(bytes(out))
+ return path
+
+
+class EngramHeader(unittest.TestCase):
+ def test_the_real_final_engram_header_is_an_engram_file(self):
+ g = PG.Gguf(FIXTURE)
+ self.assertEqual(g.kv["general.architecture"], "deepseek41-engram")
+ self.assertTrue(PG.is_engram_file(g))
+ self.assertEqual(len(g.tensors), 2)
+ self.assertEqual(g.data_start, 416)
+
+ def test_it_is_never_the_group_the_model_metadata_comes_from(self):
+ with tempfile.TemporaryDirectory() as d:
+ d = Path(d)
+ shard = PG.Gguf(tiny_gguf(d / "model-00001-of-00004.gguf", "deepseek41", {"split.count": 4}))
+ engram = PG.Gguf(FIXTURE)
+ for order in ([engram, shard], [shard, engram]):
+ kv = PG.model_kv(order)
+ self.assertIsNotNone(kv)
+ self.assertEqual(kv["general.architecture"], "deepseek41")
+ self.assertIsNone(PG.model_kv([engram])) # an Engram alone is not a model
+
+ def test_the_first_releases_engram_is_one_too(self):
+ with tempfile.TemporaryDirectory() as d:
+ self.assertTrue(PG.is_engram_file(PG.Gguf(tiny_gguf(Path(d) / "e.gguf", "engram"))))
+ self.assertFalse(PG.is_engram_file(PG.Gguf(tiny_gguf(Path(d) / "m.gguf", "deepseek41"))))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/dsv41/pack_gguf.py b/tools/dsv41/pack_gguf.py
index b83e32b88..bf0bdd703 100644
--- a/tools/dsv41/pack_gguf.py
+++ b/tools/dsv41/pack_gguf.py
@@ -316,6 +316,17 @@ def short(g: Gguf):
return None if have >= need else "%s: %d of %d bytes" % (g.path.name, have, need)
+def is_engram_file(g) -> bool:
+ """The Engram table's GGUF: general.architecture 'engram' (the first release) or 'deepseek41-engram' (ISTA-DASLab's final files)."""
+ arch = str(g.kv.get("general.architecture") or "")
+ return arch == "engram" or arch.endswith("-engram")
+
+
+def model_kv(gs):
+ """The metadata of the model: of the first group whose architecture IS deepseek41 - never an Engram file's, whatever order they come in."""
+ return next((g.kv for g in gs if g.kv.get("general.architecture") == "deepseek41"), None)
+
+
def engram_set(model: pathlib.Path, explicit: str | None):
"""The Engram tables' GGUF set for a quant that leaves them out: (its folder, its files read), or (None, []).
explicit (--engram): that folder, whole; else the first whole one of ENGRAM_SETS beside the quant or in its
@@ -427,9 +438,15 @@ def main() -> int:
raise SystemExit("%s: no .gguf files" % model if not shards else
"%s: not there" % next(p for p in shards if not p.is_file()))
gs = [Gguf(p) for p in shards]
- kv = next((g.kv for g in gs if "general.architecture" in g.kv), None)
- if kv is None or kv["general.architecture"] not in ("deepseek41",):
- raise SystemExit("%s: not a DeepSeek-V4.1 GGUF (architecture %r)" % (model, kv and kv.get("general.architecture")))
+ if not a.shards: # a folder's *.gguf: the Engram table (architecture 'engram', today 'deepseek41-engram') is not a model shard
+ keep = [i for i, g in enumerate(gs) if not is_engram_file(g)]
+ shards, gs = [shards[i] for i in keep], [gs[i] for i in keep]
+ if not gs:
+ raise SystemExit("%s: no model shards (only an Engram table)" % model)
+ kv = model_kv(gs)
+ if kv is None:
+ arch = next((g.kv.get("general.architecture") for g in gs), None)
+ raise SystemExit("%s: not a DeepSeek-V4.1 GGUF (architecture %r)" % (model, arch))
split = int(kv.get("split.count", 1))
if split != len(shards):
counts = sorted({m.group(1) for m in (re.search(r"-of-(\d{5})\.gguf$", p.name) for p in shards) if m})
diff --git a/tools/test_setup_dsv41.py b/tools/test_setup_dsv41.py
index 6d951379f..c7b7446b4 100644
--- a/tools/test_setup_dsv41.py
+++ b/tools/test_setup_dsv41.py
@@ -512,6 +512,30 @@ class InstallOfficial(Install):
got = [c[2].name for c in self.calls if c[0] == "get"]
self.assertEqual(got, [f"DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XS-{i:05d}-of-00004.gguf" for i in range(1, 5)]) # only the four shards
+ def test_the_first_releases_files_are_used_as_they_are_nothing_is_downloaded_but_the_small_files(self):
+ own = self.root / "own"
+ sub = own / "2.00bpw"
+ sub.mkdir(parents=True)
+ for i in range(1, 5):
+ (sub / f"model-2.00bpw-{i:05d}-of-00004.gguf").write_bytes(b"GGUF")
+ (sub / "engram-IQ4_NL.gguf").write_bytes(b"E")
+ (own / "dspark").mkdir()
+ (own / "dspark" / setup.DSV41_DSPARK).write_bytes(b"D")
+ tiny = {n: (4, "0" * 64) for n in setup.DSV41_LEGACY_FILES if n.startswith("model-2.00bpw")}
+ tiny["engram-IQ4_NL.gguf"] = (1, "0" * 64)
+ tiny[setup.DSV41_DSPARK] = (1, "0" * 64)
+ with mock.patch.dict(setup.DSV41_ALL_FILES, tiny):
+ rc, out = self.install_ista(gguf_dir=str(own))
+ self.assertEqual(rc, 0, out)
+ got = [c[2].name for c in self.calls if c[0] == "get"]
+ self.assertEqual(got, [setup.DSV41_SHARD.format(i=1)]) # only the 5.8 MB metadata shard
+ pack = [c for c in self.calls if c[0] == "run"][-1][1]
+ shards = pack[pack.index("--shards") + 1:pack.index("--engram")]
+ self.assertEqual(shards, [f"model-2.00bpw-{i:05d}-of-00004.gguf" for i in range(1, 5)]) # packed from the files as they are
+ self.assertTrue(pack[pack.index("--engram") + 1].endswith("engram-IQ4_NL.gguf"))
+ self.assertIn("model", pack[pack.index("--model") + 1] + "model")
+ self.assertEqual(Path(pack[pack.index("--model") + 1]), sub)
+
def test_pack_info_profile_smoke_and_the_launch_flags(self):
rc, out = self.install_ista()
self.assertEqual(rc, 0, out)