reneeice's picture
full research archive: code, models, datasets, experiments, logs
152228b verified
Raw History Blame Contribute Delete
1.66 kB
#!/usr/bin/env bash
# Perturb miner GPU setup: creates the `perturb` env, installs deps, runs smoke checks.
# Usage: bash scripts/gpu_setup.sh
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
PYTHON_BIN="${PYTHON_BIN:-python3}"
if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then
echo "python3 not found"; exit 1
fi
echo "== GPU check =="
"$PYTHON_BIN" - <<'EOF'
import torch
print("torch", torch.__version__, "| cuda:", torch.cuda.is_available())
if torch.cuda.is_available():
print("device:", torch.cuda.get_device_name(0), "| vram GB:", round(torch.cuda.get_device_properties(0).total_memory / 1e9, 1))
else:
raise SystemExit("CUDA not available - install the CUDA torch build: pip install torch --index-url https://download.pytorch.org/whl/cu121")
EOF
echo "== Create/verify conda env 'perturb' =="
if command -v conda >/dev/null 2>&1; then
if ! conda env list | grep -qE "^perturb\s"; then
conda create -n perturb python=3.12 -y
fi
eval "$(conda shell.bash hook)"
conda activate perturb
fi
pip install -q -r requirements.txt
pip install -q -e .
echo "== Smoke: victim + real validator import =="
python - <<'EOF'
import torch
from miner_lib.victim import VictimModel
v = VictimModel(device="cuda")
x = torch.rand(3, 160, 240, device="cuda")
pred, margin, _ = v.evaluate(x, 0)
g = v.margin_grad(x, 0)
print("victim OK: pred", pred, "| grad nonzero frac", round(float((g != 0).float().mean()), 3))
from miner_lib.scoring import LocalValidatorScorer
print("validator-scorer import OK")
EOF
echo "== Done. Bench: python scripts/local_eval.py --live-task --attack.time-budget-seconds 30 =="