ensemble-pipeline / setup.sh
MikeGreen2710's picture
requirements_train.txt: complete pins incl. matplotlib/scipy/tqdm/datasets
f384e12 verified
Raw
History Blame Contribute Delete
5.1 kB
#!/usr/bin/env bash
# =============================================================================
# setup.sh β€” reproducible environment for the ensemble-pipeline repo
#
# Usage (fresh VM):
# hf download MikeGreen2710/ensemble-pipeline setup.sh --repo-type dataset --local-dir .
# (or: wget https://huggingface.co/datasets/MikeGreen2710/ensemble-pipeline/resolve/main/setup.sh)
# bash setup.sh # installs miniconda if needed + creates env 'avm'
# conda activate avm
#
# Version policy:
# - If requirements_train.txt exists next to this script, it is installed
# verbatim (exact VM1 parity β€” preferred).
# - Otherwise falls back to the known-good pins below (the stack every fix
# in the July 2026 debugging session was validated against).
# - transformers MUST stay 4.x: the generator/inference scripts use 4.x
# Trainer APIs (custom compute_loss KL objective, custom optimizer
# injection). transformers 5.x breaks these, sometimes silently.
# =============================================================================
set -euo pipefail
ENV_NAME="${1:-avm}"
PYTHON_VERSION="3.12"
MINICONDA_DIR="/content/miniconda3"
echo "== ensemble-pipeline setup: env='$ENV_NAME' python=$PYTHON_VERSION =="
# ── 1. conda: use existing install if any, else miniconda ────────────────────
if command -v conda >/dev/null 2>&1; then
echo "-- conda already present: $(conda --version)"
elif [ -x "$MINICONDA_DIR/bin/conda" ]; then
echo "-- miniconda present at $MINICONDA_DIR"
else
echo "-- installing miniconda -> $MINICONDA_DIR"
ARCH=$(uname -m)
curl -fsSL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-${ARCH}.sh" -o /tmp/miniconda.sh
bash /tmp/miniconda.sh -b -p "$MINICONDA_DIR"
rm /tmp/miniconda.sh
"$MINICONDA_DIR/bin/conda" init bash
echo "-- NOTE: conda init written to ~/.bashrc (takes effect in new shells)"
fi
# make conda usable in THIS shell regardless of init state
source "$(conda info --base 2>/dev/null || echo "$MINICONDA_DIR")/etc/profile.d/conda.sh"
# ── 1b. accept default-channel ToS (required by Miniconda 2025+; no-op on old) ─
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main 2>/dev/null || true
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r 2>/dev/null || true
# ── 2. env: create if missing ────────────────────────────────────────────────
if conda env list | grep -qE "^${ENV_NAME}[[:space:]]"; then
echo "-- env '$ENV_NAME' exists β€” reusing (packages will be updated to pins)"
else
conda create -y -n "$ENV_NAME" "python=$PYTHON_VERSION"
fi
conda activate "$ENV_NAME"
echo "-- python: $(python --version) @ $(which python)"
# ── 3. packages ──────────────────────────────────────────────────────────────
python -m pip install --upgrade pip
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -f "$SCRIPT_DIR/requirements_train.txt" ]; then
echo "-- installing from requirements_train.txt (exact parity)"
pip install -r "$SCRIPT_DIR/requirements_train.txt"
else
echo "-- requirements_train.txt not found; installing known-good pins"
# torch: default wheel bundles CUDA 12.x runtime; override with
# TORCH_SPEC='torch==2.x.y --index-url https://download.pytorch.org/whl/cu121'
pip install ${TORCH_SPEC:-torch}
pip install \
"transformers==4.56.2" \
"huggingface_hub==0.34.4" \
"accelerate==1.10.1" \
"datasets>=2.19,<4" \
"safetensors>=0.4" \
"tokenizers>=0.19" \
"sentencepiece" \
"protobuf" \
"scikit-learn==1.7.2" \
"lightgbm" \
"pandas" \
"numpy<3" \
"pyarrow" \
"joblib" \
"matplotlib" \
"tqdm"
fi
# ── 4. verification gate β€” fails loudly if the stack is wrong ────────────────
python - << 'PYEOF'
import sys
import torch, transformers, accelerate, safetensors, datasets, sklearn
import huggingface_hub as hub
print("torch :", torch.__version__, "| cuda:", torch.cuda.is_available())
print("transformers :", transformers.__version__)
print("huggingface :", hub.__version__)
print("accelerate :", accelerate.__version__)
print("sklearn :", sklearn.__version__)
major = int(transformers.__version__.split(".")[0])
assert major == 4, (
"transformers %s is not 4.x β€” the pipeline's Trainer customisations "
"(KL compute_loss, custom optimizer) are 4.x APIs" % transformers.__version__)
print("\nOK β€” environment ready. Activate with: conda activate " + "${ENV_NAME}".strip() if False else "")
PYEOF
echo ""
echo "== done. next steps =="
echo " conda activate $ENV_NAME"
echo " python scripts/hf_sync.py pull --repo MikeGreen2710/ensemble-pipeline # or selective hf download"