File size: 3,823 Bytes
5cfafaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os

os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")

import spaces  # noqa: E402  (must precede torch)
import torch  # noqa: E402
import gradio as gr  # noqa: E402

import shutil
import subprocess
import sys


def _diagnostics() -> str:
    lines = [f"python: {sys.version}"]
    for name in (
        "torch",
        "triton",
        "diffusers",
        "transformers",
        "peft",
        "accelerate",
        "numpy",
        "timm",
        "kernels",
        "imageio",
        "huggingface_hub",
        "gradio",
        "spaces",
    ):
        try:
            mod = __import__(name)
            lines.append(f"{name}: {getattr(mod, '__version__', '?')}")
        except Exception as exc:  # noqa: BLE001
            lines.append(f"{name}: IMPORT FAILED {exc!r}")

    lines.append("")
    lines.append(f"cpu_count: {os.cpu_count()}")
    lines.append(f"HF_HOME={os.environ.get('HF_HOME')}")
    lines.append(f"HF_HUB_CACHE={os.environ.get('HF_HUB_CACHE')}")
    lines.append(f"torch.cuda.is_available(): {torch.cuda.is_available()}")

    lines.append("")
    for path in ("/", "/tmp", "/home/user", "/data", os.getcwd()):
        try:
            total, used, free = shutil.disk_usage(path)
            lines.append(
                f"disk {path}: total={total / 2**30:.1f}G "
                f"used={used / 2**30:.1f}G free={free / 2**30:.1f}G"
            )
        except Exception as exc:  # noqa: BLE001
            lines.append(f"disk {path}: {exc!r}")

    for cmd in (["df", "-h"], ["free", "-g"]):
        try:
            out = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
            lines.append("")
            lines.append(f"$ {' '.join(cmd)}\n{out.stdout}{out.stderr}")
        except Exception as exc:  # noqa: BLE001
            lines.append(f"{' '.join(cmd)}: {exc!r}")

    lines.append("")
    try:
        with open("/sys/fs/cgroup/memory.max") as fh:
            lines.append(f"cgroup memory.max: {fh.read().strip()}")
    except Exception as exc:  # noqa: BLE001
        lines.append(f"cgroup memory.max: {exc!r}")

    lines.append("")
    try:
        from worldcrafter import WorldCrafter  # noqa: F401

        lines.append("import worldcrafter: OK")
    except Exception as exc:  # noqa: BLE001
        import traceback

        lines.append(f"import worldcrafter: FAILED {exc!r}\n{traceback.format_exc()}")

    try:
        from worldcrafter.fast.resident import ResidentBranches  # noqa: F401

        lines.append("import worldcrafter.fast.resident (triton): OK")
    except Exception as exc:  # noqa: BLE001
        lines.append(f"import worldcrafter.fast.resident: FAILED {exc!r}")

    try:
        from worldcrafter.camera import build_trajectory, parse_trajectory

        events, options = parse_trajectory("forward1x2\nyaw_left30")
        camera, records = build_trajectory(events, **options)
        lines.append(
            f"camera smoke: events={events} camera={camera.shape} chunks={len(records)}"
        )
    except Exception as exc:  # noqa: BLE001
        import traceback

        lines.append(f"camera smoke: FAILED {exc!r}\n{traceback.format_exc()}")

    return "\n".join(lines)


REPORT = _diagnostics()
print("==== WORLDCRAFTER SPACE DIAGNOSTICS ====", flush=True)
print(REPORT, flush=True)
print("==== END DIAGNOSTICS ====", flush=True)


def report() -> str:
    """Return the environment diagnostics collected at startup."""
    return REPORT


with gr.Blocks(theme=gr.themes.Citrus(), title="WorldCrafter (provisioning)") as demo:
    gr.Markdown("# WorldCrafter — provisioning\nEnvironment diagnostics:")
    out = gr.Textbox(value=REPORT, lines=40, label="diagnostics")
    gr.Button("Refresh").click(fn=report, inputs=None, outputs=out)

if __name__ == "__main__":
    demo.launch()