File size: 2,424 Bytes
fa2d87b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
from __future__ import annotations

import argparse
import hashlib
import json
from pathlib import Path

from huggingface_hub import HfApi


SOURCE_ID = "MiniMaxAI/MiniMax-H3"
SOURCE_REVISION = "73372e6cf53e414edd3ab03e357717fb0602e758"
SOURCE_COMPONENTS = ("vae", "audio_vae")


def sha256(path: Path) -> str:
    digest = hashlib.sha256()
    with path.open("rb") as handle:
        for chunk in iter(lambda: handle.read(8 * 1024 * 1024), b""):
            digest.update(chunk)
    return digest.hexdigest()


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--release", type=Path, required=True)
    parser.add_argument("--output", type=Path, required=True)
    args = parser.parse_args()
    release = args.release.resolve()
    info = HfApi().model_info(SOURCE_ID, revision=SOURCE_REVISION, files_metadata=True)
    remote_lfs = {
        sibling.rfilename: getattr(sibling.lfs, "sha256", None)
        for sibling in info.siblings or []
        if getattr(sibling, "lfs", None) is not None
    }

    files = []
    for component in SOURCE_COMPONENTS:
        weights = sorted(
            path
            for path in (release / component).iterdir()
            if path.is_file() and path.suffix in {".safetensors", ".bin"}
        )
        if not weights:
            raise RuntimeError(f"source component has no weight files: {component}")
        for path in weights:
            relative = f"{component}/{path.name}"
            local_digest = sha256(path)
            remote_digest = remote_lfs.get(relative)
            if remote_digest != local_digest:
                raise RuntimeError(f"source-copy hash mismatch: {relative}")
            files.append(
                {
                    "file": relative,
                    "bytes": path.stat().st_size,
                    "sha256": local_digest,
                    "source_lfs_sha256": remote_digest,
                }
            )

    report = {
        "status": "pass",
        "source_model_id": SOURCE_ID,
        "source_revision": SOURCE_REVISION,
        "components": list(SOURCE_COMPONENTS),
        "verified_weight_files": files,
    }
    args.output.parent.mkdir(parents=True, exist_ok=True)
    args.output.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
    print(json.dumps(report))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())