File size: 4,108 Bytes
84af0a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Load one saved checkpoint and run a single inference. The real test of a checkpoint.

Run from inside the openpi checkout:

    # while training still owns the A100 -- CPU, slow (~1-2 min), proves loadability
    JAX_PLATFORMS=cpu uv run python <this file> /data/checkpoints/.../pickplace_full_v1/7500

    # after training exits -- GPU, fast
    uv run python <this file> /data/checkpoints/.../pickplace_full_v1/29999

`check_checkpoints.py` verifies the files are structurally complete. This verifies they actually
deserialise into the model, that norm stats resolve, and that the policy emits a finite (50, 28)
action chunk for a plausible observation. A checkpoint can pass the structural check and still be
unusable -- wrong config, mismatched action_dim, missing norm stats for this exact config name.

Nothing here touches the robot. The action values are meaningless (the images are synthetic); only
their shape, dtype and finiteness are being checked.
"""
import argparse
import pathlib
import sys
import time

TASK = "pick octopus and place inside brown basket"


def main() -> int:
    ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    ap.add_argument("checkpoint", type=pathlib.Path, help="a step directory containing params/ and assets/")
    ap.add_argument("--config", default="pi05_g1_pickplace")
    ap.add_argument("--prompt", default=TASK)
    ap.add_argument("--state-dim", type=int, default=43, choices=(28, 43))
    ap.add_argument("--repeat", type=int, default=2, help="inferences to run; the 2nd shows warm latency")
    a = ap.parse_args()

    if not (a.checkpoint / "params").is_dir():
        print(f"FAIL: {a.checkpoint}/params does not exist", file=sys.stderr)
        return 2

    import numpy as np
    import jax

    from openpi.policies import policy_config
    from openpi.training import config as _config

    print(f"jax backend : {jax.default_backend()}  devices={jax.devices()}")
    print(f"config      : {a.config}")
    print(f"checkpoint  : {a.checkpoint}")

    cfg = _config.get_config(a.config)

    t0 = time.time()
    policy = policy_config.create_trained_policy(cfg, a.checkpoint)
    print(f"loaded      : {time.time() - t0:.1f}s")

    # Dataset-native keys -- create_trained_policy applies the repack transform, so this is the
    # same dict the robot client sends (see runbook Step 12).
    rng = np.random.default_rng(0)
    obs = {
        "observation.images.ego_view": rng.integers(0, 256, (480, 640, 3), dtype=np.uint8),
        "observation.images.ego_left": rng.integers(0, 256, (480, 640, 3), dtype=np.uint8),
        "observation.images.ego_right": rng.integers(0, 256, (480, 640, 3), dtype=np.uint8),
        "observation.state": np.zeros(a.state_dim, dtype=np.float32),
        "prompt": a.prompt,
    }

    for i in range(a.repeat):
        t0 = time.time()
        out = policy.infer(obs)
        dt = time.time() - t0
        act = np.asarray(out["actions"])
        print(f"infer #{i + 1}     : {dt:.2f}s  shape={act.shape} dtype={act.dtype}")

    problems = []
    if act.shape != (50, 28):
        problems.append(f"expected action chunk (50, 28), got {act.shape}")
    if not np.all(np.isfinite(act)):
        n = int((~np.isfinite(act)).sum())
        problems.append(f"{n} non-finite value(s) in the action chunk")
    if np.allclose(act, 0.0):
        problems.append("every action is exactly 0.0 -- norm stats or params likely not loaded")

    print(f"\nfirst step  : {np.array2string(act[0], precision=3, max_line_width=200)}")
    print(f"per-dim |max|: {np.abs(act).max(axis=0).round(3)}")
    print(f"range       : [{act.min():.3f}, {act.max():.3f}]")

    if problems:
        print("\nFAIL")
        for p in problems:
            print(f"  {p}")
        return 1

    print("\nPASS -- checkpoint loads and produces a finite (50, 28) chunk.")
    print("Action VALUES are not validated here; the images were noise. Only §14 rollouts tell you")
    print("whether this checkpoint is any good.")
    return 0


if __name__ == "__main__":
    sys.exit(main())