File size: 2,175 Bytes
6711723
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Kaggle notebook body: does more training keep closing the held-out gap?

Step count has moved the numbers a lot already:

  1500 steps  a07 +4.15 pp   a08 +1.95 pp   loss 0.226
  4000 steps  a07 +2.30 pp   a08 -0.51 pp   loss 0.179

The loss was still falling at 4000, so this run doubles it to 8000 and does the
same evaluation. The two columns now answer different questions: if a07 keeps
improving the student is still underfitted; if a07 stalls or regresses while a08
improves, it is starting to memorise the six training voices, and the next lever
is data diversity rather than more steps.

Trajectories come from the cached traj.zip, so the 50-minute generation pass is
skipped unless the cache is missing.
"""
import os
import subprocess
import sys

from notebook_eval import BUNDLE, MODEL, ROOT, WEIGHTS, pull, stage_deps, stage_repo

BUNDLE_REPO = "idefinity/webfm-eval"
HOLDOUT = "a07"
EVAL_VOICES = "a07,a08"
TRAIN_STEPS = "8000"


def run(tag: str, extra: dict, gpu: int = 0) -> int:
    env = dict(os.environ, WORK_ROOT=str(ROOT), HOLDOUT=HOLDOUT, **extra)
    env["CUDA_VISIBLE_DEVICES"] = str(gpu)
    env["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
    log = open(ROOT / f"run4_{tag}.log", "w")
    p = subprocess.Popen([sys.executable, str(BUNDLE / "kaggle/train_voices.py")],
                         env=env, stdout=log, stderr=subprocess.STDOUT, cwd=str(ROOT))
    rc = p.wait()
    print(f"[{tag}] rc={rc}", flush=True)
    if rc != 0:
        print((ROOT / f"run4_{tag}.log").read_text()[-2500:])
    return rc


def main() -> None:
    stage_repo()
    stage_deps()
    pull(WEIGHTS, MODEL)
    pull(BUNDLE_REPO, BUNDLE, repo_type="dataset")

    if (BUNDLE / "traj.zip").exists():
        print("using cached trajectories", flush=True)
    else:
        raise SystemExit("traj.zip missing from the bundle — regenerate before running")

    if run("final", {"STAGE": "all", "TRAIN_STEPS": TRAIN_STEPS, "BATCH": "16",
                     "EVAL_VOICES": EVAL_VOICES}) != 0:
        raise SystemExit("train/export/eval failed")

    run("int4", {"STAGE": "eval_int4", "EVAL_VOICES": EVAL_VOICES})


if __name__ == "__main__":
    main()