Skip to content

Instantly share code, notes, and snippets.

@ellisbrown
Last active April 5, 2024 02:50
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 ellisbrown/daeb16164561b5e30b8aa31f54aebca6 to your computer and use it in GitHub Desktop.
Save ellisbrown/daeb16164561b5e30b8aa31f54aebca6 to your computer and use it in GitHub Desktop.
List total TPU usage in a GCP project
#!/bin/bash
#params
PROJECT=my-project
ZONE=us-central2-b
# Command to list TPU resources
output=$(gcloud alpha compute tpus queued-resources list \
--project $PROJECT \
--zone $ZONE)
echo "$output"
echo "" # Add a blank line for readability
# Use awk to extract the numeric parts of the accelerator types and count TPUs
echo "$output" | awk '
BEGIN {
sum = 0
count = 0
}
$4 ~ /^v4-/ {
split($4, a, "-")
sum += a[2]
count++
}
END {
print "Total num TPU nodes:", sum
print "Count of TPUs:", count
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment