Skip to content

Instantly share code, notes, and snippets.

@mkrupczak3
Created February 26, 2024 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkrupczak3/2c7f17d7730b11c981b7feab48e76d4c to your computer and use it in GitHub Desktop.
Save mkrupczak3/2c7f17d7730b11c981b7feab48e76d4c to your computer and use it in GitHub Desktop.
Fixed script from Puget Systems article
#!/usr/bin/env bash
# Set power limits on all NVIDIA GPUs
# Make sure nvidia-smi exists
command -v nvidia-smi &> /dev/null || { echo >&2 "nvidia-smi not found ... exiting."; exit 1; }
# adjust as needed
POWER_LIMIT=270
# modified, this line relies on the assumption that all GPUs are the same model
MAX_POWER_LIMIT=$(nvidia-smi -q -d POWER | grep 'Max Power Limit' | grep -v 'N/A' | tr -s ' ' | cut -d ' ' -f 6 | cut -d '.' -f 1 | head -1)
if [[ ${POWER_LIMIT%.*}+0 -lt ${MAX_POWER_LIMIT%.*}+0 ]]; then
/usr/bin/nvidia-smi --persistence-mode=1
/usr/bin/nvidia-smi --power-limit=${POWER_LIMIT}
else
echo 'FAIL! POWER_LIMIT set above MAX_POWER_LIMIT ... '
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment