setup.sh: one-shot bootstrap (workspace sync + hf_transfer fast downloads)
Browse files
setup.sh
CHANGED
|
@@ -35,14 +35,19 @@ PYTHON_BIN="${VSI_PYTHON_BIN:-python3.11}"
|
|
| 35 |
|
| 36 |
SKIP_MODELS=0
|
| 37 |
SKIP_DATA=0
|
|
|
|
|
|
|
| 38 |
FORCE=0
|
| 39 |
ASSUME_YES=0
|
| 40 |
HF_TOKEN="${HF_TOKEN:-}"
|
|
|
|
| 41 |
|
| 42 |
for arg in "$@"; do
|
| 43 |
case "$arg" in
|
| 44 |
--skip-models) SKIP_MODELS=1 ;;
|
| 45 |
--skip-data) SKIP_DATA=1 ;;
|
|
|
|
|
|
|
| 46 |
--force) FORCE=1 ;;
|
| 47 |
-y|--yes) ASSUME_YES=1 ;;
|
| 48 |
--token=*) HF_TOKEN="${arg#--token=}" ;;
|
|
@@ -271,6 +276,15 @@ fi
|
|
| 271 |
# `hf`; prefer `hf` wherever it exists and only fall back to the legacy name on
|
| 272 |
# old installs. A silent legacy-CLI failure here previously left VSI-Bench and
|
| 273 |
# every checkpoint undownloaded while the rest of setup continued.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
HF_CLI=""
|
| 275 |
for candidate in "$VENV_ROOT/bin/hf" "${PERCEPTION_VENV_ROOT}/bin/hf" \
|
| 276 |
"$VENV_ROOT/bin/huggingface-cli" "${PERCEPTION_VENV_ROOT}/bin/huggingface-cli"; do
|
|
@@ -301,6 +315,58 @@ hf_download() {
|
|
| 301 |
fi
|
| 302 |
}
|
| 303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
if [ "$SKIP_DATA" -eq 0 ]; then
|
| 305 |
hf_download "nyu-visionx/VSI-Bench" dataset "$DATA_ROOT/VSI-Bench"
|
| 306 |
|
|
|
|
| 35 |
|
| 36 |
SKIP_MODELS=0
|
| 37 |
SKIP_DATA=0
|
| 38 |
+
SKIP_WORKSPACE=0
|
| 39 |
+
WITH_CACHES=0
|
| 40 |
FORCE=0
|
| 41 |
ASSUME_YES=0
|
| 42 |
HF_TOKEN="${HF_TOKEN:-}"
|
| 43 |
+
WORKSPACE_REPO="${VSI_WORKSPACE_REPO:-AntonioJun/workspace}"
|
| 44 |
|
| 45 |
for arg in "$@"; do
|
| 46 |
case "$arg" in
|
| 47 |
--skip-models) SKIP_MODELS=1 ;;
|
| 48 |
--skip-data) SKIP_DATA=1 ;;
|
| 49 |
+
--skip-workspace) SKIP_WORKSPACE=1 ;;
|
| 50 |
+
--with-caches) WITH_CACHES=1 ;;
|
| 51 |
--force) FORCE=1 ;;
|
| 52 |
-y|--yes) ASSUME_YES=1 ;;
|
| 53 |
--token=*) HF_TOKEN="${arg#--token=}" ;;
|
|
|
|
| 276 |
# `hf`; prefer `hf` wherever it exists and only fall back to the legacy name on
|
| 277 |
# old installs. A silent legacy-CLI failure here previously left VSI-Bench and
|
| 278 |
# every checkpoint undownloaded while the rest of setup continued.
|
| 279 |
+
# Fast multi-threaded downloads: hf_transfer accelerates every hf download below
|
| 280 |
+
# (models and datasets alike) by an order of magnitude on fat pipes.
|
| 281 |
+
PIP_BIN="$VENV_ROOT/bin/pip"
|
| 282 |
+
[ -x "$PIP_BIN" ] || PIP_BIN="${VLM_VENV_ROOT}/bin/pip"
|
| 283 |
+
if [ -x "$PIP_BIN" ]; then
|
| 284 |
+
"$PIP_BIN" install -q hf_transfer huggingface_hub >/dev/null 2>&1 || warn "hf_transfer install failed; downloads will be slower"
|
| 285 |
+
fi
|
| 286 |
+
export HF_HUB_ENABLE_HF_TRANSFER=1
|
| 287 |
+
|
| 288 |
HF_CLI=""
|
| 289 |
for candidate in "$VENV_ROOT/bin/hf" "${PERCEPTION_VENV_ROOT}/bin/hf" \
|
| 290 |
"$VENV_ROOT/bin/huggingface-cli" "${PERCEPTION_VENV_ROOT}/bin/huggingface-cli"; do
|
|
|
|
| 315 |
fi
|
| 316 |
}
|
| 317 |
|
| 318 |
+
# ---------------------------------------------------------------------------
|
| 319 |
+
# 6a. Workspace sync -- pull this project's own code + spatial codes from the
|
| 320 |
+
# backup repo ($WORKSPACE_REPO), so a fresh pod needs ONLY this script to
|
| 321 |
+
# bootstrap. Uses per-folder tree listing (never enumerates the whole repo,
|
| 322 |
+
# which is huge) and skips files already present. --skip-workspace disables;
|
| 323 |
+
# --with-caches additionally pulls the SAM3/DA3 raw caches (large; only
|
| 324 |
+
# needed to run inference/encoder, not the VLM harnesses).
|
| 325 |
+
# ---------------------------------------------------------------------------
|
| 326 |
+
if [ "$SKIP_WORKSPACE" -eq 0 ]; then
|
| 327 |
+
log "Syncing workspace code + data from $WORKSPACE_REPO"
|
| 328 |
+
PY_SYNC="$VENV_ROOT/bin/python"
|
| 329 |
+
[ -x "$PY_SYNC" ] || PY_SYNC="${VLM_VENV_ROOT}/bin/python"
|
| 330 |
+
WITH_CACHES="$WITH_CACHES" WORKSPACE_REPO="$WORKSPACE_REPO" \
|
| 331 |
+
WORKSPACE_ROOT="$WORKSPACE_ROOT" "$PY_SYNC" - <<'PYSYNC' || die "workspace sync failed"
|
| 332 |
+
import os
|
| 333 |
+
from pathlib import Path
|
| 334 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 335 |
+
|
| 336 |
+
repo = os.environ["WORKSPACE_REPO"]
|
| 337 |
+
root = Path(os.environ["WORKSPACE_ROOT"])
|
| 338 |
+
token = os.environ.get("HF_TOKEN") or None
|
| 339 |
+
api = HfApi(token=token)
|
| 340 |
+
folders = [
|
| 341 |
+
"harness", "symbolic", "analysis", "corruption", "calibration",
|
| 342 |
+
"encoder", "inference", "tests", "data/spatial codes",
|
| 343 |
+
]
|
| 344 |
+
if os.environ.get("WITH_CACHES") == "1":
|
| 345 |
+
folders.append("data/caches")
|
| 346 |
+
top_files = ["README.md", "backup.py", "setup.sh"]
|
| 347 |
+
|
| 348 |
+
def fetch(rel):
|
| 349 |
+
dest = root / rel
|
| 350 |
+
if dest.is_file() and dest.stat().st_size > 0:
|
| 351 |
+
return 0
|
| 352 |
+
hf_hub_download(repo, rel, repo_type="dataset", local_dir=str(root), token=token)
|
| 353 |
+
return 1
|
| 354 |
+
|
| 355 |
+
for folder in folders:
|
| 356 |
+
files = [
|
| 357 |
+
e.path for e in api.list_repo_tree(repo, repo_type="dataset",
|
| 358 |
+
path_in_repo=folder, recursive=True)
|
| 359 |
+
if e.__class__.__name__ == "RepoFile"
|
| 360 |
+
]
|
| 361 |
+
got = sum(fetch(rel) for rel in files)
|
| 362 |
+
print(f"[{folder}] {len(files)} files ({got} downloaded, rest already present)", flush=True)
|
| 363 |
+
for rel in top_files:
|
| 364 |
+
fetch(rel)
|
| 365 |
+
print("workspace sync complete", flush=True)
|
| 366 |
+
PYSYNC
|
| 367 |
+
chmod +x "$WORKSPACE_ROOT/setup.sh" "$WORKSPACE_ROOT/backup.py" 2>/dev/null || true
|
| 368 |
+
fi
|
| 369 |
+
|
| 370 |
if [ "$SKIP_DATA" -eq 0 ]; then
|
| 371 |
hf_download "nyu-visionx/VSI-Bench" dataset "$DATA_ROOT/VSI-Bench"
|
| 372 |
|