diff --git a/cluster/launch_autobot.sh b/cluster/launch_autobot.sh new file mode 100755 index 0000000..3b73bb0 --- /dev/null +++ b/cluster/launch_autobot.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# We want an option to take GPU_TYPE and NUM_GPUS as arguments. They should be flags. + +# Parse the arguments +while getopts ":t:n:" opt; do + case $opt in + t) GPU_TYPE=$OPTARG ;; + n) NUM_GPUS=$OPTARG ;; + \?) echo "Invalid option -$OPTARG" >&2; exit 1 ;; + esac +done + +# Shift the arguments so that $@ contains only the command to run +shift $((OPTIND-1)) + +# Default values +GPU_TYPE=${GPU_TYPE:-rtx3090} +NUM_GPUS=${NUM_GPUS:-1} + + +OUTPUT=$(python -m rpad.core.autobot available ${GPU_TYPE} ${NUM_GPUS} --quiet --local) + +# Split the output on the colon +NODE=${OUTPUT%%:*} +GPU_INDICES=${OUTPUT#*:} +COMMAND=$@ + +# Print the results (optional) +echo -e "######################################" +echo -e "Launching job:" +echo -e " Node:\t\t${NODE}" +echo -e " GPU type:\t${GPU_TYPE}" +echo -e " GPU indices:\t${GPU_INDICES}" +echo -e " Command:\t${COMMAND}" +echo -e "######################################" + +# For some reason, the -c option causes an error "option requires an argument", but it still works. +ssh -t ${NODE} bash -ic " +# Setup env. +cd ~/code/rpad/python_ml_project_template +source ~/miniconda3/bin/activate +conda activate python_ml_project_template + +# Now, treat the rest of the command line arguments as the command to run. +CUDA_VISIBLE_DEVICES=$GPU_INDICES $COMMAND + +echo '######################################' +echo 'Job finished.' +echo '######################################' + +# Deactivate the conda environment. +conda deactivate +"