File size: 3,378 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
#!/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