director: 40 topics + collect/train/eval driver
Browse files
kaggle/notebook_director_train.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Kaggle notebook body: build the director's training set, fine-tune, re-score.
|
| 2 |
+
|
| 3 |
+
Three subprocesses, same upgraded environment:
|
| 4 |
+
|
| 5 |
+
1. collect - sample the base model, keep every script that already satisfies the
|
| 6 |
+
TTS contract (acceptance is about 60% with the line format, so 160 scripts
|
| 7 |
+
costs roughly 35 minutes).
|
| 8 |
+
2. train - fine-tune the last six blocks and the head on those 160.
|
| 9 |
+
3. eval - score the tuned model on the same topic list as the baseline.
|
| 10 |
+
|
| 11 |
+
Everything runs out-of-process because transformers has to be upgraded to 5.x
|
| 12 |
+
and this notebook already imported huggingface_hub to fetch the bundle.
|
| 13 |
+
"""
|
| 14 |
+
import os
|
| 15 |
+
import subprocess
|
| 16 |
+
import sys
|
| 17 |
+
|
| 18 |
+
BUNDLE = "/kaggle/working/webfm-eval"
|
| 19 |
+
ENV = dict(os.environ, WORK_ROOT="/kaggle/working")
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def sh(cmd: str) -> None:
|
| 23 |
+
print(f"$ {cmd}", flush=True)
|
| 24 |
+
if subprocess.run(cmd, shell=True).returncode != 0:
|
| 25 |
+
raise SystemExit(f"failed: {cmd}")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def run(script: str, **env) -> int:
|
| 29 |
+
target = os.path.join(BUNDLE, "kaggle", script)
|
| 30 |
+
print(f"\n===== {script} {env} =====", flush=True)
|
| 31 |
+
rc = subprocess.run([sys.executable, target], env=dict(ENV, **env)).returncode
|
| 32 |
+
print(f"----- {script} rc={rc} -----", flush=True)
|
| 33 |
+
return rc
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def main() -> None:
|
| 37 |
+
sh("pip install -q --upgrade 'transformers>=5' 'huggingface_hub>=1.31,<2' accelerate")
|
| 38 |
+
|
| 39 |
+
if not os.path.exists(os.path.join(BUNDLE, "kaggle", "director_probe.py")):
|
| 40 |
+
raise SystemExit("director_probe.py missing")
|
| 41 |
+
|
| 42 |
+
run("director_probe.py", MODE="collect", TARGET="160", MAX_TRIES="700")
|
| 43 |
+
if run("director_sft.py", EPOCHS="4", TRAIN_LAYERS="6") != 0:
|
| 44 |
+
raise SystemExit("training failed")
|
| 45 |
+
run("director_probe.py", MODE="eval", N_SAMPLES="12",
|
| 46 |
+
DIRECTOR_MODEL="/kaggle/working/director/model")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
if __name__ == "__main__":
|
| 50 |
+
main()
|