add notebook_eval bootstrap target
Browse files- kaggle/notebook_eval.py +129 -0
kaggle/notebook_eval.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Kaggle notebook body for the WebFM eval run. Not imported by the app.
|
| 2 |
+
|
| 3 |
+
Push with:
|
| 4 |
+
mcp__kaggle__save_notebook(text=<this file>, slug="webfm-ming-eval",
|
| 5 |
+
enableGpu=True, machineShape="T4x2",
|
| 6 |
+
enableInternet=True, kernelExecutionType="SaveAndRunAll")
|
| 7 |
+
|
| 8 |
+
It does four things, in this order:
|
| 9 |
+
|
| 10 |
+
1. pin and prepare the Ming repo + weights
|
| 11 |
+
2. bake prompt_latent / speaker_emb for the eight WebFM voices
|
| 12 |
+
(small enough to ship; needed by the browser regardless of what the
|
| 13 |
+
model work decides)
|
| 14 |
+
3. run the eval matrix, one voice shard per visible GPU
|
| 15 |
+
4. score it and print the table
|
| 16 |
+
|
| 17 |
+
Every stage writes into /kaggle/working, so a killed session keeps whatever it
|
| 18 |
+
finished; ming_eval.py skips cells that already have a row.
|
| 19 |
+
|
| 20 |
+
Deliberately tolerant: a failed commit checkout or a single-GPU machine does not
|
| 21 |
+
abort the run, because each of those costs a whole session otherwise.
|
| 22 |
+
"""
|
| 23 |
+
import os
|
| 24 |
+
import subprocess
|
| 25 |
+
import sys
|
| 26 |
+
import time
|
| 27 |
+
from pathlib import Path
|
| 28 |
+
|
| 29 |
+
ROOT = Path("/kaggle/working")
|
| 30 |
+
REPO = ROOT / "Ming-3.0-tts"
|
| 31 |
+
MODEL = ROOT / "Ming-3.0-tts-0.5b"
|
| 32 |
+
BUNDLE = ROOT / "webfm-eval"
|
| 33 |
+
PIN = "e999c39"
|
| 34 |
+
WEIGHTS = "inclusionAI/Ming-3.0-tts-0.5B"
|
| 35 |
+
BUNDLE_REPO = "idefinity/webfm-eval"
|
| 36 |
+
MODELS = "teacher,3step,4step"
|
| 37 |
+
HF_MIRROR = "https://hf-mirror.com"
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def sh(cmd: str, check: bool = True, env: dict | None = None) -> int:
|
| 41 |
+
print(f"\n$ {cmd}", flush=True)
|
| 42 |
+
rc = subprocess.run(cmd, shell=True, text=True, env=env).returncode
|
| 43 |
+
if check and rc != 0:
|
| 44 |
+
raise SystemExit(f"command failed ({rc}): {cmd}")
|
| 45 |
+
return rc
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def pull(repo_id: str, local_dir: Path, repo_type: str = "model") -> None:
|
| 49 |
+
"""snapshot_download with a mirror retry; Kaggle usually reaches HF direct."""
|
| 50 |
+
if local_dir.exists() and any(local_dir.iterdir()):
|
| 51 |
+
print(f"{local_dir} already populated")
|
| 52 |
+
return
|
| 53 |
+
code = (
|
| 54 |
+
"from huggingface_hub import snapshot_download as s; "
|
| 55 |
+
f"s('{repo_id}', local_dir=r'{local_dir}', repo_type='{repo_type}')"
|
| 56 |
+
)
|
| 57 |
+
if sh(f'python3 -c "{code}"', check=False) != 0:
|
| 58 |
+
print("direct download failed, retrying through hf-mirror")
|
| 59 |
+
env = dict(os.environ, HF_ENDPOINT=HF_MIRROR)
|
| 60 |
+
sh(f'python3 -c "{code}"', env=env)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def stage_setup() -> None:
|
| 64 |
+
sh("nvidia-smi --query-gpu=name,memory.total --format=csv,noheader")
|
| 65 |
+
import torch
|
| 66 |
+
|
| 67 |
+
print("torch", torch.__version__, "cuda", torch.cuda.is_available(),
|
| 68 |
+
"devices", torch.cuda.device_count())
|
| 69 |
+
|
| 70 |
+
if not REPO.exists():
|
| 71 |
+
sh(f"git clone https://github.com/inclusionAI/Ming-3.0-tts.git {REPO}")
|
| 72 |
+
if sh(f"git -C {REPO} checkout {PIN}", check=False) != 0:
|
| 73 |
+
print(f"WARNING: commit {PIN} not found, staying on the default branch")
|
| 74 |
+
|
| 75 |
+
sh("pip install -q torchaudio soundfile onnx onnxruntime-gpu huggingface_hub "
|
| 76 |
+
"transformers==4.46.3 accelerate")
|
| 77 |
+
pull(WEIGHTS, MODEL)
|
| 78 |
+
pull(BUNDLE_REPO, BUNDLE, repo_type="dataset")
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def stage_bake() -> None:
|
| 82 |
+
if (ROOT / "baked/voices_baked.npz").exists():
|
| 83 |
+
print("voices already baked, skipping")
|
| 84 |
+
return
|
| 85 |
+
sh(f"cd {ROOT} && EVAL_DATA={BUNDLE} python3 {BUNDLE}/kaggle/bake_voices.py")
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def stage_eval() -> None:
|
| 89 |
+
import torch
|
| 90 |
+
|
| 91 |
+
n = max(1, torch.cuda.device_count())
|
| 92 |
+
voices = [f"v{i:02d}" for i in range(1, 9)]
|
| 93 |
+
shards = [voices[i::n] for i in range(n)]
|
| 94 |
+
print(f"{n} GPU(s), shards: {shards}")
|
| 95 |
+
|
| 96 |
+
procs = []
|
| 97 |
+
for gpu, shard in enumerate(shards):
|
| 98 |
+
env = dict(os.environ, CUDA_VISIBLE_DEVICES=str(gpu),
|
| 99 |
+
EVAL_DATA=str(BUNDLE), VOICES=",".join(shard), MODELS=MODELS)
|
| 100 |
+
log = open(ROOT / f"eval_gpu{gpu}.log", "w")
|
| 101 |
+
procs.append((gpu, subprocess.Popen(
|
| 102 |
+
[sys.executable, str(BUNDLE / "kaggle/ming_eval.py")],
|
| 103 |
+
env=env, stdout=log, stderr=subprocess.STDOUT, cwd=str(ROOT)), log))
|
| 104 |
+
|
| 105 |
+
last = 0.0
|
| 106 |
+
while any(p.poll() is None for _, p, _ in procs):
|
| 107 |
+
time.sleep(60)
|
| 108 |
+
rows = ROOT / "ming_eval/results.jsonl"
|
| 109 |
+
n_rows = sum(1 for _ in rows.open()) if rows.exists() else 0
|
| 110 |
+
if n_rows != last:
|
| 111 |
+
print(f"[{time.strftime('%H:%M')}] rows={n_rows}", flush=True)
|
| 112 |
+
last = n_rows
|
| 113 |
+
for gpu, p, log in procs:
|
| 114 |
+
log.close()
|
| 115 |
+
print(f"gpu{gpu} exit={p.returncode}")
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def stage_score() -> None:
|
| 119 |
+
sh(f"python3 {BUNDLE}/eval/score.py aggregate "
|
| 120 |
+
f"--results {ROOT}/ming_eval/results.jsonl --baseline teacher --by-bucket "
|
| 121 |
+
f"--out {ROOT}/ming_eval/summary.json", check=False)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
if __name__ == "__main__":
|
| 125 |
+
stage_setup()
|
| 126 |
+
stage_bake()
|
| 127 |
+
stage_eval()
|
| 128 |
+
stage_score()
|
| 129 |
+
print("\nartifacts: baked/, ming_eval/results.jsonl, ming_eval/summary.json, ming_eval/wav/")
|