holdout run: exclude a07 from training, add int4 eval stage
Browse files- kaggle/notebook_holdout.py +82 -0
kaggle/notebook_holdout.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Kaggle notebook body: hold out one voice, then measure generalisation.
|
| 2 |
+
|
| 3 |
+
The previous student fitted the seven voices it was trained on to within 1.19 pp
|
| 4 |
+
of the teacher. That is in-distribution. The case that matters for user
|
| 5 |
+
uploads is a voice the student has never heard, so this run trains on six and
|
| 6 |
+
evaluates the seventh.
|
| 7 |
+
|
| 8 |
+
a07 (伊芙琳) is held out. a08 stays in training as the in-distribution control,
|
| 9 |
+
so the two columns separate "fitted" from "generalised".
|
| 10 |
+
|
| 11 |
+
Also measures the int4 quantisation of the same student, since that decides
|
| 12 |
+
which bundle ships.
|
| 13 |
+
|
| 14 |
+
traj 6 voices x 120 texts, 2 GPUs ~55 min
|
| 15 |
+
train 4-step student ~25 min
|
| 16 |
+
export ONNX fp32 + int4 ~5 min
|
| 17 |
+
eval a07 + a08, teacher vs student ~15 min
|
| 18 |
+
eval_int4 same cells through the int4 graph ~12 min
|
| 19 |
+
"""
|
| 20 |
+
import os
|
| 21 |
+
import subprocess
|
| 22 |
+
import sys
|
| 23 |
+
import time
|
| 24 |
+
|
| 25 |
+
from notebook_eval import BUNDLE, MODEL, ROOT, WEIGHTS, pull, stage_deps, stage_repo
|
| 26 |
+
|
| 27 |
+
BUNDLE_REPO = "idefinity/webfm-eval"
|
| 28 |
+
SHARDS = [["a01", "a03", "a04"], ["a05", "a06", "a08"]]
|
| 29 |
+
HOLDOUT = "a07"
|
| 30 |
+
EVAL_VOICES = "a07,a08"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def run(tag: str, extra: dict, gpu: int = 0) -> int:
|
| 34 |
+
env = dict(os.environ, WORK_ROOT=str(ROOT), HOLDOUT=HOLDOUT, **extra)
|
| 35 |
+
env["CUDA_VISIBLE_DEVICES"] = str(gpu)
|
| 36 |
+
env["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
|
| 37 |
+
log = open(ROOT / f"holdout_{tag}.log", "w")
|
| 38 |
+
p = subprocess.Popen([sys.executable, str(BUNDLE / "kaggle/train_voices.py")],
|
| 39 |
+
env=env, stdout=log, stderr=subprocess.STDOUT, cwd=str(ROOT))
|
| 40 |
+
rc = p.wait()
|
| 41 |
+
print(f"[{tag}] rc={rc}", flush=True)
|
| 42 |
+
if rc != 0:
|
| 43 |
+
print((ROOT / f"holdout_{tag}.log").read_text()[-2500:])
|
| 44 |
+
return rc
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def main() -> None:
|
| 48 |
+
stage_repo()
|
| 49 |
+
stage_deps()
|
| 50 |
+
pull(WEIGHTS, MODEL)
|
| 51 |
+
pull(BUNDLE_REPO, BUNDLE, repo_type="dataset")
|
| 52 |
+
|
| 53 |
+
# Guard: confirm the holdout filter works before spending an hour.
|
| 54 |
+
rc = run("smoke", {"STAGE": "traj", "VOICES": "a08", "SMOKE": "1", "N_TEXTS": "2"})
|
| 55 |
+
if rc != 0:
|
| 56 |
+
raise SystemExit("traj path broken")
|
| 57 |
+
if (ROOT / "train/traj/a07").exists() and any((ROOT / "train/traj/a07").iterdir()):
|
| 58 |
+
raise SystemExit("holdout voice leaked into trajectories")
|
| 59 |
+
|
| 60 |
+
print("== trajectories (6 voices) ==", flush=True)
|
| 61 |
+
procs = []
|
| 62 |
+
for gpu, shard in enumerate(SHARDS):
|
| 63 |
+
env = dict(os.environ, WORK_ROOT=str(ROOT), STAGE="traj", HOLDOUT=HOLDOUT,
|
| 64 |
+
VOICES=",".join(shard), CUDA_VISIBLE_DEVICES=str(gpu))
|
| 65 |
+
log = open(ROOT / f"traj_gpu{gpu}.log", "w")
|
| 66 |
+
procs.append(subprocess.Popen([sys.executable, str(BUNDLE / "kaggle/train_voices.py")],
|
| 67 |
+
env=env, stdout=log, stderr=subprocess.STDOUT, cwd=str(ROOT)))
|
| 68 |
+
while any(p.poll() is None for p in procs):
|
| 69 |
+
time.sleep(60)
|
| 70 |
+
n = len(list((ROOT / "train/traj").glob("*/*.pt")))
|
| 71 |
+
print(f"[{time.strftime('%H:%M')}] trajectories={n}", flush=True)
|
| 72 |
+
print("traj exits:", [p.returncode for p in procs])
|
| 73 |
+
|
| 74 |
+
if run("final", {"STAGE": "all", "TRAIN_STEPS": "1500", "BATCH": "16",
|
| 75 |
+
"EVAL_VOICES": EVAL_VOICES}) != 0:
|
| 76 |
+
raise SystemExit("train/export/eval failed")
|
| 77 |
+
|
| 78 |
+
run("int4", {"STAGE": "eval_int4", "EVAL_VOICES": EVAL_VOICES})
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
main()
|