code-202604_v2 / hf_upload /setup_env.sh
Rakancorle11's picture
Snapshot 20260424-2142
0a4deb9 verified
#!/usr/bin/env bash
# CleverHans-Evaluation — environment only (no data, no eval).
#
# On a machine *without* conda: downloads and installs Anaconda under INSTALL_DIR,
# then creates CONDA_ENV and pip-installs eval dependencies (aligned with ~/set_up_env.sh).
#
# On a machine that already has conda: skips the installer and only creates/updates the env.
#
# Usage:
# bash setup_env.sh
# INSTALL_DIR=/opt/conda CONDA_ENV=cleverhans bash setup_env.sh
# CUDA_INDEX_URL=https://download.pytorch.org/whl/cu124 bash setup_env.sh
#
set -euo pipefail
# ----- Config (override with env vars) -----
CONDA_ENV="${CONDA_ENV:-video}"
PYTHON_VER="${PYTHON_VER:-3.12}"
INSTALL_DIR="${INSTALL_DIR:-${HOME}/anaconda3}"
INSTALLER_PATH="${INSTALLER_PATH:-${HOME}/anaconda3_installer.sh}"
ANACONDA_VERSION="${ANACONDA_VERSION:-Anaconda3-2025.12-2-Linux-x86_64.sh}"
ANACONDA_URL="${ANACONDA_URL:-https://repo.anaconda.com/archive/${ANACONDA_VERSION}}"
CUDA_INDEX_URL="${CUDA_INDEX_URL:-https://download.pytorch.org/whl/cu124}"
# -------------------------------------------
log() { echo "[setup_env] $*"; }
log "Checking architecture..."
ARCH="$(uname -m)"
if [[ "${ARCH}" != "x86_64" ]]; then
echo "Error: this Anaconda installer path supports x86_64 only (found ${ARCH})."
echo "Install conda manually for your arch, then re-run this script."
exit 1
fi
bootstrap_conda() {
if command -v conda &>/dev/null; then
log "conda already on PATH: $(command -v conda)"
return 0
fi
if [[ -x "${INSTALL_DIR}/bin/conda" ]]; then
log "Using existing conda at ${INSTALL_DIR}"
# shellcheck source=/dev/null
source "${INSTALL_DIR}/etc/profile.d/conda.sh"
return 0
fi
log "No conda found. Downloading Anaconda installer..."
if ! command -v wget &>/dev/null; then
echo "Error: wget not found. Install wget (e.g. apt install wget) and retry."
exit 1
fi
wget -O "${INSTALLER_PATH}" "${ANACONDA_URL}"
log "Installing Anaconda to ${INSTALL_DIR} (batch mode)..."
bash "${INSTALLER_PATH}" -b -p "${INSTALL_DIR}"
# shellcheck source=/dev/null
source "${INSTALL_DIR}/etc/profile.d/conda.sh"
log "Initializing conda for bash (future shells)..."
"${INSTALL_DIR}/bin/conda" init bash >/dev/null 2>&1 || true
log "Anaconda installed. You can remove the installer: rm -f ${INSTALLER_PATH}"
}
bootstrap_conda
# Ensure hook is available whether conda came from PATH or fresh install
if ! command -v conda &>/dev/null; then
if [[ -f "${INSTALL_DIR}/etc/profile.d/conda.sh" ]]; then
# shellcheck source=/dev/null
source "${INSTALL_DIR}/etc/profile.d/conda.sh"
else
echo "Error: conda still not available after install."
exit 1
fi
else
eval "$(conda shell.bash hook)"
fi
log "Accepting Anaconda channel Terms of Service (if supported by this conda)..."
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
log "Creating conda environment: ${CONDA_ENV} (python=${PYTHON_VER})..."
if conda env list | awk '{print $1}' | grep -Fxq "${CONDA_ENV}"; then
log "Environment '${CONDA_ENV}' already exists; activating."
conda activate "${CONDA_ENV}"
else
conda create -n "${CONDA_ENV}" "python=${PYTHON_VER}" -y
conda activate "${CONDA_ENV}"
fi
log "Installing Python packages for Video-MME / LVBench / sync eval + vLLM..."
python -m pip install --upgrade pip
# GPU PyTorch (adjust CUDA_INDEX_URL if your driver needs another cu12x build)
pip install torch torchvision torchaudio --index-url "${CUDA_INDEX_URL}"
pip install transformers accelerate peft safetensors
pip install -U "huggingface_hub[cli]"
pip install datasets tqdm openai
pip install qwen-omni-utils
pip install soundfile librosa
pip install google-genai
# Helpful for video decode paths used by torch/qwen stack (optional but recommended)
pip install decord opencv-python-headless
pip install torchcodec || echo "[setup_env] Warning: torchcodec failed; decode may fall back to torchvision."
pip install vllm
log "Done."
echo ""
echo " Active env: ${CONDA_ENV}"
echo " Python: $(command -v python)"
echo " Conda base: ${INSTALL_DIR}"
echo ""
echo "Next: conda activate ${CONDA_ENV}"
echo " Then follow README.md and COMMANDS.md (data download + eval commands)."
echo ""
echo "Tip: install system ffmpeg if missing (Ubuntu: sudo apt install -y ffmpeg)."