File size: 3,504 Bytes
74b7543 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #!/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 <<EOF
Done. Environment '$VENV_DIR' is ready.
Next:
source $VENV_DIR/bin/activate
./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
|