ThatsNinja's picture
Sync gh-main from TheRock
cd8c7a9 verified
Raw History Blame Contribute Delete
8.66 kB
#!/usr/bin/env bash
# Correctness model β€” remote AMD Instinct GPU droplet setup (ROCm).
#
# NOTE (2026-08-16): DigitalOcean removed the gpu-mi300x1-192gb slug. The
# current AMD gfx942 drop-in is gpu-mi325x1-256gb (tor1, $3.80/hr). This
# script targets gfx942 and works unchanged on MI325X. See
# src/python/do_droplet.py for the droplet orchestrator and pinned image.
#
# This script sets up a fresh droplet to run the correctness-model training
# pipeline end-to-end, including the HIP kernel.
#
# MI300X/MI325X is a strict superset of the local gfx1030 (RX 6900 XT):
# - Official ROCm wheels target CDNA natively (no HSA_OVERRIDE needed)
# - The HIP kernel rebuilds for gfx942 via CMAKE_HIP_ARCHITECTURES
# - 192GB+ HBM vs 16GB GDDR6 β†’ 12x+ more VRAM for larger batches / longer seq
#
# Usage (on the droplet, as a non-root user with sudo):
# GITHUB_TOKEN=... HF_TOKEN=... bash correctness_model/scripts/setup_remote.sh
#
# Environment variables:
# GITHUB_TOKEN PAT with read access to the private fork (JonahSul/TheRock)
# (not needed if --from-hf is used)
# HF_TOKEN Hugging Face token for model download + results upload
# REPO_URL Override the git remote (default: JonahSul/TheRock)
# WORKDIR Override the working directory (default: $HOME/TheRock)
# GPU_TARGET Override the HIP arch (default: gfx942 for MI300X)
# FROM_HF Set to 1 to pull code from HF instead of cloning GitHub.
# Requires HF_TOKEN but not GITHUB_TOKEN.
set -euo pipefail
# --- Configuration -----------------------------------------------------------
REPO_URL="${REPO_URL:-https://github.com/JonahSul/TheRock.git}"
WORKDIR="${WORKDIR:-$HOME/TheRock}"
GPU_TARGET="${GPU_TARGET:-gfx942}" # MI300X; use gfx1030 for local 6900 XT
PY="${WORKDIR}/.venv/bin/python"
MODEL_DIR="${WORKDIR}/correctness_model/models/glm-edge-1.5b-chat"
FROM_HF="${FROM_HF:-0}"
echo "=== Correctness Model β€” Remote AMD Instinct Setup ==="
echo " Repo: $REPO_URL"
echo " Workdir: $WORKDIR"
echo " GPU arch: $GPU_TARGET (MI300X = gfx942)"
echo " Model: $MODEL_DIR"
echo " Source: ${FROM_HF:+HuggingFace}${FROM_HF:-GitHub}"
echo
# --- 1. System dependencies + ROCm ------------------------------------------
echo "[1/6] Checking ROCm and installing system dependencies..."
# ROCm is preinstalled on DO AMD GPU droplets. Verify.
if ! command -v rocminfo >/dev/null 2>&1; then
echo "ERROR: rocminfo not found. This script expects an AMD Instinct droplet"
echo " with ROCm preinstalled (DigitalOcean AMD GPU droplets ship it)."
exit 1
fi
GPU_NAME="$(rocminfo | grep 'Marketing Name' | head -1 | sed 's/.*: //')"
echo " GPU: ${GPU_NAME:-unknown}"
sudo apt-get update -qq
sudo apt-get install -y -qq \
git python3 python3-venv python3-pip build-essential curl \
cmake ninja-build
# --- 2. Get the source code ------------------------------------------------
echo "[2/6] Getting source code..."
if [[ "$FROM_HF" == "1" ]]; then
# Pull from HuggingFace β€” no GitHub access needed.
if [[ -z "${HF_TOKEN:-}" ]]; then
echo "ERROR: FROM_HF=1 but HF_TOKEN not set."
exit 1
fi
export HF_TOKEN
mkdir -p "$WORKDIR/correctness_model"
# We need huggingface_hub to pull β€” create a minimal venv first, then pull.
python3 -m venv "$WORKDIR/.venv"
# shellcheck disable=SC1091
source "$WORKDIR/.venv/bin/activate"
pip install --upgrade pip wheel
pip install "huggingface_hub[hf_transfer]>=0.25.0"
${PY} "$WORKDIR/correctness_model/src/python/pull_from_hf.py" \
--dest "$WORKDIR/correctness_model" 2>/dev/null || {
# First run: pull_from_hf.py itself isn't local yet. Pull it first.
echo " Bootstrapping: pulling source via huggingface_hub directly..."
${PY} - <<'HFPULL'
import os
from huggingface_hub import snapshot_download
snapshot_download(
'ThatsNinja/correctness-model-results',
repo_type='dataset',
local_dir=os.environ['WORKDIR'],
allow_patterns=['correctness_model/**'],
)
print('Pulled from HF dataset repo.')
HFPULL
}
else
# Clone the git repo β€” requires GITHUB_TOKEN for private fork.
if [[ -d "$WORKDIR/.git" ]]; then
echo " $WORKDIR exists β€” pulling latest."
cd "$WORKDIR"
git pull --ff-only origin main
else
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
REPO_URL="${REPO_URL/https:\/\//https:\/\/${GITHUB_TOKEN}@}"
fi
git clone --depth 1 "$REPO_URL" "$WORKDIR"
cd "$WORKDIR"
git remote add upstream https://github.com/rocm/therock 2>/dev/null || true
fi
fi
# --- 3. Python environment (ROCm PyTorch) -----------------------------------
echo "[3/6] Creating venv and installing ROCm PyTorch..."
if [[ ! -d "$WORKDIR/.venv" ]]; then
python3 -m venv "$WORKDIR/.venv"
fi
# shellcheck disable=SC1091
source "$WORKDIR/.venv/bin/activate"
pip install --upgrade pip wheel
# PyTorch ROCm β€” use the STABLE rocm6.4 wheels, not the nightly multi-arch
# index. Verified 2026-08-04 on MI300X: the nightly
# (rocm.nightlies.amd.com/whl-multi-arch) installs torch 2.13.0+rocm7.15
# which reports gfx942 in get_arch_list() but fails EVERY GPU op at runtime
# with hipErrorInvalidImage. The stable rocm6.4 wheel (torch 2.9.1) works.
# All three packages must come from the same index β€” mixing nightly
# torchvision with stable torch breaks with "operator torchvision::nms does
# not exist". (gfx1030 / RX 6900 XT uses the [device-gfx1030] extra instead
# β€” see RFC0009.)
pip install torch torchvision torchaudio \
--index-url https://download.pytorch.org/whl/rocm6.4
pip install -r "$WORKDIR/correctness_model/requirements-rocm.txt"
# GPU sanity check β€” must run an ACTUAL GPU op, not just is_available().
# is_available() and get_arch_list() both pass with the broken nightly wheel;
# only a real kernel launch exposes hipErrorInvalidImage.
${PY} - <<'PYCHECK'
import torch
assert torch.cuda.is_available(), "PyTorch cannot see the GPU"
a = torch.randn(64, 64, device="cuda")
b = torch.randn(64, 64, device="cuda")
c = a @ b # real kernel launch β€” catches hipErrorInvalidImage
assert c.shape == (64, 64), "GPU matmul failed"
print(f" PyTorch: {torch.__version__}")
print(f" Device: {torch.cuda.get_device_name(0)}")
print(f" VRAM: {torch.cuda.get_device_properties(0).total_memory / 1e9:.1f} GB")
print(" GPU matmul: OK")
PYCHECK
# --- 4. Download the base model ---------------------------------------------
echo "[4/6] Downloading GLM-Edge 1.5B Chat..."
mkdir -p "$MODEL_DIR"
if [[ -n "${HF_TOKEN:-}" ]]; then
export HF_TOKEN
${PY} -c "
from huggingface_hub import snapshot_download
snapshot_download('zai-org/glm-edge-1.5b-chat', local_dir='$MODEL_DIR')
print('Downloaded GLM-Edge to $MODEL_DIR')
"
else
echo " WARNING: HF_TOKEN not set β€” model download may fail for gated weights."
echo " Set HF_TOKEN and re-run, or download manually:"
echo " huggingface-cli download zai-org/glm-edge-1.5b-chat --local-dir $MODEL_DIR"
fi
# --- 5. Build the HIP kernel for the droplet's GPU arch ---------------------
echo "[5/6] Building block-sparse SDPA kernel for $GPU_TARGET..."
cd "$WORKDIR/correctness_model"
cmake -B build -GNinja \
-DCMAKE_HIP_ARCHITECTURES="$GPU_TARGET" \
-DCMAKE_BUILD_TYPE=Release
ninja -C build block_sparse_sdpa
echo " Kernel built at build/block_sparse_sdpa"
# --- 6. Ready ---------------------------------------------------------------
echo "[6/6] Setup complete."
echo
echo "=== Next: run the training pipeline ==="
echo
echo " source $WORKDIR/.venv/bin/activate"
echo
echo " # Track 1: MLA projection training (RFC0005 Phase 1 β†’ quality)"
echo " python correctness_model/src/python/train_mla_projections.py \\"
echo " --rank 64 --epochs 5 --num-sequences 200 --seq-len 256"
echo
echo " # Track 2: verifier data scaling (Phase A3) β€” 192GB VRAM enables"
echo " # much larger batches than the 16GB local box."
echo " python correctness_model/src/python/collect_gsm8k_features.py \\"
echo " --num-problems 1000 --split train \\"
echo " --output correctness_model/data/gsm8k_features"
echo
echo " python correctness_model/src/python/run_training.py \\"
echo " --config correctness_model/configs/verifier-v1.yaml"
echo
echo " # Export results to Hugging Face Hub"
echo " python correctness_model/src/python/export_results.py \\"
echo " --repo JonahSul/correctness-model-results \\"
echo " --tag mla-r64-mi300x-$(date +%Y%m%d)"
echo
echo "=== Hardware note ==="
echo " MI300X (gfx942, 192GB HBM) is a strict superset of the local"
echo " gfx1030 (RX 6900 XT, 16GB GDDR6). The HIP kernel and all Python"
echo " scripts run unmodified β€” only the HIP_ARCHITECTURES target changed."