| | #!/bin/bash |
| |
|
| | |
| |
|
| | zone="us-central2-b" |
| | name=$1 |
| |
|
| | echo "Connecting to $name"; |
| |
|
| | |
| | output=$(gcloud compute tpus describe $name --zone $zone 2>/dev/null) |
| | if [ $? != 0 ]; then |
| | echo "Could not find a tpu-v4 with this name in the zone $zone. Exiting." |
| | exit 1 |
| | fi |
| |
|
| | tputype=$(echo $output | awk '{print $2}') |
| | tpusize=$(echo $tputype| cut -c4-) |
| | size="$(($tpusize / 8))" |
| |
|
| | if (( $size < 1 )); then |
| | echo "This is reported as a $tputype with $size tpu(s). This is not a valid tpu-v4 resource. Exiting." |
| | exit 1 |
| | fi |
| |
|
| |
|
| | |
| | |
| |
|
| | tmux has-session -t $name 2>/dev/null |
| |
|
| |
|
| | if [ $? != 0 ]; then |
| | tmux new-session -d -s $name |
| | tmux select-layout main-vertical |
| |
|
| | for i in $(seq $(($size-1))); do |
| | tmux split-window -v -d -t $name |
| | |
| | tmux select-layout main-horizontal |
| | done |
| |
|
| | for i in $(seq $(($size))); do |
| | worker=$(($i -1)) |
| | command="gcloud alpha compute tpus tpu-vm ssh $name --zone $zone --worker $worker" |
| | tmux select-pane -t $name:0.$worker |
| | tmux send-keys -t $name "$command" Enter |
| |
|
| | done |
| |
|
| | |
| | if ((size >= 16));then |
| | tmux select-layout tiled |
| | else |
| | tmux select-layout tiled |
| | tmux select-layout main-vertical |
| | fi |
| |
|
| | |
| | |
| | |
| |
|
| | |
| | tmux select-pane -t $name:0.0 |
| |
|
| | |
| | tmux resize-pane -L 50 |
| |
|
| |
|
| |
|
| | |
| | tmux set-window-option -t $name:0 synchronize-panes on |
| |
|
| | |
| | tmux set-option -t $name pane-border-status top |
| | tmux set-option -t $name pane-border-format "worker #{pane_index} " |
| |
|
| |
|
| | fi |
| |
|
| | |
| | tmux attach -t $name |
| |
|