Create Cloud TPU VMs
You create TPU VMs using the Create Node API, the queued resources API, or Google Kubernetes Engine (GKE).
You call the Create Node API when you run the gcloud compute tpus tpu-vm create
command using the Google Cloud CLI and when you create a TPU VM using the
Google Cloud console. When you use the Create Node API, the system processes your
request immediately. If there is not enough capacity to fulfill your request,
the request fails.
We recommend creating TPU VMs using the queued resources API. When you create a TPU VM using the queued resource API, the Cloud TPU service adds your queued resource request to a queue that the service maintains. When the requested resource becomes available, the service assigns it to your Google Cloud project for your immediate and exclusive use. For more information, see Manage queued resources.
If you want to use Google Kubernetes Engine (GKE) to manage TPU resources, first, create a GKE cluster. Then, add node pools containing TPU slices to your cluster. For more information, see About TPUs in GKE.
Prerequisites
Complete the following prerequisites:
Create a Google Cloud project for your TPUs as described in Set up a Google Cloud project for TPUs.
Determine your TPU requirements as described in Plan your Cloud TPU resources.
If you're using one of the Cloud Client Libraries, follow the setup instructions for the language you're using:
Set environment variables for creating a v5e TPU with eight chips. The following examples use a v5e TPU with eight chips. You can specify a different accelerator type and version. See TPU versions for more information.
export TPU_NAME=your-tpu-name export PROJECT_ID=your-project export ZONE=us-central1-a export ACCELERATOR_TYPE=v5litepod-8 export VERSION=v2-alpha-tpuv5-lite
Create a Cloud TPU using the Create Node API
You create a Cloud TPU using gcloud, the Google Cloud console,
or the Cloud TPU API.
When creating a Cloud TPU, specify the TPU software version (also called runtime version). To determine which software version to use, see TPU software versions.
Also, specify the number of TensorCores or TPU chips for the TPU configuration you are using. For more information, see the section for your TPU version in System architecture.
gcloud
Use the gcloud compute tpus tpu-vm create
command to create a TPU using the Create Node API. See
External and internal IP addresses
to configure specific internal or external IP addresses.
The following command creates a v5e TPU VM with 8 TPU chips:
gcloud compute tpus tpu-vm create $TPU_NAME \ --project=$PROJECT_ID --zone=$ZONE \ --accelerator-type=$ACCELERATOR_TYPE \ --version=$VERSION
Command flag descriptions
zone- The zone where you create your Cloud TPU.
accelerator-type- The accelerator type specifies the version and size of the Cloud TPU you create. For more information about supported accelerator types for each TPU version, see TPU versions.
version- The TPU software version.
Console
These instructions create a v5e TPU VM with 8 TPU chips:
In the Google Cloud console, go to the TPUs page:
Click Create TPU.
In the Name field, enter a name for your TPU.
In the Zone field, select the zone where you create the TPU.
In the TPU type field, select an accelerator type. The accelerator type specifies the version and size of the Cloud TPU you create. For more information about supported accelerator types for each TPU version, see TPU versions.
In the TPU software version field, select a software version. When creating a Cloud TPU VM, the TPU software version specifies the version of the TPU runtime to install. For more information, see TPU software versions.
Click Create to create your resources.
curl
The following command uses curl to create a v5e TPU VM with 8 TPU chips.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -d "{accelerator_type: $ACCELERATOR_TYPE, \ runtime_version:'$VERSION', \ network_config: {enable_external_ips: true}, \ shielded_instance_config: { enable_secure_boot: true }}" \ https://tpu.googleapis.com/v2/projects/$PROJECT_ID/locations/$ZONE/nodes?node_id=$TPU_NAME
Required fields
runtime_version- The Cloud TPU runtime version that you use.
project-id- The name of your enrolled Google Cloud project.
zone- The zone where you create your Cloud TPU.
node_name- The name of the TPU VM you create.
Java
This code example creates a v5e TPU VM with 8 TPU chips using the Cloud TPU API in Java.
To authenticate to Cloud TPU, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Node.js
This code example creates a v5e TPU VM with 8 TPU chips using the Cloud TPU API in Node.js.
To authenticate to Cloud TPU, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
This code example creates a v5e TPU VM with 8 TPU chips using the Cloud TPU API in Python.
To authenticate to Cloud TPU, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Run a startup script
You run a startup script on your TPU VM by specifying the
--metadata startup-script flag when you create the TPU VM.
gcloud
This command creates a TPU VM and specifies a startup script.
gcloud compute tpus tpu-vm create $TPU_NAME \ --zone=$ZONE \ --accelerator-type=$ACCELERATOR_TYPE \ --version=$VERSION \ --metadata startup-script='#! /bin/bash pip3 install numpy EOF'
Java
This code example creates a TPU VM and specifies a startup script in Java.
To authenticate to Cloud TPU, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Node.js
This code example creates a TPU VM and specifies a startup script in Node.js.
To authenticate to Cloud TPU, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
This code example creates a TPU VM and specifies a startup script in Python.
To authenticate to Cloud TPU, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
What's next
- Learn about queued resources.
- Learn how to manage TPU VMs.
- Learn about TPUs in GKE.
- Learn how to run JAX code on a TPU VM.
- Learn how to run PyTorch code on a TPU VM.
- Learn how to run an ML workload on TPUs, for example, Serve Qwen2-72B-Instruct with vLLM on TPUs.