Added script to start runpod
This commit is contained in:
85
scripts/runpod.sh
Normal file
85
scripts/runpod.sh
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script for setting up and running SIA on RunPod
|
||||
# Requires the RunPod CLI (runpodctl) to be installed and configured
|
||||
|
||||
# Export MSYS_NO_PATHCONV=1 for Git Bash compatibility
|
||||
export MSYS_NO_PATHCONV=1
|
||||
|
||||
# =================== Configuration ===================
|
||||
# These can be overridden by environment variables or .env file
|
||||
|
||||
# Pod configuration
|
||||
GPU_TYPE=${GPU_TYPE:-"NVIDIA GeForce RTX 3090"}
|
||||
GPU_COUNT=${GPU_COUNT:-1}
|
||||
CONTAINER_DISK_SIZE=${CONTAINER_DISK_SIZE:-50} # GB
|
||||
MEMORY=${MEMORY:-20} # GB
|
||||
CPU_COUNT=${CPU_COUNT:-1} # vCPUs
|
||||
POD_NAME=${POD_NAME:-"sia-agent"}
|
||||
VOLUME_SIZE=${VOLUME_SIZE:-100} # GB
|
||||
VOLUME_PATH=${VOLUME_PATH:-"/root/data"} # Mount path within container
|
||||
|
||||
# Docker configuration
|
||||
DOCKER_IMAGE=${DOCKER_IMAGE:-"runpod/pytorch:2.1.0-py3.10-cuda11.8.0-devel-ubuntu22.04"}
|
||||
|
||||
# Load environment variables from .env file if it exists
|
||||
if [ -f .env ]; then
|
||||
echo "Loading environment variables from .env file"
|
||||
source .env
|
||||
fi
|
||||
|
||||
# Create pod
|
||||
echo "Creating RunPod instance with GPU type: $GPU_TYPE"
|
||||
output=$(runpodctl create pod \
|
||||
--name "$POD_NAME" \
|
||||
--imageName "$DOCKER_IMAGE" \
|
||||
--gpuType "$GPU_TYPE" \
|
||||
--gpuCount $GPU_COUNT \
|
||||
--containerDiskSize $CONTAINER_DISK_SIZE \
|
||||
--volumeSize $VOLUME_SIZE \
|
||||
--volumePath "$VOLUME_PATH" \
|
||||
--mem $MEMORY \
|
||||
--vcpu $CPU_COUNT \
|
||||
--ports "8080/http,8888/http" \
|
||||
--env "SIA_QWQ_ENABLED=1" \
|
||||
--env "SIA_HF_API_KEY=$SIA_HF_API_KEY" \
|
||||
)
|
||||
|
||||
echo "$output"
|
||||
|
||||
# Extract the last line of output (should contain pod ID)
|
||||
last_line=$(echo "$output" | tail -n 1)
|
||||
# Extract pod ID - look for the word "pod" followed by ID in quotes
|
||||
if [[ $last_line =~ pod\ \"([a-zA-Z0-9]+)\" ]]; then
|
||||
pod_id="${BASH_REMATCH[1]}"
|
||||
else
|
||||
# Try to get the last word which is often the pod ID
|
||||
pod_id=$(echo "$last_line" | awk '{print $NF}')
|
||||
fi
|
||||
|
||||
# If the ID has a double quote at the end, remove it
|
||||
pod_id=${pod_id%\"}
|
||||
|
||||
# Validate we have a proper pod ID (alphanumeric)
|
||||
if ! [[ $pod_id =~ ^[a-zA-Z0-9]+$ ]]; then
|
||||
echo "Invalid pod ID detected: $pod_id" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
while [ true ]; do
|
||||
echo "Waiting for pod $pod_id to be ready..."
|
||||
sleep 5
|
||||
|
||||
# Get the output directly and check if it contains RUNNING
|
||||
output=$(runpodctl get pod "$pod_id" 2>&1)
|
||||
|
||||
# Print the output for debugging
|
||||
echo "$output"
|
||||
|
||||
# Check both STATUS RUNNING (with two spaces) and STATUS RUNNING (with one space)
|
||||
if echo "$output" | grep -q "STATUS *RUNNING" || echo "$output" | grep -q "RUNNING"; then
|
||||
echo "Pod is now running!"
|
||||
break
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user