#!/bin/bash set -e export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.local/bin:$PATH" # Load RunPod env vars (Docker injects them into PID 1 but SSH doesn't inherit them) if [ -f /proc/1/environ ]; then while IFS= read -r -d '' line; do export "$line" done < /proc/1/environ fi exec > >(tee -a /workspace/training_boot.log) 2>&1 echo "=== Training startup $(date) ===" echo "MODEL_NAME=$MODEL_NAME" nvidia-smi -L echo "=== Installing dependencies ===" pip install "transformers>=4.45,<5" "peft>=0.13,<0.15" trl datasets accelerate bitsandbytes huggingface_hub sentencepiece protobuf 2>&1 | tail -5 pip install flash-attn --no-build-isolation 2>/dev/null || echo "flash-attn skip" echo "=== HF Login ===" python3 -c "from huggingface_hub import login; login(token='$HF_TOKEN')" echo "=== Downloading training script ===" python3 -c " from huggingface_hub import hf_hub_download hf_hub_download(repo_id='$DATASET_REPO', filename='train_lora.py', repo_type='dataset', local_dir='/workspace') print('Downloaded train_lora.py') " mkdir -p /workspace/output /workspace/hf_cache echo "=== Starting training at $(date) ===" python3 /workspace/train_lora.py 2>&1 | tee /workspace/training.log echo "DONE" > /workspace/DONE echo "=== Training complete at $(date) ==="