| #!/bin/bash |
| |
| |
| set -euo pipefail |
|
|
| echo "=== Killing old train session (if any) ===" |
| tmux kill-session -t scriptwriter-train 2>/dev/null || true |
| pkill -f 'train_runpod.py' 2>/dev/null || true |
|
|
| echo "=== Restoring torch 2.4.1 + matching torchvision (RunPod image stack) ===" |
| python3 -m pip install -q --upgrade pip |
| |
| python3 -m pip install -q --force-reinstall \ |
| "torch==2.4.1" "torchvision==0.19.1" "torchaudio==2.4.1" \ |
| --index-url https://download.pytorch.org/whl/cu124 |
|
|
| echo "=== Installing pinned HF train stack (no torch upgrade) ===" |
| python3 -m pip uninstall -y transformers peft trl accelerate 2>/dev/null || true |
| python3 -m pip install -q \ |
| "transformers==4.46.3" \ |
| "peft==0.13.2" \ |
| "trl==0.12.1" \ |
| "accelerate==0.34.2" \ |
| "datasets>=2.19.0,<3.1" \ |
| "huggingface_hub>=0.24.0,<0.30" \ |
| "safetensors>=0.4.0" \ |
| "sentencepiece>=0.2.0" \ |
| "protobuf>=4.25.0" \ |
| "pyyaml>=6.0.0" \ |
| "tqdm>=4.66.0" \ |
| "bitsandbytes>=0.43.0,<0.46" |
|
|
| |
| python3 -m pip install -q \ |
| "torch==2.4.1" "torchvision==0.19.1" "torchaudio==2.4.1" \ |
| --index-url https://download.pytorch.org/whl/cu124 |
|
|
| python3 - <<'PY' |
| import torch, torchvision, transformers, peft, trl |
| print("torch", torch.__version__, "cuda", torch.cuda.is_available(), "gpus", torch.cuda.device_count()) |
| print("torchvision", torchvision.__version__) |
| print("transformers", transformers.__version__) |
| print("peft", peft.__version__) |
| print("trl", trl.__version__) |
| from peft import LoraConfig |
| from transformers import AutoModelForCausalLM |
| print("imports ok") |
| PY |
|
|
| DEST=/workspace/scriptwriter-runpod |
| TGZ=/tmp/scriptwriter-runpod-ready.tgz |
| echo "=== Refreshing trainer scripts ===" |
| curl -fsSL "https://huggingface.co/datasets/datamatters24/scriptwriter-runpod/resolve/main/scriptwriter-runpod-ready.tgz" -o "$TGZ" |
| rm -rf "$DEST" |
| mkdir -p "$DEST" |
| tar xzf "$TGZ" -C "$DEST" --strip-components=1 --no-same-owner --no-same-permissions |
|
|
| export WORKDIR="$DEST" |
| export DATA_DIR=/workspace/data/processed |
| export OUTPUT_DIR=/workspace/models/lora |
| export HF_DATASET_REPO="${HF_DATASET_REPO:-datamatters24/scriptwriter-corpus-ia}" |
| export HF_MODEL_REPO="${HF_MODEL_REPO:-datamatters24/scriptwriter-lora-ia}" |
| export BASE_MODEL="${BASE_MODEL:-meta-llama/Llama-3.2-3B-Instruct}" |
| |
| export RUNPOD_SKIP_FORCE_PIP=1 |
|
|
| if [[ ! -f /workspace/data/processed/train.jsonl ]]; then |
| echo "=== train.jsonl missing — downloading dataset ${HF_DATASET_REPO} ===" |
| mkdir -p /workspace/data/processed |
| python3 - <<'PY' |
| import os |
| from pathlib import Path |
| from huggingface_hub import snapshot_download, login |
| token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN") |
| if not token: |
| raise SystemExit("HF_TOKEN not set in environment — set it in RunPod and retry") |
| login(token=token, add_to_git_credential=False) |
| dest = Path("/workspace/data/processed") |
| snapshot_download( |
| repo_id=os.environ.get("HF_DATASET_REPO", "datamatters24/scriptwriter-corpus-ia"), |
| repo_type="dataset", |
| local_dir=str(dest), |
| token=token, |
| ) |
| train = dest / "train.jsonl" |
| if not train.exists(): |
| for alt in ("train-ia.jsonl", "train-local.jsonl", "checkpoint-ia.jsonl"): |
| src = dest / alt |
| if src.exists() and src.stat().st_size > 0: |
| train.write_text(src.read_text(encoding="utf-8"), encoding="utf-8") |
| print(f"Created train.jsonl from {alt}") |
| break |
| if not train.exists(): |
| raise SystemExit("Download finished but train.jsonl still missing") |
| print(f"train.jsonl lines: {sum(1 for _ in train.open() if _.strip())}") |
| PY |
| fi |
|
|
| if [[ ! -f /workspace/data/processed/train.jsonl ]]; then |
| echo "ERROR: /workspace/data/processed/train.jsonl missing" |
| exit 1 |
| fi |
|
|
| cd "$DEST" |
| bash scripts/runpod_train_tmux.sh |
|
|