zziang commited on
Commit
406e494
·
verified ·
1 Parent(s): 2003020

director -> tts pipeline with two interpreters

Browse files
Files changed (1) hide show
  1. kaggle/notebook_pipeline.py +103 -0
kaggle/notebook_pipeline.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Kaggle notebook body: director -> TTS in one run, with two interpreters.
2
+
3
+ The clash: Ming pins transformers 4.46.3, Qwen3.5 needs 5.x, and one
4
+ site-packages cannot hold both. So transformers 5 is installed into a private
5
+ directory and the director runs with PYTHONPATH pointing at it, while the radio
6
+ stage keeps the pinned 4.46.3.
7
+
8
+ Order matters: Ming's dependencies are installed first and never touched again.
9
+
10
+ Stages:
11
+ 1. Ming environment (repo, pinned deps, weights, bundle)
12
+ 2. transformers 5 into /kaggle/working/tf5
13
+ 3. fine-tune the director on the 160 scripts in the bundle (skipped if the
14
+ model is already on disk)
15
+ 4. director writes one programme to director/script.json
16
+ 5. radio stage renders it with the 4-step student and the teacher
17
+ """
18
+ import os
19
+ import subprocess
20
+ import sys
21
+ import time
22
+
23
+ ROOT = "/kaggle/working"
24
+ BUNDLE = f"{ROOT}/webfm-eval"
25
+ TF5 = f"{ROOT}/tf5"
26
+
27
+
28
+ def log(msg: str) -> None:
29
+ print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True)
30
+
31
+
32
+ def sh(cmd: str, env: dict | None = None) -> int:
33
+ log(f"$ {cmd}")
34
+ rc = subprocess.run(cmd, shell=True, env=env).returncode
35
+ if rc != 0:
36
+ log(f"failed ({rc}): {cmd}")
37
+ return rc
38
+
39
+
40
+ def stage_ming() -> None:
41
+ if not os.path.exists(f"{ROOT}/Ming-3.0-tts"):
42
+ sh(f"git clone https://github.com/inclusionAI/Ming-3.0-tts.git {ROOT}/Ming-3.0-tts")
43
+ sh(f"git -C {ROOT}/Ming-3.0-tts checkout e999c39")
44
+ sh('pip install -q "transformers==4.46.3" tokenizers "accelerate==1.3.0" '
45
+ 'huggingface_hub "soundfile==0.12.1" tqdm loguru "x_transformers==2.9.2" '
46
+ '"diffusers==0.33.0" onnxruntime onnx onnx_ir onnxscript inflect einops packaging')
47
+ if not os.path.exists(f"{ROOT}/Ming-3.0-tts-0.5b"):
48
+ sh("python3 -c \"from huggingface_hub import snapshot_download as s; "
49
+ f"s('inclusionAI/Ming-3.0-tts-0.5B', local_dir=r'{ROOT}/Ming-3.0-tts-0.5b', repo_type='model')\"")
50
+
51
+
52
+ def stage_tf5() -> None:
53
+ if os.path.exists(f"{TF5}/transformers"):
54
+ log("transformers 5 already installed")
55
+ return
56
+ # Private target: never touches the pinned environment Ming uses. Only
57
+ # transformers and hub go in; everything else (torch, accelerate) resolves
58
+ # from the main interpreter through PYTHONPATH fallback.
59
+ sh(f"pip install -q --target {TF5} 'transformers>=5' 'huggingface_hub>=1.31,<2'")
60
+ out = subprocess.run([sys.executable, "-c",
61
+ "import transformers; print(transformers.__version__)"],
62
+ capture_output=True, text=True,
63
+ env=dict(os.environ, PYTHONPATH=TF5))
64
+ log(f"tf5 transformers: {out.stdout.strip() or out.stderr[-300:]}")
65
+
66
+
67
+ def main() -> None:
68
+ log("== stage 1: ming ==")
69
+ stage_ming()
70
+ from huggingface_hub import snapshot_download
71
+ snapshot_download("idefinity/webfm-eval", repo_type="dataset", local_dir=BUNDLE)
72
+
73
+ log("== stage 2: transformers 5 in a private dir ==")
74
+ stage_tf5()
75
+
76
+ env5 = dict(os.environ, WORK_ROOT=ROOT, PYTHONPATH=TF5)
77
+ model = f"{ROOT}/director/model"
78
+ if not os.path.exists(f"{model}/config.json"):
79
+ log("== stage 3: fine-tune the director ==")
80
+ rc = subprocess.run([sys.executable, f"{BUNDLE}/kaggle/director_sft.py"],
81
+ env=env5).returncode
82
+ log(f"train rc={rc}")
83
+ if rc != 0:
84
+ raise SystemExit("director training failed")
85
+
86
+ log("== stage 4: write the programme ==")
87
+ rc = subprocess.run([sys.executable, f"{BUNDLE}/kaggle/director_probe.py"],
88
+ env=dict(env5, MODE="script",
89
+ TOPIC=os.environ.get("TOPIC", "雨夜的末班公交"),
90
+ DIRECTOR_MODEL=model)).returncode
91
+ log(f"director rc={rc}")
92
+ script = f"{ROOT}/director/script.json"
93
+ if not os.path.exists(script):
94
+ raise SystemExit("no script.json")
95
+
96
+ log("== stage 5: render ==")
97
+ rc = subprocess.run([sys.executable, f"{BUNDLE}/kaggle/radio_demo.py"],
98
+ env=dict(os.environ, WORK_ROOT=ROOT, SCRIPT_FILE=script)).returncode
99
+ log(f"radio rc={rc}")
100
+
101
+
102
+ if __name__ == "__main__":
103
+ main()