File size: 2,865 Bytes
1ddfac5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""selfbootstrap.py — open-set self-bootstrap on a released tree.

Loads a safetensors snapshot, opens the action set (one sampled action
per expansion), and lets the operator grow the tree for a few minutes
without any new data.  The result is a new snapshot for the Hub.

    python3 demo/selfbootstrap.py --minutes 3
    # weights/LITOperator-community_open_selfboot.safetensors
"""
import argparse
import ctypes as C
import os
import sys
import time

HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
sys.path.insert(0, os.path.join(ROOT, "sandbox", "lerobot_host"))

from lit_pretrain import DataHost, LIB, search_pass, stats  # noqa: E402
from lit_stream import make_codec  # noqa: E402

BASE = os.path.join(ROOT, "weights",
                    "LITOperator-community_open_pretrain.safetensors")
OUT = os.path.join(ROOT, "weights",
                   "LITOperator-community_open_selfboot.safetensors")
REPO = "lerobot/community_dataset_v3"
ROOT_TAG = "1g0rrr/demo3_frames_grab3"


def main():
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument("--base", default=BASE)
    p.add_argument("--out", default=OUT)
    p.add_argument("--minutes", type=float, default=3.0)
    p.add_argument("--codec-root", default=ROOT_TAG)
    p.add_argument("--seed", type=int, default=0)
    args = p.parse_args()

    host = DataHost(open_actions=1, new_actions=1, seed=args.seed)
    s = LIB.lit_search_load_safetensors(C.byref(host.host),
                                        args.base.encode())
    if not s:
        raise SystemExit("load failed: " + args.base)
    host.s = s
    codec, _info = make_codec(REPO, args.codec_root)
    host.codec = codec
    print("base", stats(s), "codec", args.codec_root, flush=True)

    t0 = time.time()
    last = t0
    passes = 0
    try:
        while time.time() - t0 < args.minutes * 60.0:
            rc, _pops, _nodes, _path = search_pass(s, 1)
            passes += 1
            now = time.time()
            if now - last >= 10.0:
                n, u, o = stats(s)
                print("t=%.0fs passes=%d nodes=%d seen=%d open=%d rc=%d"
                      % (now - t0, passes, n, u, o, rc), flush=True)
                last = now
            if rc == 1:  # LIT_SEARCH_EMPTY
                break
    finally:
        if LIB.lit_search_save_safetensors(s, args.out.encode()) != 0:
            raise SystemExit("save failed")
        n, u, o = stats(s)
        print("saved", args.out, "nodes", n, "seen", u, "open", o,
              "passes", passes, "elapsed %.1fs" % (time.time() - t0),
              flush=True)
        LIB.lit_search_free(s)
    with open(os.path.splitext(args.out)[0] + ".progress", "w") as f:
        f.write("selfbootstrap:%s\n" % args.codec_root)
    return 0


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