File size: 1,822 Bytes
fd5366a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (c) 2026 CLSA contributors
# SPDX-License-Identifier: MIT
"""Build the dataset and train all artefacts for one backbone.

Usage:
    PYTHONPATH=src python experiments/train_all.py --model primary
"""
from __future__ import annotations

import argparse
import json
import sys
import time
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))

from clsa.transcoder.dataset import build_dataset  # noqa: E402
from clsa.util import load_config, write_result  # noqa: E402
from clsa.world_model.train import train_all  # noqa: E402


def main() -> None:
    ap = argparse.ArgumentParser()
    ap.add_argument("--model", default="primary")
    ap.add_argument("--skip-dataset", action="store_true")
    args = ap.parse_args()
    tcfg = load_config("transcoder")
    wcfg = load_config("world_model")
    wcfg["threads"] = tcfg.get("threads", 4)
    wcfg["admission"] = tcfg.get("admission", {})
    wcfg["probe"] = tcfg.get("probe", {})
    name = tcfg["backbones"].get(args.model, args.model)

    t0 = time.time()
    ds_meta = None if args.skip_dataset else build_dataset(name, tcfg)
    print("dataset:", json.dumps(ds_meta, indent=2)[:600] if ds_meta else "cached")
    art = train_all(name, wcfg)
    path = write_result(
        f"train_{name.replace('/', '__')}",
        {"dataset": ds_meta, "artifacts": art},
        config=wcfg,
        seed=int(wcfg.get("seed", 0)),
        notes=f"world-model training on {name}",
    )
    print(json.dumps(art["world_model"], indent=2)[:1200])
    print("admission:", json.dumps({k: art["admission"].get(k) for k in ("n_shared", "n_probe_only", "flip_rate_shared", "flip_rate_probe_only", "flip_rate_random")}, indent=2))
    print("seconds:", round(time.time() - t0, 1), "->", path)


if __name__ == "__main__":
    main()