Create a MIG with GPU VMs Stay organized with collections Save and categorize content based on your preferences.
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:
To consume a reservation for a future reservation inAI Hypercomputer, seeCreate a MIG and a resize requestin the AI Hypercomputer documentation.
To consume a reservation for a future reservation in calendar mode, seeCreate a resize request in a MIG.
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
- To make sure that you have sufficient GPU quota for the resources you'rerequesting,check your GPU quota.
- To understand quota consumption, readGPU VMs and preemptible allocation quotas.
- If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
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:
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.
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. To perform this task, you must have the followingpermissions:Permissions required for this task
instanceTemplates.insert method.
Console
Go to theInstance templates page.
ClickCreate instance template. TheCreate an instance templatepage opens.
In theName field, enter a name for the instance template.
In theMachine configuration section, do the following:
Click theGPUs tab.
In theGPU type list, select the GPU type.
In theNumber of GPUs list, select the number of GPUs.
In theMachine type section, select a machine type.
In theProvisioning model section, do the following:
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.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).
Optional: To change the default value boot disk type or image, in theBoot disk section, clickChange. Then, follow the prompts tochange the boot disk.
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:
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.
Note: If you want to use a specific version of the OS image, such asIMAGE_FAMILY: animage family. This specifiesthe most recent, non-deprecated OS image. For example, if you specifydebian-12, the latest version in the Debian 12 image familyis used. For more information about using image families, seeImagefamilies best practices.debian-12-bookworm-v20240701, then replace the--image-familyflagwith the--imageflag.REGION: the region in which to create the instancetemplate.MACHINE_TYPE: aGPU machine type. Ifyou specify an N1 machine type, then include the--acceleratorflagto specify the number and type of GPUs to attach to your VMs.RUN_DURATION: the duration you want the requestedVMs to run. You must format the value as the number of days, hours,minutes, or seconds followed byd,h,m, orsrespectively. For example, specify30mfor 30 minutes or1d2h3m4sfor one day, twohours, three minutes, and four seconds. The value must be between 10minutes and seven days.
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 as
family/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 theguestAcceleratorsfieldto 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:
- All permissions required to call the
instanceGroupManagers.insertmethod.
Console
Go to theInstance groups page.
ClickCreate instance group. TheCreate instance group pageopens.
In theName field, enter a name for the MIG.
Before you select an instance template, you must delete the autoscalingconfiguration and turn off repairs as follows:
- To delete the autoscaling configuration, do the following:
- In theAutoscaling section, click theAutoscaling modelist, and then clickDelete autoscaling configuration.
- In the confirmation dialog, clickDelete.
- To turn off repairs, in theVM instance lifecycle section, clicktheDefault action on failure list, and then selectNo action.
- To delete the autoscaling configuration, do the following:
Go back to theInstance template field. In theInstance templatelist, select the instance template that you created in the previoussection.
Do one of the following:
- To create a resize request with the MIG, do the following:
- In theNumber of instances field, enter the number ofFlex-start VMs that you want to create all atonce.
- Select theUse resize request to create VMs all at oncecheckbox.
- 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, enter
0.
- To create a resize request with the MIG, do the following:
In theLocation section, specify whether you want to create a zonalor a regional MIG as follows:
- To create a zonal MIG, selectSingle zone. Or, to create aregional MIG, selectMultiple zones.
- Select theRegion andZones of the MIG.
- If you're creating a regional MIG, then do the following:
- In theTarget distribution shape field, selectAny single zone.
- In the dialog that appears, clickDisable instance redistribution.
ClickCreate.
gcloud
Create a zonal MIG using the
instance-groups managed createcommand:gcloud compute instance-groups managed createINSTANCE_GROUP_NAME \ --template=INSTANCE_TEMPLATE_URL \ --size=0 \ --zone=ZONE \ --default-action-on-vm-failure=do_nothing
In the MIG, create a resize request using the
instance-groups managed resize-requests createcommand.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
- For a regional instance template:
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
Create a zonal MIG by making a
POSTrequest to theinstanceGroupManagers.insertmethod.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" }}In the MIG, create a resize request by making a
POSTrequest to theinstanceGroupManagerResizeRequests.insertmethod.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
- For a regional instance template:
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
Learn howresize requests work in a MIG.
Learn how tocreate a regional MIG that is compatible with resize requests (Preview).
Learn how toview, cancel, or delete resize requests in a MIG.
Learn how toview info about MIGs and managed VMs.
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.