Download kaggle/notebook_pipeline.py from idefinity/webfm-eval: direct link, hf CLI and curl.
- Browser
- Download file 4.15 kB
-
https://huggingface.co/datasets/idefinity/webfm-eval/resolve/main/kaggle/notebook_pipeline.py
- Command line
-
hf download hf://datasets/idefinity/webfm-eval/kaggle/notebook_pipeline.py
-
curl -L -o notebook_pipeline.py https://huggingface.co/datasets/idefinity/webfm-eval/resolve/main/kaggle/notebook_pipeline.py
4.15 kB
| """Kaggle notebook body: director -> TTS in one run, with two interpreters. | |
| The clash: Ming pins transformers 4.46.3, Qwen3.5 needs 5.x, and one | |
| site-packages cannot hold both. So transformers 5 is installed into a private | |
| directory and the director runs with PYTHONPATH pointing at it, while the radio | |
| stage keeps the pinned 4.46.3. | |
| Order matters: Ming's dependencies are installed first and never touched again. | |
| Stages: | |
| 1. Ming environment (repo, pinned deps, weights, bundle) | |
| 2. transformers 5 into /kaggle/working/tf5 | |
| 3. fine-tune the director on the 160 scripts in the bundle (skipped if the | |
| model is already on disk) | |
| 4. director writes one programme to director/script.json | |
| 5. radio stage renders it with the 4-step student and the teacher | |
| """ | |
| import os | |
| import subprocess | |
| import sys | |
| import time | |
| ROOT = "/kaggle/working" | |
| BUNDLE = f"{ROOT}/webfm-eval" | |
| TF5 = f"{ROOT}/tf5" | |
| def log(msg: str) -> None: | |
| print(f"[{time.strftime('%H:%M:%S')}] {msg}", flush=True) | |
| def sh(cmd: str, env: dict | None = None) -> int: | |
| log(f"$ {cmd}") | |
| rc = subprocess.run(cmd, shell=True, env=env).returncode | |
| if rc != 0: | |
| log(f"failed ({rc}): {cmd}") | |
| return rc | |
| def stage_ming() -> None: | |
| if not os.path.exists(f"{ROOT}/Ming-3.0-tts"): | |
| sh(f"git clone https://github.com/inclusionAI/Ming-3.0-tts.git {ROOT}/Ming-3.0-tts") | |
| sh(f"git -C {ROOT}/Ming-3.0-tts checkout e999c39") | |
| sh('pip install -q "transformers==4.46.3" tokenizers "accelerate==1.3.0" ' | |
| 'huggingface_hub "soundfile==0.12.1" tqdm loguru "x_transformers==2.9.2" ' | |
| '"diffusers==0.33.0" onnxruntime onnx onnx_ir onnxscript inflect einops packaging') | |
| if not os.path.exists(f"{ROOT}/Ming-3.0-tts-0.5b"): | |
| sh("python3 -c \"from huggingface_hub import snapshot_download as s; " | |
| f"s('inclusionAI/Ming-3.0-tts-0.5B', local_dir=r'{ROOT}/Ming-3.0-tts-0.5b', repo_type='model')\"") | |
| def stage_tf5() -> None: | |
| if os.path.exists(f"{TF5}/transformers"): | |
| log("transformers 5 already installed") | |
| return | |
| # Private target: never touches the pinned environment Ming uses. Only | |
| # transformers and hub go in; everything else (torch, accelerate) resolves | |
| # from the main interpreter through PYTHONPATH fallback. | |
| sh(f"pip install -q --target {TF5} 'transformers>=5' 'huggingface_hub>=1.31,<2'") | |
| out = subprocess.run([sys.executable, "-c", | |
| "import transformers; print(transformers.__version__)"], | |
| capture_output=True, text=True, | |
| env=dict(os.environ, PYTHONPATH=TF5)) | |
| log(f"tf5 transformers: {out.stdout.strip() or out.stderr[-300:]}") | |
| def main() -> None: | |
| log("== stage 1: ming ==") | |
| stage_ming() | |
| from huggingface_hub import snapshot_download | |
| snapshot_download("idefinity/webfm-eval", repo_type="dataset", local_dir=BUNDLE) | |
| log("== stage 2: transformers 5 in a private dir ==") | |
| stage_tf5() | |
| env5 = dict(os.environ, WORK_ROOT=ROOT, PYTHONPATH=TF5) | |
| model = f"{ROOT}/director/model" | |
| if not os.path.exists(f"{model}/config.json"): | |
| log("== stage 3: fine-tune the director ==") | |
| rc = subprocess.run([sys.executable, f"{BUNDLE}/kaggle/director_sft.py"], | |
| env=env5).returncode | |
| log(f"train rc={rc}") | |
| if rc != 0: | |
| raise SystemExit("director training failed") | |
| log("== stage 4: write the programme ==") | |
| rc = subprocess.run([sys.executable, f"{BUNDLE}/kaggle/director_probe.py"], | |
| env=dict(env5, MODE="script", | |
| TOPIC=os.environ.get("TOPIC", "雨夜的末班公交"), | |
| DIRECTOR_MODEL=model)).returncode | |
| log(f"director rc={rc}") | |
| script = f"{ROOT}/director/script.json" | |
| if not os.path.exists(script): | |
| raise SystemExit("no script.json") | |
| log("== stage 5: render ==") | |
| rc = subprocess.run([sys.executable, f"{BUNDLE}/kaggle/radio_demo.py"], | |
| env=dict(os.environ, WORK_ROOT=ROOT, SCRIPT_FILE=script)).returncode | |
| log(f"radio rc={rc}") | |
| if __name__ == "__main__": | |
| main() | |