#!/usr/bin/env bash # One-click installer for the ImplicitReasoning training environment (uv version). # # Recreates the exact `implicitreasoning` environment used to run # `train_twin_hyper_real_multi_sweep.sh` (and the other train_twin_*.sh scripts), # but with a uv-managed virtualenv instead of conda. # # Usage: # ./install_uv.sh # create/update .venv, then verify # ./install_uv.sh --venv myenv # use a different venv directory # ./install_uv.sh --cpu # install the CPU-only torch build # # After it finishes: # source .venv-implicitreasoning/bin/activate # ./train_twin_hyper_real_multi_sweep.sh --gpus 0,1 set -euo pipefail VENV_DIR=".venv-implicitreasoning" PYTHON_VERSION="3.10" TORCH_VERSION="2.9.1" CUDA_CHANNEL="cu128" # matches torch 2.9.1+cu128 (CUDA 12.8) CPU_ONLY=0 while [[ $# -gt 0 ]]; do case "$1" in --venv) VENV_DIR="$2"; shift 2 ;; --cuda) CUDA_CHANNEL="$2"; shift 2 ;; --cpu) CPU_ONLY=1; shift 1 ;; -h|--help) grep '^#' "$0" | sed 's/^# \{0,1\}//' exit 0 ;; *) echo "Unknown argument: $1" >&2; exit 1 ;; esac done SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # --- Locate uv -------------------------------------------------------------- if ! command -v uv >/dev/null 2>&1; then echo "ERROR: uv not found on PATH." >&2 echo "Install it with: curl -LsSf https://astral.sh/uv/install.sh | sh" >&2 exit 1 fi # --- Create venv ------------------------------------------------------------ # uv fetches the requested Python itself if it isn't already available. if [[ -d "$VENV_DIR" ]]; then echo ">> venv '$VENV_DIR' already exists; reusing it." else echo ">> Creating uv venv '$VENV_DIR' (python $PYTHON_VERSION)..." uv venv --python "$PYTHON_VERSION" "$VENV_DIR" fi # Point uv's pip commands at this venv. export VIRTUAL_ENV="$SCRIPT_DIR/$VENV_DIR" # shellcheck disable=SC1091 source "$VENV_DIR/bin/activate" # --- Install PyTorch -------------------------------------------------------- if [[ "$CPU_ONLY" -eq 1 ]]; then echo ">> Installing CPU-only torch $TORCH_VERSION ..." uv pip install "torch==$TORCH_VERSION" \ --index-url https://download.pytorch.org/whl/cpu else echo ">> Installing torch $TORCH_VERSION ($CUDA_CHANNEL) ..." uv pip install "torch==$TORCH_VERSION" \ --index-url "https://download.pytorch.org/whl/$CUDA_CHANNEL" fi # --- Install the rest ------------------------------------------------------- echo ">> Installing pinned Python dependencies ..." uv pip install -r "$SCRIPT_DIR/requirements.txt" # --- Verify ----------------------------------------------------------------- echo ">> Verifying installation ..." python - <<'PY' import torch, transformers, numpy print("python :", __import__("sys").version.split()[0]) print("torch :", torch.__version__) print("cuda build :", torch.version.cuda) print("cuda avail :", torch.cuda.is_available(), f"({torch.cuda.device_count()} GPUs)" if torch.cuda.is_available() else "") print("transformers:", transformers.__version__) print("numpy :", numpy.__version__) PY cat <