forked from beneisner/python_pkg_template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
" |