okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
150c2394f
main
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 4python3 -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 : 15a = sys .argv [1 :] 16root ,models ,quant = Path (a [0 ]).expanduser (),Path (a [1 ]).expanduser (),a [2 ] 17min_free = float (a [a .index ("--min-free-gb" )+ 1 ])if "--min-free-gb" in a else 15.0 18sys .path .insert (0 ,str (root / "repo" / "tools" / "image" )) 19import qimage as QI 20models .mkdir (parents = True ,exist_ok = True ) 21names = (quant ,"vae" ,"llm" ) 22need = sum (QI .FILES [n ][2 ]for n in names if not (models / Path (QI .FILES [n ][1 ]).name ).is_file ())/ 1e9 23free = shutil .disk_usage (models ).free / 1e9 24f"free { free :.1f } GB, to download about { need :.1f } GB, floor { min_free } GB" ,flush = True ) 25if "--check-only" not in a and free - need < min_free : 26raise SystemExit ("ABORT: the download would go under the disk floor" ) 27for n in names : 28repo ,path ,size ,sha = QI .FILES [n ] 29dst = models / Path (path ).name 30if "--check-only" not in a and not (dst .is_file ()and dst .stat ().st_size == size ): 31r = subprocess .run (["curl" ,"-L" ,"--fail" ,"--retry" ,"5" ,"-C" ,"-" ,"-s" ,"-S" ,"-o" ,str (dst ), 32QI .file_url (n )]) 33if r .returncode : 34raise SystemExit (f"curl failed for { path } ( { r . returncode } )" ) 35h = hashlib .sha256 () 36with open (dst ,"rb" )as f : 37for b in iter (lambda :f .read (8 << 20 ),b"" ): 38h .update (b ) 39ok = dst .stat ().st_size == size and h .hexdigest ()== sha 40f" { 'OK ' if ok else 'BAD' } { dst . name } { dst . stat (). st_size } { h . hexdigest () } " ,flush = True ) 41if not ok : 42raise SystemExit ("sha256 / size mismatch" ) 43f"free after { shutil . disk_usage ( models ). free / 1e9 :.1f } GB" ) 44"DL-OK" ) 45return 0 46 47 48if __name__ == "__main__" : 49sys .exit (main ())