fix deps: install requirement set, self-heal imports, add smoke stage
Browse files- kaggle/notebook_eval.py +102 -54
kaggle/notebook_eval.py
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
"""Kaggle notebook body for the WebFM eval run. Not imported by the app.
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 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
|
|
@@ -36,6 +36,15 @@ 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)
|
|
@@ -45,35 +54,56 @@ def sh(cmd: str, check: bool = True, env: dict | None = None) -> int:
|
|
| 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 |
-
|
| 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 |
-
|
| 60 |
-
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
|
|
|
| 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 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
pull(WEIGHTS, MODEL)
|
| 78 |
pull(BUNDLE_REPO, BUNDLE, repo_type="dataset")
|
| 79 |
|
|
@@ -85,33 +115,48 @@ def stage_bake() -> None:
|
|
| 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 |
-
|
| 92 |
voices = [f"v{i:02d}" for i in range(1, 9)]
|
| 93 |
-
shards = [voices[i::
|
| 94 |
-
print(f"{
|
| 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
|
| 107 |
time.sleep(60)
|
| 108 |
rows = ROOT / "ming_eval/results.jsonl"
|
| 109 |
-
|
| 110 |
-
if
|
| 111 |
-
print(f"[{time.strftime('%H:%M')}] rows={
|
| 112 |
-
last =
|
| 113 |
-
for gpu, p
|
| 114 |
-
log.close()
|
| 115 |
print(f"gpu{gpu} exit={p.returncode}")
|
| 116 |
|
| 117 |
|
|
@@ -122,8 +167,11 @@ def stage_score() -> None:
|
|
| 122 |
|
| 123 |
|
| 124 |
if __name__ == "__main__":
|
| 125 |
-
|
|
|
|
|
|
|
| 126 |
stage_bake()
|
|
|
|
| 127 |
stage_eval()
|
| 128 |
stage_score()
|
| 129 |
print("\nartifacts: baked/, ming_eval/results.jsonl, ming_eval/summary.json, ming_eval/wav/")
|
|
|
|
| 1 |
"""Kaggle notebook body for the WebFM eval run. Not imported by the app.
|
| 2 |
|
| 3 |
+
Pulled and executed by the kernel `kkonda/webfm-ming-tts-eval`, which does
|
| 4 |
+
nothing but snapshot_download idefinity/webfm-eval and exec this file. The run
|
| 5 |
+
logic lives here so it can change without touching the kernel.
|
| 6 |
+
|
| 7 |
+
Stages, in order:
|
| 8 |
+
|
| 9 |
+
1. install the pinned runtime, then prove `from ming_tts import MingTTS`
|
| 10 |
+
imports — repairing missing modules by name, because guessing the
|
| 11 |
+
transitive dependency set is how the first run died on `loguru`
|
| 12 |
+
2. clone the repo at the pinned commit, download weights, pull the bundle
|
| 13 |
+
3. bake prompt_latent / speaker_emb for the eight WebFM voices
|
| 14 |
+
4. smoke: one voice, two sentences, teacher + 3step. Cheaper to find API
|
| 15 |
+
drift here than 40 minutes into the matrix
|
| 16 |
+
5. the full matrix, one voice shard per visible GPU
|
| 17 |
+
6. score
|
| 18 |
+
|
| 19 |
+
Everything writes into /kaggle/working; ming_eval.py skips cells that already
|
| 20 |
+
have a row, so a killed session keeps its progress.
|
|
|
|
| 21 |
"""
|
| 22 |
import os
|
| 23 |
+
import re
|
| 24 |
import subprocess
|
| 25 |
import sys
|
| 26 |
import time
|
|
|
|
| 36 |
MODELS = "teacher,3step,4step"
|
| 37 |
HF_MIRROR = "https://hf-mirror.com"
|
| 38 |
|
| 39 |
+
# requirements.txt at PIN, minus torch/torchaudio: Kaggle ships a newer CUDA
|
| 40 |
+
# build and downgrading it would cost the session.
|
| 41 |
+
DEPS = [
|
| 42 |
+
"transformers==4.46.3", "tokenizers", "accelerate==1.3.0", "huggingface_hub",
|
| 43 |
+
"soundfile==0.12.1", "tqdm", "loguru", "x_transformers==2.9.2",
|
| 44 |
+
"diffusers==0.33.0", "onnxruntime", "onnx", "inflect", "einops", "packaging",
|
| 45 |
+
]
|
| 46 |
+
ALIASES = {"cv2": "opencv-python", "yaml": "pyyaml", "PIL": "pillow", "sklearn": "scikit-learn"}
|
| 47 |
+
|
| 48 |
|
| 49 |
def sh(cmd: str, check: bool = True, env: dict | None = None) -> int:
|
| 50 |
print(f"\n$ {cmd}", flush=True)
|
|
|
|
| 54 |
return rc
|
| 55 |
|
| 56 |
|
| 57 |
+
def pip(*pkgs: str) -> None:
|
| 58 |
+
sh("pip install -q " + " ".join(f'"{p}"' for p in pkgs), check=False)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
def pull(repo_id: str, local_dir: Path, repo_type: str = "model") -> None:
|
|
|
|
| 62 |
if local_dir.exists() and any(local_dir.iterdir()):
|
| 63 |
print(f"{local_dir} already populated")
|
| 64 |
return
|
| 65 |
+
code = ("from huggingface_hub import snapshot_download as s; "
|
| 66 |
+
f"s('{repo_id}', local_dir=r'{local_dir}', repo_type='{repo_type}')")
|
|
|
|
|
|
|
| 67 |
if sh(f'python3 -c "{code}"', check=False) != 0:
|
| 68 |
print("direct download failed, retrying through hf-mirror")
|
| 69 |
+
sh(f'python3 -c "{code}"', env=dict(os.environ, HF_ENDPOINT=HF_MIRROR))
|
| 70 |
+
|
| 71 |
|
| 72 |
+
def stage_repo() -> None:
|
| 73 |
+
"""Clone before the import probe, which imports from this directory."""
|
| 74 |
+
if not REPO.exists():
|
| 75 |
+
sh(f"git clone https://github.com/inclusionAI/Ming-3.0-tts.git {REPO}")
|
| 76 |
+
if sh(f"git -C {REPO} checkout {PIN}", check=False) != 0:
|
| 77 |
+
print(f"WARNING: commit {PIN} not found, staying on the default branch")
|
| 78 |
|
| 79 |
+
|
| 80 |
+
def stage_deps() -> None:
|
| 81 |
sh("nvidia-smi --query-gpu=name,memory.total --format=csv,noheader")
|
| 82 |
import torch
|
| 83 |
|
| 84 |
print("torch", torch.__version__, "cuda", torch.cuda.is_available(),
|
| 85 |
"devices", torch.cuda.device_count())
|
| 86 |
|
| 87 |
+
pip(*DEPS)
|
| 88 |
+
probe = ("import sys; sys.path.insert(0, r'%s'); from ming_tts import MingTTS; "
|
| 89 |
+
"print('import ok')" % REPO)
|
| 90 |
+
for attempt in range(6):
|
| 91 |
+
r = subprocess.run([sys.executable, "-c", probe], capture_output=True, text=True)
|
| 92 |
+
if r.returncode == 0:
|
| 93 |
+
print("ming_tts imports cleanly")
|
| 94 |
+
return
|
| 95 |
+
m = re.search(r"No module named '([^']+)'", r.stderr)
|
| 96 |
+
if not m:
|
| 97 |
+
print(r.stderr[-3000:])
|
| 98 |
+
raise SystemExit("ming_tts import failed for a reason pip cannot repair")
|
| 99 |
+
missing = m.group(1).split(".")[0]
|
| 100 |
+
pkg = ALIASES.get(missing, missing)
|
| 101 |
+
print(f"[{attempt+1}] missing '{missing}' -> installing '{pkg}'")
|
| 102 |
+
pip(pkg)
|
| 103 |
+
raise SystemExit("could not satisfy ming_tts imports")
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def stage_prepare() -> None:
|
| 107 |
pull(WEIGHTS, MODEL)
|
| 108 |
pull(BUNDLE_REPO, BUNDLE, repo_type="dataset")
|
| 109 |
|
|
|
|
| 115 |
sh(f"cd {ROOT} && EVAL_DATA={BUNDLE} python3 {BUNDLE}/kaggle/bake_voices.py")
|
| 116 |
|
| 117 |
|
| 118 |
+
def run_eval(tag: str, voices: list[str], models: str, limit: int, gpu: int = 0) -> subprocess.Popen:
|
| 119 |
+
env = dict(os.environ, CUDA_VISIBLE_DEVICES=str(gpu), EVAL_DATA=str(BUNDLE),
|
| 120 |
+
VOICES=",".join(voices), MODELS=models, LIMIT=str(limit))
|
| 121 |
+
log = open(ROOT / f"eval_{tag}.log", "w")
|
| 122 |
+
return subprocess.Popen([sys.executable, str(BUNDLE / "kaggle/ming_eval.py")],
|
| 123 |
+
env=env, stdout=log, stderr=subprocess.STDOUT, cwd=str(ROOT))
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def stage_smoke() -> None:
|
| 127 |
+
"""One voice, two sentences. Catches API drift before the long run."""
|
| 128 |
+
if (ROOT / "smoke.ok").exists():
|
| 129 |
+
return
|
| 130 |
+
p = run_eval("smoke", ["v01"], "teacher,3step", 2)
|
| 131 |
+
p.wait()
|
| 132 |
+
rows = ROOT / "ming_eval/results.jsonl"
|
| 133 |
+
n = sum(1 for _ in rows.open()) if rows.exists() else 0
|
| 134 |
+
if n < 4:
|
| 135 |
+
print((ROOT / "eval_smoke.log").read_text()[-4000:])
|
| 136 |
+
raise SystemExit(f"smoke produced {n} rows, expected at least 4")
|
| 137 |
+
(ROOT / "smoke.ok").write_text("ok")
|
| 138 |
+
print(f"smoke ok ({n} rows)")
|
| 139 |
+
|
| 140 |
+
|
| 141 |
def stage_eval() -> None:
|
| 142 |
import torch
|
| 143 |
|
| 144 |
+
n_gpu = max(1, torch.cuda.device_count())
|
| 145 |
voices = [f"v{i:02d}" for i in range(1, 9)]
|
| 146 |
+
shards = [voices[i::n_gpu] for i in range(n_gpu)]
|
| 147 |
+
print(f"{n_gpu} GPU(s), shards: {shards}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
+
procs = [(gpu, run_eval(f"gpu{gpu}", shard, MODELS, 40, gpu))
|
| 150 |
+
for gpu, shard in enumerate(shards)]
|
| 151 |
last = 0.0
|
| 152 |
+
while any(p.poll() is None for _, p in procs):
|
| 153 |
time.sleep(60)
|
| 154 |
rows = ROOT / "ming_eval/results.jsonl"
|
| 155 |
+
n = sum(1 for _ in rows.open()) if rows.exists() else 0
|
| 156 |
+
if n != last:
|
| 157 |
+
print(f"[{time.strftime('%H:%M')}] rows={n}", flush=True)
|
| 158 |
+
last = n
|
| 159 |
+
for gpu, p in procs:
|
|
|
|
| 160 |
print(f"gpu{gpu} exit={p.returncode}")
|
| 161 |
|
| 162 |
|
|
|
|
| 167 |
|
| 168 |
|
| 169 |
if __name__ == "__main__":
|
| 170 |
+
stage_repo()
|
| 171 |
+
stage_deps()
|
| 172 |
+
stage_prepare()
|
| 173 |
stage_bake()
|
| 174 |
+
stage_smoke()
|
| 175 |
stage_eval()
|
| 176 |
stage_score()
|
| 177 |
print("\nartifacts: baked/, ming_eval/results.jsonl, ming_eval/summary.json, ming_eval/wav/")
|