Create GPU VMs in bulk

You can create a group of virtual machines (VMs) that have attached graphical processing units (GPUs) by using the bulk creation process. With the bulk creation process, you get upfront validation where the request fails fast if it is not feasible. Also, if you use the region flag, the bulk creation API automatically chooses the zone that has the capacity to fulfill the request.

To learn more about bulk creation, see About bulk creation of VMs. To learn more about creating VMs with attached GPUs, see Overview of creating an instance with attached GPUs.

Before you begin

Required roles

To get the permissions that you need to create VMs, ask your administrator to grant you the Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to create VMs. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create VMs:

  • compute.instances.create on the project
  • To use a custom image to create the VM: compute.images.useReadOnly on the image
  • To use a snapshot to create the VM: compute.snapshots.useReadOnly on the snapshot
  • To use an instance template to create the VM: compute.instanceTemplates.useReadOnly on the instance template
  • To specify a subnet for your VM: compute.subnetworks.use on the project or on the chosen subnet
  • To specify a static IP address for the VM: compute.addresses.use on the project
  • To assign an external IP address to the VM when using a VPC network: compute.subnetworks.useExternalIp on the project or on the chosen subnet
  • To assign a legacy network to the VM: compute.networks.use on the project
  • To assign an external IP address to the VM when using a legacy network: compute.networks.useExternalIp on the project
  • To set VM instance metadata for the VM: compute.instances.setMetadata on the project
  • To set tags for the VM: compute.instances.setTags on the VM
  • To set labels for the VM: compute.instances.setLabels on the VM
  • To set a service account for the VM to use: compute.instances.setServiceAccount on the VM
  • To create a new disk for the VM: compute.disks.create on the project
  • To attach an existing disk in read-only or read-write mode: compute.disks.use on the disk
  • To attach an existing disk in read-only mode: compute.disks.useReadOnly on the disk

You might also be able to get these permissions with custom roles or other predefined roles.

Overview

When creating VMs with attached GPUs using the bulk creation method, you can choose to create VMs in a region (such as u-france-east1) or in a specific zone such as (u-france-east1-a).

If you choose to specify a region, Compute Engine places the VMs in any zone within the region that supports GPUs.

Machine types

You can create GPU VMs in bulk by using accelerator-optimized machine types. Compute Engine offers different machine types to support your various workloads.

GPU machine types
AI and ML workloads
Accelerator-optimized A series machine types are designed for high performance computing (HPC), artificial intelligence (AI), and machine learning (ML) workloads.

For these machine types, the GPU model is automatically attached to the instance.

  • A3 High (NVIDIA H100)
    (nvidia-h100-80gb)
  • A3 Edge (NVIDIA H100)
    (nvidia-h100-80gb)

Create groups of A3 VMs

This section explains how you can create instances in bulk for the A3 High and A3 Edge machine series by using Google Cloud CLI, or REST.

gcloud

To create a group of VMs, use the gcloud compute instances bulk create command. For more information about the parameters and how to use this command, see Create VMs in bulk.

Example

This example creates two VMs that have attached GPUs by using the following specifications:

gcloud compute instances bulk create \
    --name-pattern="my-test-vm-#" \
    --region=REGION \
    --count=2 \
    --machine-type=MACHINE_TYPE \
    --boot-disk-size=200 \
    --image=IMAGE \
    --image-project=IMAGE_PROJECT \
    --on-host-maintenance=TERMINATE

Replace the following:

  • REGION: the region for the VMs. This region must support your selected accelerator-optimized machine type.
  • MACHINE_TYPE: the machine type that you selected. Choose from one of the following:

  • An A3 High machine type
  • An A3 Edge machine type
  • IMAGE: an operating system image that supports GPUs.

    If you want to use the latest image in an image family, replace the --image flag with the --image-family flag and set its value to an image family that supports GPUs. For example: --image-family=rocky-linux-8-optimized-gcp.

    You can also specify a custom image.

  • IMAGE_PROJECT: the Compute Engine image project that the OS image belongs to. If using a custom image, specify the project that the image belongs to.

  • If successful, the output is similar to the following:

    NAME          ZONE
    my-test-vm-1  u-france-east1-b
    my-test-vm-2  u-france-east1-b
    Bulk create request finished with status message: [VM instances created: 2, failed: 0.]
    

    Optional flags

    To further configure your instance to meet your workload or operating system needs, include one or more of the following flags when you run the gcloud compute instances bulk create command.

    Feature Description
    Provisioning model Sets the provisioning model for the instance. You can specify either STANDARD or SPOT. If you don't specify a provisioning model, then Compute Engine sets the value to STANDARD. For more information, see Compute Engine instances provisioning models.
    --provisioning-model=PROVISIONING_MODEL
    Placement policy Controls the placement of your instance within a zone. You can specify a compact policy to minimize network latency across your instances, or a spread policy to improve your instances' resilience against zone-specific disruptions.
       --resource-policies=POLICY_NAME
       

    Replace POLICY_NAME with the name of your placement policy. You can only create the instance in the same region as the policy.

    REST

    Use the regionInstances.bulkInsert method with the required parameters to create multiple VMs in a region. For more information about the parameters and how to use this command, see Create VMs in bulk.

    Example

    This example creates two VMs that have attached GPUs by using the following specifications:

    • VM names: my-test-vm-1, my-test-vm-2
    • Each VM has two GPUs attached, specified by using the appropriate accelerator-optimized machine type

      POST https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/regions/REGION/instances/bulkInsert
      {
      "namePattern":"my-test-vm-#",
      "count":"2",
      "instanceProperties": {
        "machineType":MACHINE_TYPE,
        "disks":[
          {
            "type":"PERSISTENT",
            "initializeParams":{
              "diskSizeGb":"200",
              "sourceImage":SOURCE_IMAGE_URI
            },
            "boot":true
          }
        ],
        "name": "default",
        "networkInterfaces":
        [
          {
            "network": "projects/PROJECT_ID/global/networks/default"
          }
        ],
        "scheduling":{
          "onHostMaintenance":"TERMINATE",
          ["automaticRestart":true]
        }
      }
      }
      

    Replace the following:

    • PROJECT_ID: your project ID
    • REGION: the region for the VMs. This region must support your selected GPU model.
    • MACHINE_TYPE: the machine type that you selected. Choose from one of the following:

    • An A3 High machine type
    • An A3 Edge machine type
  • SOURCE_IMAGE_URI: the URI for the specific image or image family that you want to use.

    For example:

    • Specific image: "sourceImage": "projects/rocky-linux-cloud/global/images/rocky-linux-8-optimized-gcp-v20220719"
    • Image family: "sourceImage": "projects/rocky-linux-cloud/global/images/family/rocky-linux-8-optimized-gcp".

    When you specify an image family, Compute Engine creates a VM from the most recent, non-deprecated OS image in that family. For more information about when to use image families, see Image family best practices.

  • Optional fields

    To further configure your instance to meet your workload or operating system needs, include one or more of the following flags when you run the instances.bulkInsert method.

    Feature Description
    Provisioning model To lower your costs, you can specify a different provisioning model by adding the "provisioningModel": "PROVISIONING_MODEL" field to the scheduling object in your request. For more information, see Compute Engine instances provisioning models.
        "scheduling":
         {
           "onHostMaintenance": "TERMINATE",
           "provisioningModel": "PROVISIONING_MODEL"
         }
      

    Replace PROVISIONING_MODEL with one of the following:

    • STANDARD: A standard instance. This is the default value.
    • SPOT: A Spot VM. If you create a Spot VM, then the onHostMaintenance and automaticRestart fields are overridden. Spot VMs are deeply discounted, but Compute Engine can preempt them at any time to reclaim capacity.
    Placement policy Controls the placement of your instance within a zone. You can specify a compact policy to minimize network latency across your instances, or a spread policy to improve your instances' resilience against zone-specific disruptions.
       "resourcePolicies": [
         "projects/PROJECT_ID/regions/REGION/resourcePolicies/POLICY_NAME"
       ]
       

    Replace the following:

    • REGION: the region where your placement policy exists. You can only create the instance in the same region as the policy.
    • POLICY_NAME: the name of your placement policy.