Create a MIG with GPU VMs

This document describes how to create a managed instance group (MIG) withvirtual machine (VM) instances that have attached GPUs. Specifically, itdescribes how to add GPU VMs all at once in a zonal MIG by usingresize requests andthe flex-start provisioning model. The VMs that you create by using theflex-start provisioning model are calledFlex-start VMs. If you wantto create a MIG resize request to consume a reservation, then see instead thefollowing:

Use a MIG resize request with the flex-start provisioning model to increase yourchances of obtaining GPU Flex-start VMs. In the request, you mustspecify the number of GPU Flex-start VMs that you want to create.Dynamic Workload Scheduler (DWS),the underlying scheduler mechanism, makes best-effort attempts to scheduleresize requests created across Compute Engine based on requested durations andresource availability. If your request resources become available, then the MIGcreates the Flex-start VMs.

If your job finishes earlier than the requested duration, then you can deletethe created Flex-start VMs. Otherwise, the MIG deletesFlex-start VMs at the end of their run duration.

You can also read about otherbasic scenarios for creating a MIG.

Before you begin

Limitations

Review thelimitationsfor creating a MIG resize request.

Create a MIG and add GPU VMs all at once

To create a MIG and add GPU Flex-start VMs all at once in thegroup, do the following:

  1. Create an instance template, which is requiredto create a MIG. The MIG creates each VM in the group based on the instancetemplate. In the template, specify the configuration for GPUFlex-start VMs and additional configurations required to useresize requests.

    For more information about instance templates, seeAbout instance templates.

  2. Create a MIG and a resize requestto add GPU Flex-start VMs all at once.

Create an instance template

Create an instance template that specifies asupported GPU machine seriesfor MIG resize requests, as described in this section. Then, use the template tocreate a MIG.

Note: If you want to run data science or machine learning workloads,consider using a Deep Learning VM image when you create aninstance template. Deep Learning VM Images is a set ofprepackaged VM images that comes with machine learning frameworks and essentialtools. For more information about these images, seeChoose an imagein the Deep Learning VM Images documentation.

Permissions required for this task

To perform this task, you must have the followingpermissions:

Console

  1. Go to theInstance templates page.

    Go to Instance templates

  2. ClickCreate instance template. TheCreate an instance templatepage opens.

  3. In theName field, enter a name for the instance template.

  4. In theMachine configuration section, do the following:

    1. Click theGPUs tab.

    2. In theGPU type list, select the GPU type.

    3. In theNumber of GPUs list, select the number of GPUs.

    4. In theMachine type section, select a machine type.

  5. In theProvisioning model section, do the following:

    1. In theVM provisioning model list, selectFlex-start.

      Note: When you select the flex-start provisioning model, you can't usereservations. The Google Cloud console automatically selects theDon't use a reservation option in theAdvanced options> Management> Reservationssection.
    2. To set a run duration for the VMs created through the instancetemplate, in theEnter number of hours field, enter the number ofhours. The value must be between one hour (1) and seven days(168).

  6. Optional: To change the default value boot disk type or image, in theBoot disk section, clickChange. Then, follow the prompts tochange the boot disk.

  7. ClickCreate.

gcloud

Create an instance template by using theinstance-templates create command:

gcloud compute instance-templates createINSTANCE_TEMPLATE_NAME \    --image-project=IMAGE_PROJECT \    --image-family=IMAGE_FAMILY \    --instance-termination-action=DELETE \    --instance-template-region=REGION \    --machine-type=MACHINE_TYPE \    --maintenance-policy=TERMINATE \    --max-run-duration=RUN_DURATION \    --provisioning-model=FLEX_START \    --reservation-affinity=none

Replace the following:

REST

Create an instance template by making aPOST request to theinstanceTemplates.insert method:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates{  "name": "INSTANCE_TEMPLATE_NAME",  "properties": {    "disks": [      {        "boot": true,        "initializeParams": {          "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE        }      }    ],    "machineType": "MACHINE_TYPE",    "networkInterfaces": [      {        "network": "global/networks/default"      }    ],    "reservationAffinity": {      "consumeReservationType": "NO_RESERVATION"    },    "scheduling": {      "instanceTerminationAction": "DELETE",      "maxRunDuration": {        "seconds":RUN_DURATION      },      "onHostMaintenance": "TERMINATE",      "provisioningModel": "FLEX_START"    }  }}

Replace the following:

  • PROJECT_ID: the ID of the project in which youwant to create the instance template.

  • REGION: the region in which to create the instancetemplate.

  • INSTANCE_TEMPLATE_NAME: the name of the instancetemplate.

  • IMAGE_PROJECT: the image project that contains theimage—for example,debian-cloud. For more informationabout the supported image projects, seePublic images.

  • IMAGE: specify one of the following:

    • A specific version of the OS image—for example,debian-12-bookworm-v20240617.

    • Animage family, which must beformatted asfamily/IMAGE_FAMILY. Thisspecifies the most recent, non-deprecated OS image. For example, ifyou specifyfamily/debian-12, the latest version in theDebian 12 image family is used. For more information about using imagefamilies, seeImage families best practices.

  • MACHINE_TYPE: aGPU machine type. Ifyou specify an N1 machine type, then include theguestAccelerators fieldto specify the number and type of GPUs to attach to your VMs.

  • RUN_DURATION: the duration, in seconds, you wantthe requested VMs to run before the MIG automatically deletes them. Thevalue must be between600, which is 600 seconds (10 minutes),and604800, which is 604,800 seconds (seven days).

After you create the instance template, you canview itto see its ID and review its instance properties.

Create a MIG and add GPU VMs all at once

Create a MIG as described in this section. To create a resize request in theMIG, you must not configureautoscaling and mustturn offrepairs.

Note: When you create a MIG by using the Google Cloud console, you can alsocreate a resize request in the MIG at the same time. Otherwise, if you want touse the gcloud CLI or REST, then you must create a MIG, andthen a resize request in the MIG.

Permissions required for this task

To perform this task, you must have the followingpermissions:

Console

  1. Go to theInstance groups page.

    Go to Instance groups

  2. ClickCreate instance group. TheCreate instance group pageopens.

  3. In theName field, enter a name for the MIG.

  4. Before you select an instance template, you must delete the autoscalingconfiguration and turn off repairs as follows:

    1. To delete the autoscaling configuration, do the following:
      1. In theAutoscaling section, click theAutoscaling modelist, and then clickDelete autoscaling configuration.
      2. In the confirmation dialog, clickDelete.
    2. To turn off repairs, in theVM instance lifecycle section, clicktheDefault action on failure list, and then selectNo action.
  5. Go back to theInstance template field. In theInstance templatelist, select the instance template that you created in the previoussection.

  6. Do one of the following:

    • To create a resize request with the MIG, do the following:
      1. In theNumber of instances field, enter the number ofFlex-start VMs that you want to create all atonce.
      2. Select theUse resize request to create VMs all at oncecheckbox.
      3. Optional: To specify a different run duration for the VMs thanthe one set in the instance template, in theRequested run duration field andUnit lists, specify aduration. The duration must be between one hour and seven days.
    • To create a resize request after you create the MIG, in theNumber of instances field, enter0.
  7. In theLocation section, specify whether you want to create a zonalor a regional MIG as follows:

    1. To create a zonal MIG, selectSingle zone. Or, to create aregional MIG, selectMultiple zones.
    2. Select theRegion andZones of the MIG.
    3. If you're creating a regional MIG, then do the following:
      1. In theTarget distribution shape field, selectAny single zone.
      2. In the dialog that appears, clickDisable instance redistribution.
  8. ClickCreate.

gcloud

  1. Create a zonal MIG using theinstance-groups managed create command:

    gcloud compute instance-groups managed createINSTANCE_GROUP_NAME \   --template=INSTANCE_TEMPLATE_URL \   --size=0 \   --zone=ZONE \   --default-action-on-vm-failure=do_nothing
  2. In the MIG, create a resize request using theinstance-groups managed resize-requests create command.Specify the number of GPU VMs that you want and the duration for whichyou want to run those VMs.

    gcloud compute instance-groups managed resize-requests createINSTANCE_GROUP_NAME \   --resize-request=RESIZE_REQUEST_NAME \   --resize-by=COUNT \   --zone=ZONE

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG.
  • INSTANCE_TEMPLATE_URL: the URL of the instance template that you want touse to create VMs in the MIG. The URL can contain either theIDor name of the instance template. Specify one of the following values:
    • For a regional instance template:projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
    • For a global instance template:INSTANCE_TEMPLATE_ID
  • ZONE: one of thezones available forCompute Engine.
  • RESIZE_REQUEST_NAME: the name of the resizerequest.
  • COUNT: the number of Flex-start VMsto add all at once in the group.

REST

  1. Create a zonal MIG by making aPOST request to theinstanceGroupManagers.insert method.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers{ "versions": [   {     "instanceTemplate": "INSTANCE_TEMPLATE_URL"   } ], "name": "INSTANCE_GROUP_NAME", "targetSize": 0, "instanceLifecyclePolicy": {   "defaultActionOnFailure": "DO_NOTHING" }}
  2. In the MIG, create a resize request by making aPOST request to theinstanceGroupManagerResizeRequests.insert method.In the request body, specify the number of GPUFlex-start VMs that you want to create all at once and theduration that you want to run those Flex-start VMs.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests{ "name": "RESIZE_REQUEST_NAME", "resizeBy":COUNT}

Replace the following:

  • PROJECT_ID: the ID of the project in which youwant to create the MIG.
  • INSTANCE_GROUP_NAME: the name of the MIG.
  • INSTANCE_TEMPLATE_URL: the URL of the instance template that you want touse to create VMs in the MIG. The URL can contain either theIDor name of the instance template. Specify one of the following values:
    • For a regional instance template:projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
    • For a global instance template:INSTANCE_TEMPLATE_ID
  • ZONE: one of thezones available forCompute Engine.
  • RESIZE_REQUEST_NAME: the name of the resizerequest.
  • COUNT: the number of Flex-start VMsto add all at once in the group.

The resize request that you create stays in theACCEPTED state until the MIGcreates all the requested GPU Flex-start VMs. After all GPUFlex-start VMs are created in the group, the state of the requestchanges toSUCCEEDED.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.