#!/bin/bash # Launch training on a remote node, pinning CUDA_VISIBLE_DEVICES. # Usage: scripts/launch.sh [gpu-index-or-auto] # Default "auto" claims the first GPU with no compute processes. set -euo pipefail NODE=$1; CONFIG=$2; SEED=$3; GPU=${4:-auto} REPO=/fsx/ajay-stu/Translation_Guided_Sandhi_Splitting_Experiment_Guide NAME=$(basename "$CONFIG" .yaml)_seed${SEED} LOG=$REPO/outputs/logs/${NAME}.log if [ "$GPU" = "auto" ]; then # Combine "no compute app" with "< 100 MiB" so a just-launched job counts busy. GPU=$(ssh -o BatchMode=yes -o StrictHostKeyChecking=no "$NODE" \ 'python3 -c " import subprocess busy=set() for l in subprocess.check_output([\"nvidia-smi\",\"--query-compute-apps=gpu_uuid\",\"--format=csv,noheader\"],text=True).splitlines(): busy.add(l.strip()) uuid={} for l in subprocess.check_output([\"nvidia-smi\",\"--query-gpu=index,uuid,memory.used\",\"--format=csv,noheader,nounits\"],text=True).splitlines(): i,u,m=[x.strip() for x in l.split(\",\")] if u not in busy and int(m)<100: print(i); break "') fi if [ -z "$GPU" ]; then echo "NO FREE GPU on $NODE"; exit 1; fi echo "node=$NODE gpu=$GPU config=$CONFIG seed=$SEED -> $LOG" ssh -o BatchMode=yes -o StrictHostKeyChecking=no "$NODE" bash -lc "' cd $REPO export PYTHONNOUSERSITE=1 HF_HOME=/fsx/ajay-stu/hf_cache export CUDA_VISIBLE_DEVICES=$GPU TOKENIZERS_PARALLELISM=false nohup ./.conda-env/bin/python -I src/splitter/train.py \ --config $CONFIG --seed $SEED > $LOG 2>&1 & echo started pid \$! '"