plmap_2026-11-02: Vast.ai bootstrap script (copy of tools/vastai/setup.sh)
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183#!/usr/bin/env bash# Bootstrap a Vast.ai instance for plmap: the cluster's absolute paths, code, conda envs, the data set from# Hugging Face (eztao/data_transfer, plmap_2026-11-02/), external repos and weights, then checks.## export GITHUB_TOKEN=... # fine-grained PAT, Contents:Read on Enze-Tao/plmap (the repo is private)# export HF_TOKEN=... # the data repo is public; the token avoids rate limits and is used by jobs# export WANDB_API_KEY=... # optional; without it W&B runs stay offline# bash setup.sh # every stage, in order (each one is safe to rerun)# bash setup.sh data checks # only some stages## Stages: preflight paths code conda plmap secrets data external omniroam miniworld checks# Everything lives under $WORKDIR/u7543832, which becomes /home/projects/u7543832 (701 paths in the code are# absolute; data/Holo360D_aligned_views symlinks with absolute targets). Not covered: outputs/code_snapshots# (copy it from the cluster, see the end) and Slurm (run the run_*.sh files with bash; #SBATCH lines are comments).set -euo pipefail
WORKDIR=${WORKDIR:-/workspace}U=$WORKDIR/u7543832LINK=/home/projects/u7543832REPO_URL=https://github.com/Enze-Tao/plmap.gitREF=${REF:-main} # branch to check out (REF=worktree-vastai-setup before that PR is merged)JOBS=${JOBS:-4} # parallel tar downloads in the data stageSUDO=""; [ "$(id -u)" -eq 0 ] || SUDO=sudoLOG=$WORKDIR/plmap_setup.logmkdir -p "$WORKDIR"exec > >(tee -a "$LOG") 2>&1
say() { printf '\n=== %s %s\n' "$(date +%T)" "$*"; }conda_on() { source "$U/anaconda3/etc/profile.d/conda.sh"; conda activate "$1"; }
stage_preflight() { say "preflight" nvidia-smi --query-gpu=name,memory.total,driver_version --format=csv,noheader local cuda; cuda=$(nvidia-smi | sed -n 's/.*CUDA Version: \([0-9.]*\).*/\1/p' | head -1) echo "driver supports CUDA $cuda" awk -v c="$cuda" 'BEGIN { split(c, v, "."); exit !(v[1] > 12 || (v[1] == 12 && v[2] >= 8)) }' \ || { echo "ERROR: torch 2.9.1+cu128 needs a driver with CUDA >= 12.8 (pick another host)"; exit 1; } local free; free=$(df -BG --output=avail "$WORKDIR" | tail -1 | tr -dc 0-9) echo "disk free on $WORKDIR: ${free} GB (data 130 GB + envs/weights ~60 GB + new outputs)" [ "$free" -ge 300 ] || echo "WARNING: < 300 GB free; Vast disks cannot be resized later" echo "CPUs $(nproc), RAM $(free -g | awk '/Mem:/ {print $2}') GB"}
stage_paths() { say "paths: $LINK -> $U" mkdir -p "$U/hf_cache" "$U/plmap_out/venvs" "$U/pylibs" $SUDO mkdir -p /home/projects if [ -e "$LINK" ] && [ "$(readlink -f "$LINK")" != "$(readlink -f "$U")" ]; then echo "ERROR: $LINK exists and is not a link to $U"; exit 1 fi $SUDO ln -sfn "$U" "$LINK" $SUDO apt-get update -qq DEBIAN_FRONTEND=noninteractive $SUDO apt-get install -y -qq git git-lfs tmux rsync pv htop jq unzip wget \ build-essential ffmpeg libgl1 libglib2.0-0 libegl1 libglu1-mesa >/dev/null echo "ok"}
stage_code() { say "code" local auth=() if [ -n "${GITHUB_TOKEN:-}" ]; then # header only for this command: the token is not written to .git/config auth=(-c "http.https://github.com/.extraheader=AUTHORIZATION: basic $(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 -w0)") fi if [ ! -d "$U/plmap/.git" ]; then git "${auth[@]}" clone "$REPO_URL" "$U/plmap" else git -C "$U/plmap" "${auth[@]}" fetch origin fi git config --global --add safe.directory "$U/plmap" git -C "$U/plmap" checkout -q "$REF" && git -C "$U/plmap" merge -q --ff-only "origin/$REF" git -C "$U/plmap" log --oneline -1}
stage_conda() { say "conda (Miniforge) at $U/anaconda3 -- the run scripts source $LINK/anaconda3/etc/profile.d/conda.sh" if [ ! -x "$U/anaconda3/bin/conda" ]; then wget -q -O /tmp/miniforge.sh https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh bash /tmp/miniforge.sh -b -p "$U/anaconda3" rm -f /tmp/miniforge.sh fi "$U/anaconda3/bin/conda" --version}
stage_plmap() { say "plmap env (python 3.11, requirements.txt: torch 2.9.1 + CUDA 12.8 wheels, wandb 0.30.0)" source "$U/anaconda3/etc/profile.d/conda.sh" conda env list | grep -q '^plmap ' || conda create -y -q -n plmap python=3.11 conda activate plmap pip install -q --upgrade pip pip install -q -r "$U/plmap/requirements.txt" python -c "import torch, wandb, transformers, huggingface_hub as h; print('torch', torch.__version__, 'cuda', torch.version.cuda, '| wandb', wandb.__version__, '| transformers', transformers.__version__, '| hf', h.__version__)"}
stage_secrets() { say "secrets (HF token into $LINK/hf_cache/token, mode 600; W&B login if WANDB_API_KEY is set)" if [ -n "${HF_TOKEN:-}" ]; then umask 077; printf '%s' "$HF_TOKEN" > "$U/hf_cache/token"; umask 022 else echo "HF_TOKEN not set: public downloads still work, gated models will not" fi if [ -n "${WANDB_API_KEY:-}" ]; then conda_on plmap && wandb login --relogin "$WANDB_API_KEY" >/dev/null && echo "wandb: logged in" else echo "WANDB_API_KEY not set: W&B runs will stay offline (wandb sync later)" fi}
stage_data() { say "data: plmap_2026-11-02 from eztao/data_transfer ($JOBS tars in flight, sha256-checked, resumable)" conda_on plmap export HF_HOME=$U/hf_cache python "$U/plmap/tools/vastai/restore_hf_data.py" "$LINK/plmap" "$WORKDIR/hf_transfer" --jobs "$JOBS" du -sh "$U/plmap/data/Holo360D_aligned" "$U/plmap/data/Holo360D_aligned_views" 2>/dev/null || true}
stage_external() { say "external repos at the pinned commits" bash "$U/plmap/tools/fetch_external.sh"}
stage_omniroam() { say "OmniRoam venv (the exact freeze of the cluster venv) + Wan2.1-T2V-1.3B / OmniRoam preview weights" local venv=$U/plmap_out/venvs/omniroam freeze=$U/plmap/outputs/omniroam_s1_20261031/requirements.freeze.txt [ -f "$freeze" ] || { echo "ERROR: $freeze missing -- run the data stage first"; exit 1; } [ -x "$venv/bin/python" ] || "$U/anaconda3/envs/plmap/bin/python" -m venv "$venv" "$venv/bin/pip" install -q --upgrade pip wheel "$venv/bin/pip" install -q -r "$freeze" cd "$U/plmap/external/OmniRoam" HF_HOME=$U/hf_cache "$venv/bin/python" - <<'EOF'from huggingface_hub import snapshot_downloadsnapshot_download("Wan-AI/Wan2.1-T2V-1.3B", local_dir="models/Wan-AI/Wan2.1-T2V-1.3B", allow_patterns=["diffusion_pytorch_model.safetensors", "models_t5_umt5-xxl-enc-bf16.pth", "Wan2.1_VAE.pth", "*.json", "google/*"])snapshot_download("Yuheng02/OmniRoam", local_dir="models/OmniRoam", allow_patterns=["Preview/*", "*.md", "*.json"])EOF local want; want=$(awk '{print $1}' "$U/plmap/outputs/omniroam_s0_20261030/preview_ckpt.sha256" 2>/dev/null || true) local got; got=$(sha256sum models/OmniRoam/Preview/preview.ckpt | awk '{print $1}') if [ -n "$want" ] && [ "$want" != "$got" ]; then echo "ERROR: preview.ckpt sha256 differs from the cluster's"; exit 1; fi echo "preview.ckpt sha256 ${got:0:12}... ${want:+matches the cluster}" "$venv/bin/python" -c "import sys; sys.path.insert(0, '.'); import torch, peft; from diffsynth import ModelManager; print('omniroam venv ok: torch', torch.__version__, 'peft', peft.__version__)" cd - >/dev/null}
stage_miniworld() { say "Miniworld 2.1.0 (only needed to render new worlds; the cluster kept it under pylibs/)" conda_on plmap pip install -q --no-deps miniworld==2.1.0 pyglet==1.5.31 gymnasium==1.4.0 cloudpickle farama-notifications PYGLET_HEADLESS=1 python -c "import miniworld; print('miniworld', miniworld.__version__)" \ || echo "WARNING: no GL here; Mesa software EGL works (memory: miniworld-on-cluster), see tools/miniworld_rgb_worker.py"}
stage_checks() { say "checks: GPU + SDPA vs float64, the 19 tests/ scripts, the VAE CPU checks" conda_on plmap cd "$LINK/plmap" python tools/vastai/gpu_check.py local pass=0 fail=0 failed=() for t in tests/test_*.py; do if PYTHONPATH=$PWD timeout 900 python "$t" > "/tmp/$(basename "$t").log" 2>&1; then pass=$((pass + 1)) else fail=$((fail + 1)); failed+=("$t"); fi done echo "tests/: $pass passed, $fail failed ${failed[*]:-}" PYTHONPATH=$PWD timeout 900 python tools/test_vae_continuity.py | tail -1 PYTHONPATH=$PWD timeout 1500 python tools/test_vae_joint_hr.py test/Indoor_016 | tail -1 cd - >/dev/null}
ALL=(preflight paths code conda plmap secrets data external omniroam miniworld checks)STAGES=("$@"); [ ${#STAGES[@]} -gt 0 ] || STAGES=("${ALL[@]}")for s in "${STAGES[@]}"; do declare -F "stage_$s" >/dev/null || { echo "unknown stage '$s' (have: ${ALL[*]})"; exit 2; } "stage_$s"done
say "done (log: $LOG)"cat <<EOFNext: * outputs/code_snapshots/ (106 MB, frozen trainer copies) is not on Hugging Face. From the cluster: rsync -a -e "ssh -p <vast ssh port>" /home/projects/u7543832/plmap/outputs/code_snapshots/ \\ root@<vast ip>:$U/plmap/outputs/code_snapshots/ * No Slurm here: run a job script with bash run_xxx.sh (or tmux new -s run 'bash run_xxx.sh'). * Activate the env: source $LINK/anaconda3/etc/profile.d/conda.sh && conda activate plmapEOFplmap_2026-11-02/vastai_setup.shAdded+183