Download code/scripts/gpu_setup.sh from reneeice/sparse-adversarial-research-archive: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/datasets/reneeice/sparse-adversarial-research-archive/resolve/main/code/scripts/gpu_setup.sh
- Command line
-
hf download hf://datasets/reneeice/sparse-adversarial-research-archive/code/scripts/gpu_setup.sh
-
curl -L -o gpu_setup.sh https://huggingface.co/datasets/reneeice/sparse-adversarial-research-archive/resolve/main/code/scripts/gpu_setup.sh
1.66 kB
| # 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 ==" | |