"""Kaggle notebook body: distil the flow head on the seven mined voices. Order matters. A smoke pass (5 texts, 5 optimizer steps) validates the trajectory and training code paths before spending an hour generating 840 trajectories; the earlier failures in this project each cost a full session. smoke traj x5 on one GPU, train x5 steps ~4 min traj 7 voices x 120 texts, sharded over 2 GPUs ~70 min train 4-step student on all shards ~25 min export ONNX fp32 + int4 ~5 min eval 40 sentences x 2 voices x {teacher, stu} ~25 min """ import os import subprocess import sys import time from notebook_eval import BUNDLE, MODEL, ROOT, WEIGHTS, pull, stage_deps, stage_repo BUNDLE_REPO = "idefinity/webfm-eval" SHARDS = [["a01", "a03", "a04"], ["a05", "a06", "a07", "a08"]] EVAL_VOICES = "a08,a01" def run(tag: str, env_extra: dict, gpu: int = 0) -> int: env = dict(os.environ, WORK_ROOT=str(ROOT), **env_extra) if gpu is not None: env["CUDA_VISIBLE_DEVICES"] = str(gpu) log = open(ROOT / f"train_{tag}.log", "w") p = subprocess.Popen([sys.executable, str(BUNDLE / "kaggle/train_voices.py")], env=env, stdout=log, stderr=subprocess.STDOUT, cwd=str(ROOT)) return p.wait() def main() -> None: stage_repo() stage_deps() pull(WEIGHTS, MODEL) pull(BUNDLE_REPO, BUNDLE, repo_type="dataset") print("== smoke: traj x5, train x5 ==", flush=True) rc = run("smoke_traj", {"STAGE": "traj", "VOICES": "a08", "SMOKE": "1", "N_TEXTS": "5"}) print("smoke traj rc", rc) rc = run("smoke_train", {"STAGE": "train", "TRAIN_STEPS": "5", "BATCH": "4"}) print("smoke train rc", rc) if rc != 0: print((ROOT / "train_smoke_train.log").read_text()[-3000:]) raise SystemExit("training path failed in smoke") print("== full trajectories ==", flush=True) procs = [] for gpu, shard in enumerate(SHARDS): env = dict(os.environ, WORK_ROOT=str(ROOT), STAGE="traj", VOICES=",".join(shard), CUDA_VISIBLE_DEVICES=str(gpu)) log = open(ROOT / f"traj_gpu{gpu}.log", "w") procs.append(subprocess.Popen([sys.executable, str(BUNDLE / "kaggle/train_voices.py")], env=env, stdout=log, stderr=subprocess.STDOUT, cwd=str(ROOT))) while any(p.poll() is None for p in procs): time.sleep(60) n = len(list((ROOT / "train/traj").glob("*/*.pt"))) print(f"[{time.strftime('%H:%M')}] trajectories={n}", flush=True) print("traj exits:", [p.returncode for p in procs]) print("== train + export + eval ==", flush=True) rc = run("final", {"STAGE": "all", "TRAIN_STEPS": "1500", "BATCH": "16", "EVAL_VOICES": EVAL_VOICES}, gpu=0) print("final rc", rc) if __name__ == "__main__": main()