File size: 1,663 Bytes
ce47bc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Verify local sanitized LoRA files against weights_manifest.json."""

from __future__ import annotations

import argparse
import hashlib
import json
from pathlib import Path


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() -> None:
    parser = argparse.ArgumentParser(description="Verify HandEdit LoRA checkpoints.")
    parser.add_argument(
        "--root",
        type=Path,
        default=Path("."),
        help="Repository root containing weights_manifest.json and checkpoints/.",
    )
    args = parser.parse_args()

    root = args.root.expanduser().resolve()
    manifest = json.loads(
        (root / "weights_manifest.json").read_text(encoding="utf-8")
    )
    failures = []
    for adapter in manifest["adapters"].values():
        for item in adapter["files"]:
            path = root / item["path"]
            if not path.is_file():
                failures.append(f"missing: {item['path']}")
                continue
            if path.stat().st_size != item["size_bytes"]:
                failures.append(f"size mismatch: {item['path']}")
                continue
            if sha256(path) != item["sha256"]:
                failures.append(f"SHA-256 mismatch: {item['path']}")
                continue
            print(f"[OK] {item['path']}")

    if failures:
        raise SystemExit("\n".join(failures))
    print("[DONE] All sanitized LoRA files passed verification.")


if __name__ == "__main__":
    main()