File size: 2,525 Bytes
d7ecc62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
# One-time setup on a fresh Runpod (or similar) GPU VM.
# Run from the project root: cd /workspace/pawn && bash deploy/setup.sh
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
echo "=== PAWN Setup ==="
echo "Root: $ROOT"

# --- System packages ---
NEED_INSTALL=()
for pkg in rsync zstd; do
    command -v "$pkg" &>/dev/null || NEED_INSTALL+=("$pkg")
done
if [ ${#NEED_INSTALL[@]} -gt 0 ]; then
    apt-get update -qq && apt-get install -y -qq "${NEED_INSTALL[@]}"
fi

# --- Rust (needed for chess engine) ---
if ! command -v cargo &>/dev/null; then
    echo ""
    echo "--- Installing Rust ---"
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
fi
source "$HOME/.cargo/env" 2>/dev/null || true

# --- uv ---
echo ""
echo "--- Installing/upgrading uv ---"
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"

# --- Build chess engine ---
echo ""
echo "--- Building chess engine ---"
cd "$ROOT/engine"
uv run --with maturin maturin develop --release
cd "$ROOT"

# --- Sync workspace with CUDA torch ---
echo ""
echo "--- Syncing workspace (cu128) ---"
uv sync --extra cu128 --no-dev

# --- Verify ---
echo ""
echo "--- Verifying CUDA ---"
uv run python -c "
import torch
print(f'PyTorch: {torch.__version__}')
print(f'CUDA available: {torch.cuda.is_available()}')
if torch.cuda.is_available():
    print(f'GPU: {torch.cuda.get_device_name(0)}')
    print(f'VRAM: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.1f} GB')
"

echo ""
echo "--- Verifying chess engine ---"
uv run python -c "import chess_engine; print(f'chess_engine OK: {len(chess_engine.export_move_vocabulary()[\"token_to_move\"])} tokens')"

# --- Decompress data if needed ---
if ls "$ROOT/data"/*.zst &>/dev/null; then
    echo ""
    echo "--- Decompressing training data ---"
    cd "$ROOT/data"
    for zst in *.zst; do
        [ -f "$zst" ] || continue
        pgn="${zst%.zst}"
        if [ -f "$pgn" ]; then
            echo "  $pgn already exists, skipping"
        else
            echo "  Decompressing $zst..."
            zstd -d "$zst" -o "$pgn"
        fi
    done
    cd "$ROOT"
fi

echo ""
echo "=== Setup complete ==="
echo ""
echo "To pretrain:"
echo "  uv run python scripts/train.py --variant base"
echo ""
echo "To train an adapter:"
echo "  uv run python scripts/train_bottleneck.py \\"
echo "      --checkpoint checkpoints/pawn-base.pt \\"
echo "      --pgn data/lichess_1800_1900.pgn \\"
echo "      --bottleneck-dim 32 --lr 1e-4"