From 5c95a8482f5ac44efea3606ae57b1862de1906c2 Mon Sep 17 00:00:00 2001 From: Niels Geens Date: Fri, 14 Mar 2025 11:22:45 +0100 Subject: [PATCH] Added script to start runpod --- scripts/runpod.sh | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 scripts/runpod.sh diff --git a/scripts/runpod.sh b/scripts/runpod.sh new file mode 100644 index 0000000..52e1480 --- /dev/null +++ b/scripts/runpod.sh @@ -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 \ No newline at end of file