Skip to content

Instantly share code, notes, and snippets.

@hfoffani
Last active December 23, 2022 07: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 hfoffani/93b12f55915178bfa454b20bd202ddf1 to your computer and use it in GitHub Desktop.
Save hfoffani/93b12f55915178bfa454b20bd202ddf1 to your computer and use it in GitHub Desktop.
Script for managing Google Cloud instances for fast.ai. Requires gcloud cli tool.
#!/bin/bash
# Manage GCP instances for fast.ai projects
# Based on https://arunoda.me/blog/ideal-way-to-creare-a-fastai-node
# For Mac OS. Minor modifications for other OSs.
# Requires:
# a GCP account
# a GCP image
# gcloud cli tool
project=fastai
current_zone='us-west1-b'
start () {
accelerator=""
machine_type=""
case "$1" in
min) accelerator="" ; machine_type="n1-standard-4" ;;
k80) accelerator="--accelerator=type=nvidia-tesla-k80,count=1" ; machine_type="n1-standard-4" ;;
p4) accelerator="--accelerator=type=nvidia-tesla-p100,count=1" ; machine_type="n1-standard-4" ;;
p100) accelerator="--accelerator=type=nvidia-tesla-p100,count=1" ; machine_type="n1-standard-8" ;;
v100) accelerator="--accelerator=type=nvidia-tesla-v100,count=1" ; machine_type="n1-standard-8" ;;
*) echo bad argument; return ;;
esac
gcloud beta compute instances create $project \
--zone=$current_zone \
--machine-type=$machine_type \
--subnet=$project \
--network-tier=PREMIUM \
--no-restart-on-failure \
--maintenance-policy=TERMINATE --preemptible \
$accelerator \
--disk=name=$project-boot,device-name=$project-boot,mode=rw,boot=yes
}
ssh () {
gcloud beta compute ssh $project
}
stop() {
gcloud compute instances delete $project
}
ip() {
ip=`gcloud beta compute instances list | grep $project | sed 's/ */ /g' | cut -d ' ' -f6`
echo ${ip}
}
jupyter() {
vmip=$(ip)
open "/Applications/Firefox.app" --args -url "http://${vmip}:8888/"
}
help() {
echo ""
echo "fastai start {min|k80|p4|p100|v100}"
echo "fastai stop"
echo "fastai ssh"
echo "fastai ip"
echo "fastai jupyter"
echo "fastai help"
echo ""
}
command=$1
if [ "$#" == 0 ]; then
help
else
$command $2 $3
fi
@alexa1829
Copy link

Best AI Content Write and AI Images Generator from Text Prompts: https://writerzingo.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment