Download training_yutubeasl/scripts/select_gpus.sh from SignerX/SignX: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/datasets/SignerX/SignX/resolve/main/training_yutubeasl/scripts/select_gpus.sh
- Command line
-
hf download hf://datasets/SignerX/SignX/training_yutubeasl/scripts/select_gpus.sh
-
curl -L -o select_gpus.sh https://huggingface.co/datasets/SignerX/SignX/resolve/main/training_yutubeasl/scripts/select_gpus.sh
1.82 kB
| # Auto-select available GPUs based on memory usage | |
| # Usage: source select_gpus.sh | |
| # Returns: CUDA_VISIBLE_DEVICES and GPU_LIST for training | |
| MEMORY_THRESHOLD=20 # Skip GPUs with >20% memory usage | |
| MAX_GPUS=1 # Maximum number of GPUs to use | |
| # Get GPU info: index, memory_used, memory_total | |
| gpu_info=$(nvidia-smi --query-gpu=index,memory.used,memory.total --format=csv,noheader,nounits) | |
| available_gpus=() | |
| gpu_list=() | |
| while IFS=, read -r idx mem_used mem_total; do | |
| # Trim whitespace | |
| idx=$(echo $idx | xargs) | |
| mem_used=$(echo $mem_used | xargs) | |
| mem_total=$(echo $mem_total | xargs) | |
| # Calculate memory usage percentage | |
| mem_percent=$(awk "BEGIN {printf \"%.2f\", ($mem_used/$mem_total)*100}") | |
| # Check if GPU is available (memory usage < threshold) | |
| if (( $(awk "BEGIN {print ($mem_percent < $MEMORY_THRESHOLD)}") )); then | |
| available_gpus+=($idx) | |
| gpu_list+=($idx) | |
| echo "GPU $idx: ${mem_percent}% memory used - AVAILABLE" >&2 | |
| else | |
| echo "GPU $idx: ${mem_percent}% memory used - BUSY (skipped)" >&2 | |
| fi | |
| # Stop if we have enough GPUs | |
| if [ ${#available_gpus[@]} -ge $MAX_GPUS ]; then | |
| break | |
| fi | |
| done <<< "$gpu_info" | |
| # Export CUDA_VISIBLE_DEVICES | |
| if [ ${#available_gpus[@]} -eq 0 ]; then | |
| echo "ERROR: No available GPUs found!" >&2 | |
| exit 1 | |
| fi | |
| export CUDA_VISIBLE_DEVICES=$(IFS=,; echo "${available_gpus[*]}") | |
| export GPU_LIST="[$(IFS=,; echo "${gpu_list[*]}")]" | |
| export NUM_GPUS=${#available_gpus[@]} | |
| echo "" >&2 | |
| echo "Selected GPUs: $CUDA_VISIBLE_DEVICES" >&2 | |
| echo "GPU List for training: $GPU_LIST" >&2 | |
| echo "Number of GPUs: $NUM_GPUS" >&2 | |
| echo "" >&2 | |
| # Print variables for sourcing | |
| echo "export CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES" | |
| echo "export GPU_LIST='$GPU_LIST'" | |
| echo "export NUM_GPUS=$NUM_GPUS" | |