Files
Strata/tools/release_grid/fetch_models.py
T
Niko1221 4adbc88135 feat(control): the Inkling-2-Mini lineup of 0.2.23: Strata packs, GSQ-RCO IQ3_S, Unsloth UD-Q4_K_XL, DFlash 2 the only drafter
Offered, in this order in setup, the launcher, `strata launch` and the app's model table: SQ-20, SQ-15, SQ-10, GSQ-RCO-IQ3_S, UD-Q4_K_XL.

Files and pins (strata_control/inkling_family.py, inkling_fit.py):
- SQ-20 is the re-adjusted 16 KiB-layout file Inkling-2-Mini-SQv2-20.strata (19,374,768,128 bytes, sha256 429671f8...); the Vision shard is
  Inkling-2-Mini-Vision-v2.strata (636,551,168 bytes, 34a17650...), used with every pack. The shown name and the model id stay SQ-20 /
  inkling-2-mini-sq-20.
- Every .strata download (packs, Vision, tokenizer files) is pinned to commit 5623ceb47d7a of strata-engine/Inkling-2-Mini-Strata (STRATA_PACK_COMMIT),
  which holds both v2 files and still the 0.2.22 files.
- An install that has the old SQ-20 or the old Vision file keeps running it (model_file_in, vision_in, LEGACY_FILES), is marked "update available" in the
  model table, the Terminal list and the app, and gets the new file only when the person installs again. No old file is ever deleted.
- Unsloth: UD-Q4_K_XL is the refreshed file (17,629,760,736 bytes, e6427665...) at commit 8078d149286e; the other nine quants are no longer offered,
  but an install that has one keeps working and the lists show it as installed, "no longer offered" (INKLING_FAMILIES legacy_models, ModelRow.offered).
- GSQ-RCO IQ3_S (ISTA-DASLab, Apache-2.0): Inkling-2-Mini-GSQ-RCO-IQ3_S.gguf, 11,425,259,648 bytes, sha256 8a351537..., pinned to commit
  357051619a88. Planner figures (routed experts 9.52 GB, eight expert types) are read from the file's GGUF header; credit "GSQ + RCO by IST Austria
  DASLab, Apache-2.0".

Drafter: DFlash 2 only, on every device. setup and update fetch dflash2.safetensors beside every Inkling model that Strata downloaded (packs and GGUFs);
no DSpark GGUF and no mtp.safetensors is fetched, passed (--dspark) or offered any more. Without the file the model starts with --draft off and
the launcher does not probe. The status word is dflash2. An old config that names the DSpark file still starts.

Also: the Terminal and `strata launch` lists carry the credit line, the no-longer-offered mark and the update mark; models.py reads SQv2 and GSQ file names;
the release grid pins follow the new tables; docs (README and translations, MODELS.md, DOCKER.md) and the DFlash 2 notice credit tjm8874.

Tests: terminal/tests/terminal/test_inkling_lineup.py (pins, order, hidden-but-installed, update offer, no DSpark fetch, DFlash 2 for every model);
the older Inkling tests follow the new tables.
2026-11-26 20:31:30 +01:00

213 lines
11 KiB
Python

#!/usr/bin/env python3
"""fetch_models.py: the grid's model files, pinned by size and SHA-256.
python3 fetch_models.py pin [--out models.lock.json] (in a checkout: read the pins the product itself trusts)
python3 fetch_models.py list (what the lock file holds)
python3 fetch_models.py fetch KEY --dest DIR [--lock FILE] (on a box: download with resume, verify, keep only verified files)
python3 fetch_models.py verify KEY --dest DIR [--quick] (sizes only with --quick; else SHA-256 of every file)
KEY is a pin key such as qwen/Q2_0, qwen/UD-Q4_K_XL, ink/SQ-10, ink/UD-Q2_K_XL (a GGUF key also lists its DSpark drafter), hy4/SQ-64.
The pins are not typed in here: `pin` imports them from terminal/setup.py (Qwen), strata_control/inkling_family.py and hy4_family.py, so the grid
checks the same bytes the product's own setup checks. A file whose size or SHA-256 differs is deleted and the fetch stops: nothing unverified is kept.
Downloads come from Hugging Face over https with Range resume, 4 tries per file. No token is read or sent (the repositories are public).
Disk: `fetch` refuses to start when the folder's disk would be left with less than --floor-gb free (default 25).
"""
from __future__ import annotations
import argparse
import hashlib
import json
import os
import shutil
import sys
import time
import urllib.error
import urllib.request
from pathlib import Path
HERE = Path(__file__).resolve().parent
LOCK = HERE / "models.lock.json"
# ---------------------------------------------------------------------------------------------------------------- pin
def make_pins(repo_root: Path) -> dict:
sys.path.insert(0, str(repo_root / "terminal"))
import setup # noqa: E402 (terminal/setup.py: the pins the product trusts)
from strata_control import hy4_family as hy4, inkling_family as ink # noqa: E402
out = {}
rev = setup.HF_REVISIONS
ista = setup.hf("ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF")
for q in ("Q2_0", "IQ2_XS", "IQ3_XXS", "IQ3_S"):
files = [n for n in setup.ISTA_FILES if "-GSQ-RCO-%s-0000" % q in n]
if files:
out["qwen/" + q] = {"folder": q, "files": [
{"name": n, "bytes": setup.ISTA_FILES[n][0], "sha256": setup.ISTA_FILES[n][1], "url": "%s%s/%s" % (ista, q, n)} for n in sorted(files)]}
uns = setup.hf(setup.UNSLOTH_REPO)
out["qwen/UD-Q4_K_XL"] = {"folder": "UD-Q4_K_XL", "files": [
{"name": n, "bytes": v[0], "sha256": v[1], "url": "%sUD-Q4_K_XL/%s" % (uns, n)} for n, v in sorted(setup.UNSLOTH_SHARDS.items())]}
# every offered build (the 0.2.23 lineup) with the sidecar the engine drafts with; the quants that are no longer offered keep their pin keys (the grid still tests them) at their own commit
strata_base = ink.pack_base()
for build in ink.inkling_fit.ORDER:
fn = ink.build_file(build)
src = ink.sources_for(fn, env={})[0]
out["ink/" + build] = {"folder": "Inkling-2-Mini-" + build, "files": [
{"name": fn, "bytes": ink.size_of(fn), "sha256": ink.sha256_of(fn), "url": ink.urls_for(fn, src)[0]},
{"name": ink.DFLASH2_FILE, "bytes": ink.size_of(ink.DFLASH2_FILE), "sha256": ink.sha256_of(ink.DFLASH2_FILE), "url": ink.DFLASH2_URL}]}
for key in ink.inkling_fit.LEGACY_ORDER:
fn = ink.build_file(key)
size, sha = ink.UNSLOTH_GGUF_FILES[fn]
gguf_base = ink.sources_for(fn, env={})[0]["base"]
d = ink.DSPARK_GGUF_FILE
out["ink/" + key] = {"folder": "Inkling-2-Mini-" + key, "files": [
{"name": fn, "bytes": size, "sha256": sha, "url": "%s/%s" % (gguf_base, fn)},
{"name": d, "bytes": ink.LEGACY_FILES[d][0], "sha256": ink.LEGACY_FILES[d][1], "url": "%s/%s" % (gguf_base, d)}]}
# the picture reader: every build reads pictures with the Vision shard beside the model
out["ink/Vision"] = {"folder": "Inkling-2-Mini-Vision", "files": [
{"name": ink.VISION_FILE, "bytes": ink.FILES[ink.VISION_FILE][0], "sha256": ink.FILES[ink.VISION_FILE][1], "url": "%s/%s" % (strata_base, ink.VISION_FILE)}]}
out["ink/mmproj-BF16"] = {"folder": "Inkling-2-Mini-mmproj-BF16", "files": [
{"name": ink.MMPROJ_BF16_FILE, "bytes": ink.LEGACY_FILES[ink.MMPROJ_BF16_FILE][0], "sha256": ink.LEGACY_FILES[ink.MMPROJ_BF16_FILE][1],
"url": "%s/%s" % (ink.hf_base(ink.UNSLOTH_REPO, ink.UNSLOTH_OLD_COMMIT), ink.MMPROJ_BF16_FILE)}]}
hsrc = json.loads((repo_root / "terminal" / "data" / "hy4-sources.json").read_text(encoding="utf-8"))["sources"][0]["base"]
for name in ("SQ-64",):
fn = hy4.build_file(name)
files = [fn, hy4.ENGRAM_FILE]
out["hy4/" + name] = {"folder": "Hy4-Flash-" + name, "files": [
{"name": f, "bytes": hy4.FILES[f][0], "sha256": hy4.FILES[f][1], "url": "%s/%s" % (hsrc, f)} for f in files]}
return {"note": "generated by `fetch_models.py pin` from the product's own pin tables; do not edit by hand", "hf_revisions": {k: v for k, v in rev.items()}, "models": out}
# ---------------------------------------------------------------------------------------------------------------- files
def sha256_of(path: Path, block=8 << 20) -> str:
h = hashlib.sha256()
with open(path, "rb") as f:
while True:
b = f.read(block)
if not b:
break
h.update(b)
return h.hexdigest()
def load_lock(path=None) -> dict:
return json.loads(Path(path or LOCK).read_text(encoding="utf-8"))["models"]
def download(url: str, part: Path, want: int, tries=4):
"""Resume-capable download to `part` until it holds `want` bytes."""
for attempt in range(1, tries + 1):
have = part.stat().st_size if part.exists() else 0
if have == want:
return
if have > want:
part.unlink()
have = 0
req = urllib.request.Request(url, headers={"User-Agent": "release-grid", **({"Range": "bytes=%d-" % have} if have else {})})
try:
with urllib.request.urlopen(req, timeout=60) as r, open(part, "ab" if have else "wb") as f:
if have and r.status != 206:
f.seek(0)
f.truncate()
last = time.time()
while True:
b = r.read(4 << 20)
if not b:
break
f.write(b)
if time.time() - last > 60:
print(" %s: %.1f of %.1f GB" % (part.name, f.tell() / 1e9, want / 1e9), flush=True)
last = time.time()
except (urllib.error.URLError, OSError, TimeoutError) as e:
print(" attempt %d: %s" % (attempt, e), flush=True)
time.sleep(5 * attempt)
if (part.stat().st_size if part.exists() else 0) != want:
raise SystemExit("download of %s did not complete" % url)
def disk_free_gb(folder: Path) -> float:
folder.mkdir(parents=True, exist_ok=True)
return shutil.disk_usage(folder).free / 1e9
def fetch(key: str, dest: Path, lock=None, floor_gb=25.0) -> list:
spec = load_lock(lock)[key]
dest = Path(os.path.expanduser(str(dest))) / spec["folder"]
dest.mkdir(parents=True, exist_ok=True)
todo = [f for f in spec["files"] if not (dest / f["name"]).exists() or (dest / f["name"]).stat().st_size != f["bytes"]]
need = sum(f["bytes"] for f in todo) / 1e9
free = disk_free_gb(dest)
if todo and free - need < floor_gb:
raise SystemExit("not enough disk: %.1f GB free, %.1f GB to fetch, floor %.1f GB" % (free, need, floor_gb))
got = []
for f in spec["files"]:
target = dest / f["name"]
if target.exists() and target.stat().st_size == f["bytes"]:
marker = target.with_name(target.name + ".sha-ok")
if marker.exists() and marker.read_text().strip() == f["sha256"]:
got.append(str(target))
continue
else:
print("fetching %s (%.1f GB)" % (f["name"], f["bytes"] / 1e9), flush=True)
part = target.with_name(target.name + ".part")
download(f["url"], part, f["bytes"])
os.replace(part, target)
digest = sha256_of(target)
if digest != f["sha256"]:
target.unlink()
raise SystemExit("SHA-256 of %s is %s, pinned %s: file deleted" % (f["name"], digest, f["sha256"]))
target.with_name(target.name + ".sha-ok").write_text(digest)
got.append(str(target))
return got
def verify(key: str, dest: Path, quick=False, lock=None) -> list:
spec = load_lock(lock)[key]
problems = []
for f in spec["files"]:
p = Path(os.path.expanduser(str(dest))) / f["name"]
if not p.exists():
problems.append("%s: missing" % f["name"])
elif p.stat().st_size != f["bytes"]:
problems.append("%s: size %d, pinned %d" % (f["name"], p.stat().st_size, f["bytes"]))
elif not quick and sha256_of(p) != f["sha256"]:
problems.append("%s: SHA-256 differs from the pin" % f["name"])
return problems
def main(argv=None) -> int:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
sub = ap.add_subparsers(dest="cmd", required=True)
p = sub.add_parser("pin")
p.add_argument("--out", default=str(LOCK))
p.add_argument("--repo", default=str(HERE.parents[1]))
sub.add_parser("list").add_argument("--lock")
for name in ("fetch", "verify"):
q = sub.add_parser(name)
q.add_argument("key")
q.add_argument("--dest", required=True)
q.add_argument("--lock")
if name == "fetch":
q.add_argument("--floor-gb", type=float, default=25.0)
else:
q.add_argument("--quick", action="store_true")
a = ap.parse_args(argv)
if a.cmd == "pin":
data = make_pins(Path(a.repo))
Path(a.out).write_text(json.dumps(data, indent=1, sort_keys=True) + "\n", encoding="utf-8")
print("wrote %s: %d keys" % (a.out, len(data["models"])))
elif a.cmd == "list":
for k, v in sorted(load_lock(a.lock).items()):
print("%-22s %6.1f GB %s" % (k, sum(f["bytes"] for f in v["files"]) / 1e9, ", ".join(f["name"] for f in v["files"])[:100]))
elif a.cmd == "fetch":
for g in fetch(a.key, Path(a.dest), a.lock, a.floor_gb):
print("ok", g)
else:
bad = verify(a.key, Path(a.dest), a.quick, a.lock)
print("\n".join(bad) or "all files match the pins")
return 1 if bad else 0
return 0
if __name__ == "__main__":
sys.exit(main())