Create groups of GPU VMs using instance templates

Stay organized with collections Save and categorize content based on your preferences.

You can use instance templates to create managed instance groups with GPUs added to each instance. Managed instance groups use the template to create multiple identical instances. You can scale the number of instances in the group to match your workload.

Because the instances created must have the CUDA toolkit and NVIDIA driver installed, the process for creating an instance template for GPU instances is as follows:

  1. Create an instance that has attached GPUs.
  2. Install a GPU driver on the instance.
  3. Create an image from the disk that is attached to the VM instance that has the GPUs and drivers installed.
  4. Use the image to create an instance template.
  5. Use the template to create an instance group

Before you begin

Creating an instance template

For steps to create an instance template, see Creating instance templates.


To create the instance template using the Console, ensure that you make the following customizations:

  • Specify the machine type.
  • Specify the image name and family for your custom image that has attached GPUs and drivers.

For more information about using custom images, see Using custom or public images in your instance templates.


To create the instance template using gcloud compute instance-templates create, include the --accelerators and --maintenance-policy TERMINATE flags.

The following example creates an instance template with 2 vCPUs, a 250 GB boot disk based on your image (with drivers installed) and, an NVIDIA K80 GPU. Replace my-image and my-project with the image and project name for the image that has the attached GPUs and drivers.

gcloud compute instance-templates create gpu-template \
    --machine-type n1-standard-2 \
    --boot-disk-size 250GB \
    --accelerator type=nvidia-tesla-k80,count=1 \
    --image-family my-image \
    --image-project my-project \
    --maintenance-policy TERMINATE \

Creating an instance group

After you create the template, use the template to create an instance group. Every time you add an instance to the group, it starts that instance using the settings in the instance template.

If you are creating a regional managed instance group, be sure to select zones that specifically support the GPU model that you want. For a list of GPU models and available zones, see GPUs on Compute Engine. The following example creates a regional managed instance group across two zones that support the nvidia-tesla-k80 model.

gcloud compute instance-groups managed create example-rmig \
    --template gpu-template --base-instance-name example-instances \
    --size 30 --zones us-east1-c,us-east1-d

What's next?