Create a MIG with single-host TPU slices

This document describes how to create a managed instance group (MIG) that forms single-host TPU slices. A single-host TPU slice maps to one TPU virtual machine (VM) instance.

You can also create a single-host TPU slice as a standalone TPU instance. For more information, see Create a TPU VM instance.

Before you begin

Prerequisites

Before you proceed to create a single-host TPU slice, you must do the following:

  1. Choose the TPU version: select the TPU version that is suitable for your workload. For a list of TPU versions by workload type, see Recommended TPU versions by workload types.

  2. Validate TPU availability in your preferred location: TPUs are available in specific Google Cloud regions. To use a TPU version, ensure its availability in your preferred region. For a list of TPU locations, see TPU availability.

  3. Ensure that your project has sufficient TPU quota: if you are creating a single-host TPU slice with on-demand or Spot VMs, you must have sufficient TPU quota available in the region that you want to use. Creating a single-host TPU slice that consumes a TPU reservation doesn't require any TPU quota as quota is used when the reservation was created. For a list of TPU quota names, see TPU quota and for instructions on how to view the quota, see View and manage quotas

  4. Choose a TPU consumption option: select a consumption option that best fits your workload, its duration, and your cost needs. For a list of consumption option availability by TPU versions, see TPU consumption options.

  5. Choose a topology: select a topology supported for the selected TPU version. For a list of topologies available for each TPU version, see TPU topology.

Create a MIG with multiple single-host TPU slices

To create multiple, independent TPU VMs in a MIG:

  1. Create an instance template.
  2. Create the MIG.

Create an instance template

Instance template configurations vary based on the consumption option you use: on-demand, Spot, reservations, or Flex-start. For more information about consumption options, see About VM provisioning models .

Create an instance template for an on-demand TPU VM

The following command creates an instance template that uses the on-demand consumption option:

gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --machine-type=MACHINE_TYPE \
    --maintenance-policy=TERMINATE \
    --image-family=IMAGE_FAMILY \
    --image-project=IMAGE_PROJECT

Replace the following placeholders:

Create an instance template for a TPU Spot VM

The following command creates an instance template that uses the Spot consumption option:

 gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --machine-type=MACHINE_TYPE \
    --maintenance-policy=TERMINATE \
    --instance-termination-action=STOP \
    --provisioning-model=SPOT \
    --image-family=IMAGE_FAMILY \
    --image-project=IMAGE_PROJECT

Replace the following placeholders:

Create an instance template for a TPU reservation-bound VM

The following command creates an instance template that uses the reservation-bound consumption option:

 gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --machine-type=MACHINE_TYPE \
    --maintenance-policy=TERMINATE \
    --instance-termination-action=DELETE \
    --reservation-affinity=specific \
    --provisioning-model=reservation-bound \
    --reservation=RESERVATION_NAME \
    --image-family=IMAGE_FAMILY \
    --image-project=IMAGE_PROJECT

Replace the following placeholders:

Create an instance template for a TPU Flex-start VM

The following command creates an instance template that uses the Flex-start consumption option:

 gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --machine-type=MACHINE_TYPE \
    --maintenance-policy=TERMINATE \
    --instance-termination-action=DELETE \
    --provisioning-model=FLEX_START \
    --max-run-duration=DURATION \
    --image-family=IMAGE_FAMILY \
    --image-project=IMAGE_PROJECT

Replace the following placeholders:

Create a MIG

Create a zonal or a regional MIG by using the gcloud compute instance-groups managed create command as follows:

Replace the following placeholders:

Create VMs with custom names in a MIG

You can create VMs in a MIG by specifying custom names for each VM. This is useful for debugging and ensuring instances are created in a specific order.

gcloud

Create a VM with custom name by using the create-instance command and specify the --instance flag. To create multiple VMs, repeat the command for each VM. Otherwise, use the REST API method to specify multiple VMs in a single request.

Replace the following placeholders:

  • MIG_NAME: The name of your MIG.
  • ZONE: The zone of the MIG.
  • REGION: The region of the MIG.
  • INSTANCE_NAME: The name of the VM to add to the specified MIG.

    REST

    Create VMs with custom names by using one of the following REST API methods:

    Replace the following placeholders:

    What's next