minhluanquach's picture
download
raw
3.94 kB
#!/bin/bash
# ==============================================================
# GCP VM Training Launcher
# ==============================================================
# Run training inside tmux with auto-resume capability.
# If training crashes or the spot VM is preempted, just re-run this script.
#
# Usage:
# bash scripts/gcp/launch_training.sh # Fresh start
# bash scripts/gcp/launch_training.sh --resume # Resume from best checkpoint
# bash scripts/gcp/launch_training.sh --resume --checkpoint checkpoints/checkpoint_epoch_50.pt
# ==============================================================
set -e
RESUME=false
DISTRIBUTED=false
CHECKPOINT="checkpoints/best_model.pt"
CONFIG=""
SESSION_NAME="train"
# Parse args
while [[ $# -gt 0 ]]; do
case $1 in
--resume) RESUME=true; shift ;;
--distributed) DISTRIBUTED=true; shift ;;
--checkpoint) CHECKPOINT="$2"; shift 2 ;;
--config) CONFIG="$2"; shift 2 ;;
*) echo "Unknown arg: $1"; exit 1 ;;
esac
done
# Auto-select config if not specified
if [ -z "$CONFIG" ]; then
if [ "$DISTRIBUTED" = true ]; then
CONFIG="configs/train_gcp_distributed.yaml"
else
CONFIG="configs/train_gcp.yaml"
fi
fi
cd ~/Train_Advanced_Lipsync_Model
source venv/bin/activate
NUM_GPUS=$(python3 -c 'import torch; print(torch.cuda.device_count())')
echo "============================================"
echo " GCP Training Launcher"
echo "============================================"
echo " Config: $CONFIG"
echo " Distributed: $DISTRIBUTED ($NUM_GPUS GPUs)"
echo " Resume: $RESUME"
if [ "$RESUME" = true ]; then
echo " Checkpoint: $CHECKPOINT"
fi
echo "============================================"
# Check GPU
python3 -c "
import torch
assert torch.cuda.is_available(), 'No GPU detected!'
props = torch.cuda.get_device_properties(0)
print(f'GPU: {props.name} ({props.total_memory / 1024**3:.1f} GB)')
"
# Update config for resume if requested
if [ "$RESUME" = true ]; then
if [ -f "$CHECKPOINT" ]; then
echo "Will resume from: $CHECKPOINT"
# Create a temporary config with resume_from set
python3 -c "
from omegaconf import OmegaConf
config = OmegaConf.load('$CONFIG')
config.training.resume_from = '$CHECKPOINT'
OmegaConf.save(config, '/tmp/train_gcp_resume.yaml')
print('Config updated with resume_from')
"
CONFIG="/tmp/train_gcp_resume.yaml"
else
echo "WARNING: Checkpoint $CHECKPOINT not found. Starting from scratch."
fi
fi
# Build the training command
if [ "$DISTRIBUTED" = true ] && [ "$NUM_GPUS" -gt 1 ]; then
TRAIN_CMD="cd ~/Train_Advanced_Lipsync_Model && source venv/bin/activate && torchrun --nproc_per_node=$NUM_GPUS -m src.training.train_model_distributed --config $CONFIG"
if [ "$RESUME" = true ] && [ -f "$CHECKPOINT" ]; then
TRAIN_CMD="$TRAIN_CMD --resume $CHECKPOINT"
fi
else
TRAIN_CMD="cd ~/Train_Advanced_Lipsync_Model && source venv/bin/activate && python -m src.training.train_model --config $CONFIG"
fi
# Kill existing session if any
tmux kill-session -t $SESSION_NAME 2>/dev/null || true
# Launch in tmux
echo ""
echo "Launching training in tmux session '$SESSION_NAME'..."
tmux new-session -d -s $SESSION_NAME "$TRAIN_CMD"
echo ""
echo "============================================"
echo " Training Started!"
echo "============================================"
echo ""
echo "Monitor commands:"
echo " tmux attach -t $SESSION_NAME # Watch live training"
echo " Ctrl+B then D # Detach from tmux"
echo " nvidia-smi -l 5 # GPU monitoring"
echo " tensorboard --logdir logs --port 6006 # TensorBoard"
echo ""
echo "Download checkpoints to your machine:"
echo " gsutil -m cp -r checkpoints/ gs://\$GCS_BUCKET/checkpoints/"
echo ""
echo "Stop training gracefully:"
echo " tmux send-keys -t $SESSION_NAME C-c"
echo ""

Xet Storage Details

Size:
3.94 kB
·
Xet hash:
8d8baf8986bdf023faad01d4bf2e38d3131f13e154f6e1f84b8aabb9b0f211ad

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