File size: 3,059 Bytes
cb8518a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from __future__ import annotations

import argparse
import importlib
import shutil
import subprocess
import sys
from dataclasses import dataclass
from pathlib import Path


@dataclass
class Check:
    name: str
    ok: bool
    detail: str


def check_package(pkg: str) -> Check:
    try:
        mod = importlib.import_module(pkg)
        ver = getattr(mod, "__version__", "unknown")
        return Check(pkg, True, f"version={ver}")
    except Exception as exc:
        return Check(pkg, False, str(exc))


def check_blender(blender_bin: str) -> Check:
    blender = shutil.which(blender_bin) if not Path(blender_bin).is_file() else blender_bin
    if blender is None:
        return Check("blender", False, "not found in PATH")

    try:
        proc = subprocess.run([blender, "--version"], capture_output=True, text=True, timeout=15)
    except Exception as exc:
        return Check("blender", False, str(exc))

    first_line = proc.stdout.splitlines()[0] if proc.stdout else "unknown"
    return Check("blender", proc.returncode == 0, first_line)


def check_torch_cuda() -> Check:
    try:
        import torch

        if torch.cuda.is_available():
            return Check("torch.cuda", True, f"available, devices={torch.cuda.device_count()}")
        return Check("torch.cuda", True, "not available, CPU fallback is supported")
    except Exception as exc:
        return Check("torch.cuda", False, str(exc))


def check_clip_cache(model_name: str = "openai/clip-vit-base-patch32") -> Check:
    try:
        from transformers import CLIPModel

        CLIPModel.from_pretrained(model_name, local_files_only=True)
        return Check("clip.cache", True, f"cached model={model_name}")
    except Exception as exc:
        return Check("clip.cache", False, f"{model_name}: {exc}")


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--blender_bin", default="blender")
    parser.add_argument("--clip_model_path", default="openai/clip-vit-base-patch32")
    parser.add_argument("--skip_clip_cache", action="store_true")
    return parser.parse_args()


def main() -> int:
    args = parse_args()
    checks = [
        Check("python", True, sys.version.splitlines()[0]),
        check_package("numpy"),
        check_package("cv2"),
        check_package("PIL"),
        check_package("torch"),
        check_package("transformers"),
        check_package("safetensors"),
        check_package("ftfy"),
        check_package("regex"),
        check_package("scipy"),
        check_blender(args.blender_bin),
        check_torch_cuda(),
    ]
    if not args.skip_clip_cache:
        checks.append(check_clip_cache(args.clip_model_path))

    failed = 0
    for c in checks:
        status = "OK" if c.ok else "FAIL"
        print(f"[{status}] {c.name}: {c.detail}")
        if not c.ok:
            failed += 1

    print(f"\nSummary: {len(checks) - failed}/{len(checks)} checks passed")
    return 1 if failed else 0


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