Set up the Cloud TPU environment
Before you can use Cloud TPU resources to train or run inference on models, you need to do the following set up steps:
- Set up your Google Cloud project
- Set up your environment to use Cloud TPU
- Prepare to request a Cloud TPU
Set up your Google Cloud project
You must have a Google Cloud account and project to use Cloud TPU.
Install the Google Cloud CLI. The Google Cloud CLI is an interface for accessing and managing Google Cloud resources and services.
Select or create a Google Cloud project:
In the Google Cloud console, select or create a Cloud project from the project selector.
In the Cloud Shell, set your project ID using the gcloud CLI. The project ID is the name of your project shown in the Google Cloud console.
$ gcloud config set project PROJECT-ID
Billing setup is required for all Google Cloud usage. You will only be charged after you start using Google Cloud resources. For more information, see the Cloud Billing documentation.
Billing for all Cloud TPU versions usage follows the standard regional pricing shown on the Cloud TPU pricing page.
Set up your environment to use Cloud TPU
Before requesting a Cloud TPU, you must activate the Cloud TPU API and ensure that you have permissions to manage access in your project and to create a Cloud TPU. It is also recommended that you create a user-managed service account to attach to your TPU.
Activate the Cloud TPU API from the Google Cloud console or using the gcloud CLI in the Cloud Shell:
$ gcloud services enable tpu.googleapis.com
- In the Google Cloud console, go to the Cloud TPU API page.
- Click Enable.
Make sure you have the following roles on your project:
- Service Account Admin: Needed to create a service account
- Project IAM Admin: Needed to grant a role in a project
- TPU Admin: Needed to create a TPU
Follow the instructions in View current access to view who has access to your project, folder, or organization. To view your own access, in the Principal column, find the row that has your email address. If your email address isn't in that column, then you don't have any roles. In the Role column for the row with your email address, check whether the list of roles includes the required roles.
If you don't have a required role, grant the role or ask an administrator to do so.
Create a TPU service account:
Service accounts allow the Cloud TPU service to access other Google Cloud services. A user-managed service account is a recommended Google Cloud practice. Attach a service account to your TPU when you create it using the
Follow the instructions in Create service accounts to create a service account.
Follow the instructions in Manage access to projects, folders, and organizations to grant your service account access to Google Cloud services that your TPU will access. The following roles are recommended so that your TPU to access commonly-used Google Cloud services.
Prepare to create a Cloud TPU
Before creating a Cloud TPU, you must request quota. You should also consider using queued resources, as well as which parameters you want to use to configure your TPU.
In order to create a Cloud TPU, your Google Cloud project must have quota for the version and size of TPU you want to create and the zone where you want to create it. For example, if you want to create a TPU v4-8 in
us-central2-b, you would request a quota of 8 TPU v4 cores in
us-central2-b. For more information about zones where Cloud TPU is available, see TPU regions and zones.
Quota is allocated differently depending on the TPU version. Different types of quota have different availability expectations. For more information about quota allocation, quota types, and how to request quota, see Quotas.
Determine if you want to use queued resources.
Creating a Cloud TPU as a queued resource is a best practice. Queued resources allow you to receive capacity once it becomes available. You can specify an optional start and end time for when the request should be filled.
There are different gcloud CLI commands for working with queued resources. For more information, see Queued resources user guide.
Determine Cloud TPU creation parameters:
Zone: Set the
--zoneflag to the zone where you want to create a TPU. You must have quota allocated in this zone. For more information, see TPU regions and zones.
TPU configuration: If you don't need to specify a custom topology, or you are using TPU v2 or v3, set the
vVERSION-TENSORCORES. Replace VERSION with the TPU version number you want to use. Replace TENSORCORES with the number of TensorCores you want to use.
If you want to customize the physical topology of your TPU, use the
--topologyflags. Set the
--versionflag to the TPU version you want to use. Set the
--topologyflag to the topology you want to use.
For more information about TPU configurations, including supported configurations and topology variants, see TPU configurations.
Software version: If you are requesting a queued resource, set the
--runtime-versionflag to the name of the software version you want to use. Otherwise, use the
--versionflag. TPU software versions are available for TensorFlow, PyTorch, and JAX frameworks. For more information about supported software versions, see TPU VM software versions.
Service account: Set
--service-accountto the email address of a service account, if you created one, to attach the service account to your TPU. If empty, the default Compute Engine service account will be used.
Quota type: If you want to create a TPU using reserved quota, add the
--reservedflag to your request.
If you want to create a TPU using preemptible quota, and you are requesting a queued resource, add the
--best-effortflag to your request.
If you want to create a TPU using preemptible quota, and you aren't requesting a queued resource, add the
--preemptibleflag to your request.
If you want to create a TPU using on-demand quota, you don't need to add any additional flags.
Advanced configuration: You can add additional flags to your request to configure your TPU. See the
gcloud compute tpus tpu-vm createdocumentation and the following sections in Manage TPUs for more information:
For examples of how to create a Cloud TPU, see Get started.