training-runtime / bootstrap.sh
gregjanik's picture
Upload bootstrap.sh with huggingface_hub
06271d9 verified
#!/usr/bin/env bash
set -euo pipefail
# ============================================================================
# bootstrap.sh — Zero-image entrypoint for RunPod Instant Clusters.
#
# This script runs inside the stock runpod/pytorch base image (no custom
# Docker build). It:
# 1. Fixes the Python 3.10 → 3.12 symlink mismatch
# 2. Exports environment variables matching Dockerfile.slim
# 3. Configures SSH for multi-node communication
# 4. Installs vim (apt, one-time)
# 5. Creates workspace directories
# 6. Hands off to slim-entrypoint.sh (pip deps + app launch)
#
# The HF download of f13rnd/training-runtime into /opt/f13/ is done by the
# RunPod CMD *before* this script runs, so all files are already in place.
#
# RunPod template CMD:
# bash -c "pip install -q huggingface_hub && \
# hf download f13rnd/training-runtime --repo-type dataset \
# --local-dir /opt/f13 ${HF_TOKEN:+--token $HF_TOKEN} && \
# chmod +x /opt/f13/*.sh /opt/f13/scripts/*.sh && \
# exec /opt/f13/bootstrap.sh"
# ============================================================================
echo "[bootstrap] Starting zero-image bootstrap..."
# --- Python 3.12 symlink fix ---
# The runpod/pytorch base ships python3 -> 3.10 but pip/torch target 3.12.
if [ -x /usr/bin/python3.12 ]; then
ln -sf /usr/bin/python3.12 /usr/bin/python3
ln -sf /usr/bin/python3.12 /usr/bin/python
echo "[bootstrap] python3 -> python3.12"
fi
# --- Environment variables (match Dockerfile.slim) ---
export DEBIAN_FRONTEND=noninteractive
export PYTHONUNBUFFERED=1
export PYTORCH_ALLOC_CONF="${PYTORCH_ALLOC_CONF:-expandable_segments:True}"
export HF_HOME="${HF_HOME:-/workspace/hf-cache}"
export MODELSCOPE_CACHE="${MODELSCOPE_CACHE:-/workspace/ms-cache}"
export HF_HUB_DISABLE_PROGRESS_BARS="${HF_HUB_DISABLE_PROGRESS_BARS:-0}"
export HF_HUB_VERBOSITY="${HF_HUB_VERBOSITY:-info}"
export TRANSFORMERS_VERBOSITY="${TRANSFORMERS_VERBOSITY:-info}"
# --- apt packages (idempotent) ---
if ! command -v vim &>/dev/null; then
apt-get update -qq && apt-get install -y --no-install-recommends vim \
&& rm -rf /var/lib/apt/lists/*
echo "[bootstrap] vim installed"
fi
# --- SSH setup ---
mkdir -p /var/run/sshd
if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
ssh-keygen -A
fi
sed -i 's/#*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
# --- Workspace directories ---
mkdir -p /workspace/data /workspace/output /workspace/config
echo "[bootstrap] Bootstrap complete, handing off to slim-entrypoint.sh"
exec /opt/f13/slim-entrypoint.sh "$@"