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: a missing or short shard is named with its numbers before anything reads it
Léon Avic Simmons896586e36557
diff --git a/setup.py b/setup.pyindex e24da5339..2c30348f0 100644--- a/setup.py+++ b/setup.py@@ -36,6 +36,7 @@ import osimport platformimport reimport shutil+import structimport subprocessimport sysimport time@@ -400,12 +401,34 @@ def download(url, dst: Path, what=None):warn(f"download interrupted ({e}); retrying in 10 s ...")time.sleep(10)if total and part.stat().st_size != total:- fail(f"could not finish downloading {dst.name}", "check your internet connection and run it again")+ fail(f"could not finish downloading {dst.name}: {part.stat().st_size:,} bytes on disk, the server says {total:,}",+ "check your internet connection and run it again (the download resumes where it stopped)")part.replace(dst)mark(dst)ok(f"{what or dst.name} downloaded")+def check_shards(shards):+ """Every shard present and whole, or setup stops naming the file and the numbers. Whole means as long as+ its own tensor directory says (the header is read, the data is not): a truncated copy (--gguf-dir, a .part+ renamed by hand, a download finished by an older setup) otherwise passes as a model file and the engine+ fails much later, at the first tensor that runs past the end."""+ sys.path.insert(0, str(ROOT / "tools"))+ from gguf_reader import GGUFFile+ for s in shards:+ if not s.exists():+ fail(f"missing {s}")+ try:+ g = GGUFFile(s)+ except (ValueError, struct.error) as e:+ fail(f"{s.name} is not a whole GGUF shard ({e})", "delete it and run setup again")+ need = g.data_start + max((t.offset + (t.expected_bytes() or 0) for t in g.tensors), default=0)+ have = s.stat().st_size+ if have < need:+ fail(f"{s.name} is short: {have:,} of {need:,} bytes ({need - have:,} missing)",+ "delete it and run setup again (or copy the whole file into --gguf-dir)")++def get_llama_cpp():"""llama.cpp at the pinned commit (ggml for the build, gguf-py for the tools, mtmd for images), as a zip: no git."""llama = ROOT / "third_party" / "llama.cpp"@@ -1335,9 +1358,7 @@ def main() -> int:except OSError:passdownload(fam["hf"].format(q=model) + s.name, s)- for s in shards:- if not s.exists():- fail(f"missing {s}")+ check_shards(shards)ok("model files present")mmproj = Path(a.models_dir) / fam["mmproj"]if not mmproj.exists():diff --git a/tools/test_shards.py b/tools/test_shards.pynew file mode 100644index 000000000..b84966349--- /dev/null+++ b/tools/test_shards.py@@ -0,0 +1,79 @@+"""A missing or short model shard is named with its numbers - over a minimal GGUF written here (no download,+no model, no GPU).++ python -m unittest tools.test_shards+"""+from __future__ import annotations++import struct+import sys+import tempfile+import unittest+from pathlib import Path++ROOT = Path(__file__).resolve().parents[1]+sys.path.insert(0, str(ROOT / "tools"))+sys.path.insert(0, str(ROOT))+import setup as S # noqa: E402+++class Stop(Exception):+ """setup.fail(), caught instead of exiting: the message is what the test reads."""+++def write_gguf(path: Path, names=("blk.0.attn_q.weight", "blk.0.attn_k.weight")) -> int:+ """A GGUF v3 of F32[8] tensors 32 bytes apart from a 32-byte-aligned data start; returns its whole length."""+ b = bytearray(struct.pack("<IIQQ", 0x46554747, 3, len(names), 0))+ for i, n in enumerate(names):+ b += struct.pack("<Q", len(n)) + n.encode() + struct.pack("<IQIQ", 1, 8, 0, 32 * i)+ b += bytes(-len(b) % 32 + 32 * len(names))+ path.write_bytes(b)+ return len(b)+++class ShardCheck(unittest.TestCase):+ def setUp(self):+ self.tmp = tempfile.TemporaryDirectory()+ self.dir = Path(self.tmp.name)+ self.saved = S.fail+ S.fail = lambda msg, hint=None: (_ for _ in ()).throw(Stop(msg))++ def tearDown(self):+ S.fail = self.saved+ self.tmp.cleanup()++ def test_whole_shards_pass(self):+ shards = [self.dir / f"m-0000{i}-of-00002.gguf" for i in (1, 2)]+ for s in shards:+ write_gguf(s)+ S.check_shards(shards)++ def test_missing_shard_is_named(self):+ shards = [self.dir / "m-00001-of-00002.gguf", self.dir / "m-00002-of-00002.gguf"]+ write_gguf(shards[0])+ with self.assertRaises(Stop) as cm:+ S.check_shards(shards)+ self.assertIn("m-00002-of-00002.gguf", str(cm.exception))++ def test_short_shard_names_file_and_sizes(self):+ s = self.dir / "m-00001-of-00002.gguf"+ whole = write_gguf(s)+ s.write_bytes(s.read_bytes()[:-40])+ with self.assertRaises(Stop) as cm:+ S.check_shards([s])+ msg = str(cm.exception)+ self.assertIn("m-00001-of-00002.gguf is short", msg)+ self.assertIn(f"{whole - 40:,} of {whole:,} bytes", msg)+ self.assertIn("40 missing", msg)++ def test_truncated_header_is_refused(self):+ s = self.dir / "m-00001-of-00002.gguf"+ write_gguf(s)+ s.write_bytes(s.read_bytes()[:12])+ with self.assertRaises(Stop) as cm:+ S.check_shards([s])+ self.assertIn("m-00001-of-00002.gguf is not a whole GGUF shard", str(cm.exception))+++if __name__ == "__main__":+ unittest.main()