Upload install_env_cpu.sh with huggingface_hub
Browse files- install_env_cpu.sh +133 -0
install_env_cpu.sh
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
|
| 4 |
+
# ==== READ ENV NAME PARAMETER ====
|
| 5 |
+
if [ $# -lt 1 ]; then
|
| 6 |
+
echo "Usage: $0 <env_name> [python_version] [requirements_file]"
|
| 7 |
+
echo " env_name = name of the new conda environment"
|
| 8 |
+
echo " python_version = (optional) default 3.10"
|
| 9 |
+
echo " requirements_file= (optional) default requirements.txt"
|
| 10 |
+
exit 1
|
| 11 |
+
fi
|
| 12 |
+
|
| 13 |
+
ENV_NAME="$1"
|
| 14 |
+
PY_VER="${2:-3.10}"
|
| 15 |
+
REQ_FILE="${3:-requirements.txt}"
|
| 16 |
+
|
| 17 |
+
LOG_DIR="install_logs"
|
| 18 |
+
SUCCESS_LOG="$LOG_DIR/success.log"
|
| 19 |
+
FAIL_LOG="$LOG_DIR/failures.log"
|
| 20 |
+
FULL_LOG="$LOG_DIR/full_output.log"
|
| 21 |
+
|
| 22 |
+
mkdir -p "$LOG_DIR"
|
| 23 |
+
: > "$SUCCESS_LOG"
|
| 24 |
+
: > "$FAIL_LOG"
|
| 25 |
+
: > "$FULL_LOG"
|
| 26 |
+
source ~/miniconda3/etc/profile.d/conda.sh
|
| 27 |
+
# ==== LOAD CONDA (Miniconda) ====
|
| 28 |
+
if ! command -v conda >/dev/null 2>&1; then
|
| 29 |
+
if [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then
|
| 30 |
+
# shellcheck disable=SC1091
|
| 31 |
+
source "$HOME/miniconda3/etc/profile.d/conda.sh"
|
| 32 |
+
elif [ -f "$HOME/anaconda3/etc/profile.d/conda.sh" ]; then
|
| 33 |
+
# shellcheck disable=SC1091
|
| 34 |
+
source "$HOME/anaconda3/etc/profile.d/conda.sh"
|
| 35 |
+
else
|
| 36 |
+
echo "❌ Could not find conda.sh. Ensure Miniconda is installed and try again."
|
| 37 |
+
exit 1
|
| 38 |
+
fi
|
| 39 |
+
fi
|
| 40 |
+
|
| 41 |
+
# ==== CREATE ENV ====
|
| 42 |
+
if conda env list | awk '{print $1}' | grep -qx "$ENV_NAME"; then
|
| 43 |
+
echo "ℹ️ Conda env '$ENV_NAME' already exists. Skipping creation."
|
| 44 |
+
else
|
| 45 |
+
echo "🚀 Creating conda env '$ENV_NAME' with Python $PY_VER ..."
|
| 46 |
+
conda create -n "$ENV_NAME" "python=$PY_VER" -y | tee -a "$FULL_LOG"
|
| 47 |
+
fi
|
| 48 |
+
|
| 49 |
+
# ==== ACTIVATE ENV ====
|
| 50 |
+
echo "🔧 Activating env '$ENV_NAME' ..."
|
| 51 |
+
conda activate "$ENV_NAME"
|
| 52 |
+
|
| 53 |
+
# Ensure pip is fresh
|
| 54 |
+
python -m pip install --upgrade pip setuptools wheel | tee -a "$FULL_LOG"
|
| 55 |
+
|
| 56 |
+
# Keep setuptools pinned for test_common1 to ensure pkg_resources works.
|
| 57 |
+
if [[ "$ENV_NAME" == "test_common1" ]]; then
|
| 58 |
+
python -m pip install --force-reinstall --no-cache-dir "setuptools==73.0.1" | tee -a "$FULL_LOG"
|
| 59 |
+
fi
|
| 60 |
+
|
| 61 |
+
pip_install_one() {
|
| 62 |
+
local pkg="$1"
|
| 63 |
+
|
| 64 |
+
# PyTorch wheels with local version tags (+cpu / +cuXXX) are not on the default PyPI index.
|
| 65 |
+
# Use the official PyTorch wheel index as an additional source for those packages only.
|
| 66 |
+
case "$pkg" in
|
| 67 |
+
torch==*+cpu|torchvision==*+cpu|torchaudio==*+cpu)
|
| 68 |
+
python -m pip install "$pkg" --extra-index-url https://download.pytorch.org/whl/cpu
|
| 69 |
+
return $?
|
| 70 |
+
;;
|
| 71 |
+
torch==*+cu*|torchvision==*+cu*|torchaudio==*+cu*)
|
| 72 |
+
local cu="${pkg##*+cu}"
|
| 73 |
+
python -m pip install "$pkg" --extra-index-url "https://download.pytorch.org/whl/cu${cu}"
|
| 74 |
+
return $?
|
| 75 |
+
;;
|
| 76 |
+
*)
|
| 77 |
+
python -m pip install "$pkg"
|
| 78 |
+
return $?
|
| 79 |
+
;;
|
| 80 |
+
esac
|
| 81 |
+
}
|
| 82 |
+
# ==== INSTALL ONE BY ONE ====
|
| 83 |
+
if [ ! -f "$REQ_FILE" ]; then
|
| 84 |
+
echo "❌ Requirements file '$REQ_FILE' not found!"
|
| 85 |
+
exit 1
|
| 86 |
+
fi
|
| 87 |
+
|
| 88 |
+
echo "📦 Installing packages from '$REQ_FILE' one by one..."
|
| 89 |
+
while IFS= read -r pkg || [[ -n "${pkg:-}" ]]; do
|
| 90 |
+
pkg="$(echo "$pkg" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
|
| 91 |
+
[[ -z "$pkg" || "$pkg" =~ ^# ]] && continue
|
| 92 |
+
|
| 93 |
+
echo "====================================" | tee -a "$FULL_LOG"
|
| 94 |
+
echo "Installing: $pkg" | tee -a "$FULL_LOG"
|
| 95 |
+
echo "------------------------------------" | tee -a "$FULL_LOG"
|
| 96 |
+
|
| 97 |
+
if pip_install_one "$pkg" 2>&1 | tee -a "$FULL_LOG"; then
|
| 98 |
+
echo "✅ OK: $pkg" | tee -a "$SUCCESS_LOG"
|
| 99 |
+
else
|
| 100 |
+
echo "❌ FAIL: $pkg" | tee -a "$FAIL_LOG"
|
| 101 |
+
fi
|
| 102 |
+
|
| 103 |
+
echo "" | tee -a "$FULL_LOG"
|
| 104 |
+
done < "$REQ_FILE"
|
| 105 |
+
|
| 106 |
+
# ==== OPTIONAL: EXTRA WHEELS FOR SPECIFIC ENVS ====
|
| 107 |
+
# NOTE:
|
| 108 |
+
# The DGL wheels-test index below is tied to a specific PyTorch+CUDA combo.
|
| 109 |
+
# To avoid breaking the env, we gate it behind an explicit flag and a torch version check.
|
| 110 |
+
if [[ "$ENV_NAME" == "test_981" ]]; then
|
| 111 |
+
if [[ "${INSTALL_DGL_WHEELS_TEST:-0}" == "1" ]]; then
|
| 112 |
+
TORCH_VER="$(python -c 'import torch; print(torch.__version__)' 2>/dev/null || true)"
|
| 113 |
+
echo "====================================" | tee -a "$FULL_LOG"
|
| 114 |
+
echo "Optional install (test_981): DGL pre-release wheels-test" | tee -a "$FULL_LOG"
|
| 115 |
+
echo "torch version: ${TORCH_VER:-<unknown>}" | tee -a "$FULL_LOG"
|
| 116 |
+
echo "------------------------------------" | tee -a "$FULL_LOG"
|
| 117 |
+
if [[ "$TORCH_VER" == 2.4.* ]]; then
|
| 118 |
+
python -m pip install --pre dgl -f https://data.dgl.ai/wheels-test/torch-2.4/cu124/repo.html 2>&1 | tee -a "$FULL_LOG"
|
| 119 |
+
else
|
| 120 |
+
echo "⚠️ Skipping DGL wheels-test install: requires torch 2.4.*, got '${TORCH_VER:-unknown}'." | tee -a "$FULL_LOG"
|
| 121 |
+
echo " If you really want this, align your torch version (e.g. requirements) to 2.4.* first." | tee -a "$FULL_LOG"
|
| 122 |
+
fi
|
| 123 |
+
echo "" | tee -a "$FULL_LOG"
|
| 124 |
+
else
|
| 125 |
+
echo "ℹ️ (test_981) DGL wheels-test step is disabled. To enable: export INSTALL_DGL_WHEELS_TEST=1" | tee -a "$FULL_LOG"
|
| 126 |
+
fi
|
| 127 |
+
fi
|
| 128 |
+
|
| 129 |
+
echo
|
| 130 |
+
echo "🎉 Done."
|
| 131 |
+
echo " Successes: $SUCCESS_LOG"
|
| 132 |
+
echo " Failures : $FAIL_LOG"
|
| 133 |
+
echo " Full log : $FULL_LOG"
|