fhyfhy's picture
Add code/
74b7543 verified
Raw History Blame Contribute Delete
3.38 kB
#!/usr/bin/env bash
# One-click installer for the ImplicitReasoning training environment.
#
# Recreates the exact `implicitreasoning` conda env used to run
# `train_twin_hyper_real_multi_sweep.sh` (and the other train_twin_*.sh scripts).
#
# Usage:
# ./install.sh # create/update env, then verify
# ./install.sh --name myenv # use a different env name
# ./install.sh --cpu # install the CPU-only torch build
#
# After it finishes:
# conda activate implicitreasoning
# ./train_twin_hyper_real_multi_sweep.sh --gpus 0,1
set -euo pipefail
ENV_NAME="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
--name) ENV_NAME="$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 conda -----------------------------------------------------------
if ! command -v conda >/dev/null 2>&1; then
echo "ERROR: conda not found on PATH. Install Miniconda/Anaconda first." >&2
exit 1
fi
CONDA_BASE="$(conda info --base)"
# shellcheck disable=SC1091
source "$CONDA_BASE/etc/profile.d/conda.sh"
# --- Create env -------------------------------------------------------------
if conda env list | awk '{print $1}' | grep -qx "$ENV_NAME"; then
echo ">> Conda env '$ENV_NAME' already exists; reusing it."
else
echo ">> Creating conda env '$ENV_NAME' (python $PYTHON_VERSION)..."
conda create -y -n "$ENV_NAME" "python=$PYTHON_VERSION"
fi
conda activate "$ENV_NAME"
python -m pip install --upgrade pip
# --- Install PyTorch --------------------------------------------------------
if [[ "$CPU_ONLY" -eq 1 ]]; then
echo ">> Installing CPU-only torch $TORCH_VERSION ..."
python -m pip install "torch==$TORCH_VERSION" \
--index-url https://download.pytorch.org/whl/cpu
else
echo ">> Installing torch $TORCH_VERSION ($CUDA_CHANNEL) ..."
python -m pip install "torch==$TORCH_VERSION" \
--index-url "https://download.pytorch.org/whl/$CUDA_CHANNEL"
fi
# --- Install the rest -------------------------------------------------------
echo ">> Installing pinned Python dependencies ..."
python -m 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 <<EOF
Done. Environment '$ENV_NAME' is ready.
Next:
conda activate $ENV_NAME
./train_twin_hyper_real_multi_sweep.sh --gpus 0,1 # run the sweep
./train_twin_hyper_real_multi_sweep.sh --gpus 0,1 --dry-run # preview only
If you use Weights & Biases logging, run 'wandb login' once first
(or set WANDB_MODE=offline to disable it).
EOF