minhluanquach/unet-training-data / scripts /transfer_to_runpod.sh
minhluanquach's picture
download
raw
7.35 kB
#!/bin/bash
# ==============================================================
# Transfer Project to RunPod for SyncNet Training Resume
# ==============================================================
#
# Transfers ONLY what's needed for SyncNet training (~148 GB):
# - data/processed/ (145.5 GB) — lip frames + metadata
# - data/cache/*/mel_spectrogram.npy (1.2 GB) — mel spectrograms only
# - checkpoints/syncnet_best.pt (354 MB) — resume checkpoint
# - Code, configs, scripts (tiny)
#
# SKIPS (~150 GB saved):
# - data/raw/ (15 GB) — original videos, not needed
# - data/cache/*/vae_latents.npy (~25 GB) — UNet only
# - data/cache/*/whisper_features.npy (~1 GB) — UNet only
# - venv/ — recreated on pod
# - .git/ — not needed for training
# - node_modules/ — not needed for training
#
# ==============================================================
# USAGE:
# 1. Start your RunPod pod and note the SSH connection details
# 2. Edit the variables below with your pod's IP and port
# 3. Run from WSL or Git Bash on Windows:
# bash scripts/transfer_to_runpod.sh
#
# Or run individual steps:
# bash scripts/transfer_to_runpod.sh code # Step 1: code only
# bash scripts/transfer_to_runpod.sh checkpoint # Step 2: checkpoint
# bash scripts/transfer_to_runpod.sh mel # Step 3: mel spectrograms
# bash scripts/transfer_to_runpod.sh processed # Step 4: processed data
# bash scripts/transfer_to_runpod.sh verify # Step 5: verify
# ==============================================================
set -e
# ========================
# CONFIGURE THESE VALUES
# ========================
RUNPOD_IP="${RUNPOD_IP:-}" # e.g., 194.68.245.11
RUNPOD_PORT="${RUNPOD_PORT:-}" # e.g., 22167
RUNPOD_DEST="/workspace/Train_Advanced_Lipsync_Model"
# Auto-detect project root (script is in scripts/)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# ========================
# VALIDATION
# ========================
if [ -z "$RUNPOD_IP" ] || [ -z "$RUNPOD_PORT" ]; then
echo "ERROR: Set your RunPod SSH connection details:"
echo ""
echo " export RUNPOD_IP=<your-pod-ip>"
echo " export RUNPOD_PORT=<your-pod-port>"
echo " bash scripts/transfer_to_runpod.sh"
echo ""
echo "Or edit this script directly."
exit 1
fi
SSH_CMD="ssh -p $RUNPOD_PORT -o StrictHostKeyChecking=no"
RSYNC_BASE="rsync -avz --progress -e '$SSH_CMD'"
REMOTE="root@$RUNPOD_IP:$RUNPOD_DEST"
echo "============================================"
echo " Transfer to RunPod"
echo "============================================"
echo " Source: $PROJECT_ROOT"
echo " Target: root@$RUNPOD_IP:$RUNPOD_DEST"
echo " Port: $RUNPOD_PORT"
echo "============================================"
# ========================
# STEP FUNCTIONS
# ========================
transfer_code() {
echo ""
echo "[1/5] Transferring code, configs, and scripts..."
# Create remote directories
eval $SSH_CMD root@$RUNPOD_IP "mkdir -p $RUNPOD_DEST/{checkpoints,data/{processed,cache},logs}"
# Sync code (tiny — a few MB total)
eval $RSYNC_BASE \
--exclude='__pycache__' \
--exclude='*.pyc' \
--exclude='.git' \
--exclude='venv' \
--exclude='node_modules' \
--exclude='data/' \
--exclude='checkpoints/' \
--exclude='logs/' \
--exclude='app/frontend/node_modules' \
--exclude='app/uploads' \
--exclude='app/outputs' \
--exclude='advanced_lipsync.egg-info' \
"$PROJECT_ROOT/" "$REMOTE/"
echo " Done — code synced."
}
transfer_checkpoint() {
echo ""
echo "[2/5] Transferring SyncNet checkpoint (~354 MB)..."
eval $RSYNC_BASE \
"$PROJECT_ROOT/checkpoints/syncnet_best.pt" \
"$REMOTE/checkpoints/"
echo " Done — checkpoint synced."
}
transfer_mel() {
echo ""
echo "[3/5] Transferring mel spectrograms (~1.2 GB)..."
# Only transfer mel_spectrogram.npy from each cache subfolder
# This avoids the heavy vae_latents.npy (~25 GB) and whisper_features.npy
eval $RSYNC_BASE \
--include='*/' \
--include='mel_spectrogram.npy' \
--exclude='*' \
"$PROJECT_ROOT/data/cache/" \
"$REMOTE/data/cache/"
echo " Done — mel spectrograms synced."
}
transfer_processed() {
echo ""
echo "[4/5] Transferring processed data (~145 GB)..."
echo " This is the largest transfer — will take a while."
echo " Tip: Run in tmux/screen so it survives disconnects."
echo ""
eval $RSYNC_BASE \
"$PROJECT_ROOT/data/processed/" \
"$REMOTE/data/processed/"
echo " Done — processed data synced."
}
verify_transfer() {
echo ""
echo "[5/5] Verifying transfer..."
eval $SSH_CMD root@$RUNPOD_IP << 'VERIFY_EOF'
cd /workspace/Train_Advanced_Lipsync_Model
echo "=== Checking files ==="
# Code
if [ -f "pyproject.toml" ]; then
echo " ✓ Code transferred"
else
echo " ✗ Code MISSING"
fi
# Checkpoint
if [ -f "checkpoints/syncnet_best.pt" ]; then
SIZE=$(du -h checkpoints/syncnet_best.pt | cut -f1)
echo " ✓ Checkpoint: syncnet_best.pt ($SIZE)"
python3 -c "
import torch
ckpt = torch.load('checkpoints/syncnet_best.pt', map_location='cpu', weights_only=False)
print(f' Epoch: {ckpt.get(\"epoch\", \"?\")}, Val loss: {ckpt.get(\"val_loss\", \"?\"):.4f}')
" 2>/dev/null || echo " (could not read checkpoint details)"
else
echo " ✗ Checkpoint MISSING"
fi
# Processed data
if [ -d "data/processed" ]; then
NUM=$(find data/processed -maxdepth 1 -type d | wc -l)
echo " ✓ Processed: $((NUM - 1)) video directories"
else
echo " ✗ Processed data MISSING"
fi
# Mel spectrograms
if [ -d "data/cache" ]; then
MEL_COUNT=$(find data/cache -name "mel_spectrogram.npy" | wc -l)
echo " ✓ Mel spectrograms: $MEL_COUNT files"
else
echo " ✗ Cache/mel data MISSING"
fi
echo ""
echo "=== Disk usage ==="
du -sh data/processed/ data/cache/ checkpoints/ 2>/dev/null || true
df -h /workspace
echo ""
echo "=== Ready to train! ==="
echo "Run: bash scripts/runpod_setup.sh"
echo "Then: torchrun --nproc_per_node=\$(python3 -c 'import torch; print(torch.cuda.device_count())') \\"
echo " -m src.training.train_syncnet_distributed \\"
echo " --config configs/syncnet_distributed.yaml \\"
echo " --resume checkpoints/syncnet_best.pt"
VERIFY_EOF
}
# ========================
# MAIN
# ========================
STEP="${1:-all}"
case "$STEP" in
code)
transfer_code
;;
checkpoint)
transfer_checkpoint
;;
mel)
transfer_mel
;;
processed)
transfer_processed
;;
verify)
verify_transfer
;;
all)
transfer_code
transfer_checkpoint
transfer_mel
transfer_processed
verify_transfer
echo ""
echo "============================================"
echo " All transfers complete!"
echo "============================================"
;;
*)
echo "Unknown step: $STEP"
echo "Usage: $0 [code|checkpoint|mel|processed|verify|all]"
exit 1
;;
esac

Xet Storage Details

Size:
7.35 kB
·
Xet hash:
d56c683ec1b0fc96d587b1fe654d34cfbf24d41779b40181ccbf808d6e607e56

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.