okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-5 fccdb48a3 (image noise switch, step 1 only) into f-own-int150c2394f

main
2.1 KiB49 linesraw
1"""OWN-5: download Qwen-Image-2.1-Turbo's files at the pinned revisions (tools/image/qimage.py FILES/REVISIONS) and
2check size + sha256, as setup does.  Uses curl (resumable).
3
4    python3 -I -B dl_models.py <root> <models_dir> <quant> [--min-free-gb N] [--check-only]"""
5from __future__ import annotations
6
7import hashlib
8import shutil
9import subprocess
10import sys
11from pathlib import Path
12
13
14def main() -> int:
15    a = sys.argv[1:]
16    root, models, quant = Path(a[0]).expanduser(), Path(a[1]).expanduser(), a[2]
17    min_free = float(a[a.index("--min-free-gb") + 1]) if "--min-free-gb" in a else 15.0
18    sys.path.insert(0, str(root / "repo" / "tools" / "image"))
19    import qimage as QI
20    models.mkdir(parents=True, exist_ok=True)
21    names = (quant, "vae", "llm")
22    need = sum(QI.FILES[n][2] for n in names if not (models / Path(QI.FILES[n][1]).name).is_file()) / 1e9
23    free = shutil.disk_usage(models).free / 1e9
24    print(f"free {free:.1f} GB, to download about {need:.1f} GB, floor {min_free} GB", flush=True)
25    if "--check-only" not in a and free - need < min_free:
26        raise SystemExit("ABORT: the download would go under the disk floor")
27    for n in names:
28        repo, path, size, sha = QI.FILES[n]
29        dst = models / Path(path).name
30        if "--check-only" not in a and not (dst.is_file() and dst.stat().st_size == size):
31            r = subprocess.run(["curl", "-L", "--fail", "--retry", "5", "-C", "-", "-s", "-S", "-o", str(dst),
32                                QI.file_url(n)])
33            if r.returncode:
34                raise SystemExit(f"curl failed for {path} ({r.returncode})")
35        h = hashlib.sha256()
36        with open(dst, "rb") as f:
37            for b in iter(lambda: f.read(8 << 20), b""):
38                h.update(b)
39        ok = dst.stat().st_size == size and h.hexdigest() == sha
40        print(f"{'OK ' if ok else 'BAD'} {dst.name} {dst.stat().st_size} {h.hexdigest()}", flush=True)
41        if not ok:
42            raise SystemExit("sha256 / size mismatch")
43    print(f"free after {shutil.disk_usage(models).free / 1e9:.1f} GB")
44    print("DL-OK")
45    return 0
46
47
48if __name__ == "__main__":
49    sys.exit(main())