| from __future__ import annotations
|
|
|
| import argparse
|
| import hashlib
|
| import json
|
| import shutil
|
| from pathlib import Path
|
|
|
| from huggingface_hub import hf_hub_download
|
|
|
|
|
| def digest(path: Path) -> str:
|
| value = hashlib.sha256()
|
| with path.open("rb") as stream:
|
| while block := stream.read(8 * 1024 * 1024):
|
| value.update(block)
|
| return value.hexdigest()
|
|
|
|
|
| def main() -> int:
|
| parser = argparse.ArgumentParser(description="Download and verify Krea 2 benchmark models")
|
| parser.add_argument("--models-dir", type=Path, required=True)
|
| parser.add_argument("--manifest", type=Path, default=Path(__file__).resolve().parents[1] / "provenance" / "model_manifest.json")
|
| parser.add_argument("--all", action="store_true", help="Download all eight formats plus text encoder and VAE")
|
| parser.add_argument("--format", choices=["bf16", "fp8_scaled", "int8_convrot", "mxfp8", "nvfp4", "int4_convrot", "gguf_q8_0", "gguf_q4_k_m"], action="append")
|
| parser.add_argument("--accept-krea-license", action="store_true")
|
| args = parser.parse_args()
|
| if not args.accept_krea_license:
|
| parser.error("Review the Krea 2 Community License, then pass --accept-krea-license")
|
| selected = set(args.format or [])
|
| if not args.all and not selected:
|
| parser.error("Choose --all or at least one --format")
|
| manifest = json.loads(args.manifest.read_text(encoding="utf-8"))
|
| args.models_dir.mkdir(parents=True, exist_ok=True)
|
| common = {"qwen3vl_4b_bf16.safetensors", "qwen_image_vae.safetensors"}
|
| wanted = common | {item["filename"] for item in manifest["files"] if item.get("format_id") in selected}
|
| if args.all:
|
| wanted = {item["filename"] for item in manifest["files"]}
|
| for item in manifest["files"]:
|
| if item["filename"] not in wanted:
|
| continue
|
| destination = args.models_dir / item["filename"]
|
| if destination.exists() and digest(destination) == item["sha256"]:
|
| print(f"verified {destination.name}")
|
| continue
|
| cached = Path(hf_hub_download(repo_id=item["repository"], revision=item["revision"], filename=item["repository_path"]))
|
| shutil.copy2(cached, destination)
|
| actual = digest(destination)
|
| if actual != item["sha256"]:
|
| destination.unlink(missing_ok=True)
|
| raise RuntimeError(f"SHA-256 mismatch for {item['filename']}: {actual}")
|
| print(f"downloaded and verified {destination.name}")
|
| return 0
|
|
|
|
|
| if __name__ == "__main__":
|
| raise SystemExit(main())
|
|
|