File size: 1,945 Bytes
e6e274e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Kaggle notebook body: release-candidate run at the operating point.

4000 steps was the best configuration; 8000 regressed. This run reproduces it
with the teacher seeded, and this time keeps the audio so the result can be
judged by ear rather than only by CER.

Produces:
  train/student4.pt        weights
  train/dit4.onnx          412 MB fp32
  train/dit4_int4.onnx     70 MB int4
  train/eval_rows*.json    teacher / student / int4 on a07 + a08
  train/eval_wavs/*.wav    teacher and student audio for the same cells

Uses the cached trajectories, so no regeneration.
"""
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 = "4000"


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"final_{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"final_{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 not (BUNDLE / "traj.zip").exists():
        raise SystemExit("traj.zip missing")

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

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


if __name__ == "__main__":
    main()