Skip to content

Instantly share code, notes, and snippets.

@alpharomercoma
Last active February 4, 2025 18:54
Show Gist options
  • Save alpharomercoma/2d27cffee876fb0185e7aeb32e8825da to your computer and use it in GitHub Desktop.
Save alpharomercoma/2d27cffee876fb0185e7aeb32e8825da to your computer and use it in GitHub Desktop.

GCP TPU Setup

TPU Research Cloud Application (Optional)

To get free TPU access for 30 days from google for your machine/deep learning projects. Please read the terms and conditions.

  1. Apply to TPU Research Cloud
  2. Instantly receieve an email form with subject [TRC] Welcome to the TPU Research Cloud!
  3. Follow the steps in the received email, create your project, and send the form
  4. Receive an email with subject [TRC] You have access to free Cloud TPUs within 3-4 days

Why did I document this?

Because I encountered ERROR: (gcloud.compute.tpus.tpu-vm.create) INVALID_ARGUMENT: Cloud TPU received a bad request. The value "default" provided for field "Subnetwork" does not exist. See "https://cloud.google.com/vpc/docs/create-modify-vpc-networks" for more information: invalid argument in running gcloud compute tpus tpu-vm create node-02 --zone=us-central2-b --accelerator-type=v4-8 --version=tpu-ubuntu2204-base --preemptible while following this tutorial on GitHub

Steps

All steps here will be done through the google cloud browser terminal unless stated (Local Machine) although they can also be done by installing the goodle cloud CLI (see step 6) first. Keep in mind in what regions your quota from the email is located and modify accordingly. Replace the variables like $EXAMPLE

  1. Switch project
gcloud projects list

gcloud config set project $GCP_PROJECT_ID
  1. Create network
gcloud compute networks create my-network --subnet-mode=auto
  1. Create subnet
gcloud compute networks subnets create my-subnet \
    --network=my-network \
    --region=us-central2 \
    --range=172.16.1.0/24
  1. Enable SSH
gcloud compute firewall-rules create allow-ssh \
    --network=my-network \
    --allow=tcp:22
  1. Create TPU
gcloud compute tpus tpu-vm create $CLOUD_TPU_PROJECT_NAME \
    --zone=us-central2-b \
    --accelerator-type=v4-8 \
    --version=tpu-ubuntu2204-base \
    --network my-network \
    --subnetwork my-subnet
  1. Install Google Cloud CLI (Local Machine)
mkdir google_cloud

cd google_cloud

curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz

tar -xf google-cloud-cli-linux-x86_64.tar.gz

./google-cloud-sdk/install.sh

./google-cloud-sdk/bin/gcloud init
  1. SSH into TPU instance (Local Machine)
./google-cloud-sdk/bin/gcloud compute tpus tpu-vm ssh \
    --zone "us-central2-b" \
    "$CLOUD_TPU_PROJECT_NAME" \
    --project "$GCP_PROJECT_ID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment