Add or remove GPUs

Linux Windows

Compute Engine provides graphics processing units (GPUs) that you canadd to your virtual machine (VM) instances. You can use these GPUs to acceleratespecific workloads on your VMs such as machine learning and dataprocessing.

You can only use two machine families when running GPUs on Compute Engine:

  • The accelerator-optimized machine family. All accelerator-optimized machinetypes have attached GPUs.
  • The N1 general-purpose machine family. You can usemost N1 machine types except the N1 shared-core machine type. If you are notusing an N1 general-purpose machine, you canswitch to an N1 general-purpose machineand then add the GPUs.

Before you begin

Accelerator-optimized VMs

Each accelerator-optimized machine type has a specific model of NVIDIA GPUsattached to support the recommended workload type.

AI and ML workloadsGraphics and visualization
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.

Accelerator-optimized G series machine types are designed for workloads such as NVIDIA Omniverse simulation workloads, graphics-intensive applications, video transcoding, and virtual desktops. These machine types supportNVIDIA RTX Virtual Workstations (vWS).

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

  • A4X (NVIDIA GB200 Superchips)
    (nvidia-gb200)
  • A4 (NVIDIA B200)
    (nvidia-b200)
  • A3 Ultra (NVIDIA H200)
    (nvidia-h200-141gb)
  • A3 Mega (NVIDIA H100)
    (nvidia-h100-mega-80gb)
  • A3 High (NVIDIA H100)
    (nvidia-h100-80gb)
  • A3 Edge (NVIDIA H100)
    (nvidia-h100-80gb)
  • A2 Ultra (NVIDIA A100 80GB)
    (nvidia-a100-80gb)
  • A2 Standard (NVIDIA A100)
    (nvidia-a100-40gb)
  • G4 (NVIDIA RTX PRO 6000)
    (nvidia-rtx-pro-6000)
    (nvidia-rtx-pro-6000-vws)
  • G2 (NVIDIA L4)
    (nvidia-l4)
    (nvidia-l4-vws)

You can modify each accelerator-optimized instance as follows:

  • For A4X, A4, A3, and A2 Ultra instances, you can't modify the machine type.If you are using any of these machine types for your instance and you need tochange the machine type, create a new instance.

  • For A2 Standard instances, you can modify the GPU count by switching from oneA2 Standard machine type to another A2 Standard machine type.

  • For G4 instances, you can modify the GPU count by switching from oneG4 machine type to another G4 machine type.

  • For G2 instances, you can do the following:

    • You can modify the GPU count by switching from one G2 machine typeto another G2 machine type.
    • You can switch from a G2 machine type to a machine type from adifferent machine family such as general-purpose or compute-optimized.SeeEdit the machine type of a VM.
  • You can't remove GPUs from any of the accelerator-optimized machine type.

Modify the GPU count

You can modify the GPU count of an A2 standard, G4, or G2 accelerator-optimized instanceby using either the Google Cloud console, or REST.

Console

You can modify the number of GPUs for your instance by stopping the instance andediting the instance configuration.

  1. Verify that all of your critical applications are stopped on theinstance.

  2. In the Google Cloud console, go to theVM instances page to see your listof instances.

    Go to VM instances

  3. Click the name of the instance that you want to modify the number of GPUs for.TheDetails page opens.

  4. Complete the following steps from theDetails page.

    1. If the instance is running, clickStopto stop the instance. If there is noStop option, clickMore actions >Stop.

    2. ClickEdit.

    3. In theMachine configuration section, select theGPUs machinefamily, and then do the following:

      1. In theNumber of GPUs list, increase or decrease the GPU count.

        Note: Each accelerator-optimized machine type has a specificnumber of GPUs attached. If you adjust the number of GPUs, themachine type changes.
    4. To apply your changes, clickSave.

    5. To restart the instance, clickStart/Resume.

REST

You can modify the number of GPUs on your instance by stopping the instance andchanging the machine type. Each accelerator-optimized machine type hasa specific number of GPUs attached. If you change the machine type, thisadjusts the number of GPUs that are attached to the instance.

  1. Verify that all of your critical applications are stopped on the instance,and then create a POST command to stop the instance so it can move toa host system where GPUs are available.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/stop
  2. After the instance stops, create a POST request to modify the machine type.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/setMachineType{   machineType: "zones/ZONE/machineTypes/MACHINE_TYPE"}
  3. Start the instance.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/start

Replace the following:

Limitations

A2 instances

  • You can only request capacity by using thesupported consumption optionsfor an A2 Standard machine type.
  • You don't receivesustaineduse discounts andflexible committed usediscounts for instances that use an A2 Standard machine type.
  • You can only use an A2 Standard machine type in certainregionsand zones.
  • The A2 Standard machine type is only available on theCascade Lake platform.
  • If your instance uses an A2 Standard machine type, you can only switch from one A2 Standard machine typetype to another A2 Standard machine type. You can't change to any other machine type.For more information, seeModify accelerator-optimized instances.
  • You can't use the Windows operating system with thea2-megagpu-16g machine type.When using a Windows operating system, choose a different A2 Standard machine type.
  • You can't do a quick format of the attached Local SSDs on Windows instances that use A2 Standard machine types.To format these Local SSDs, you must do a full format by using thediskpartutility and specifyingformat fs=ntfs label=tmpfs.

G2 instances

  • You can only request capacity by using thesupported consumption optionsfor a G2 machine type.
  • You don't receivesustaineduse discounts andflexible committed usediscounts for instances that use a G2 machine type.
  • You can only use a G2 machine type in certainregionsand zones.
  • The G2 machine type is only available on theCascade Lake platform.
  • Standard Persistent Disk (pd-standard) isn't supported on instances that use theG2 machine type. For supported disk types, seeSupported disk types for G2.
  • You can't createMulti-InstanceGPUs on an instance that uses a G2 machine type.
  • If you need to change the machine type of a G2 instance, reviewModify accelerator-optmized instances.
  • You can't useDeep Learning VM Images as boot disksfor instances that use the G2 machine type.
  • The current default driver for Container-Optimized OS doesn't support L4 GPUs running onG2 machine types. Also, Container-Optimized OS only supports a select set of drivers.If you want to use Container-Optimized OS on G2 machine types, review the following notes:
    • Use a Container-Optimized OS version that supports the minimum recommended NVIDIA driver version525.60.13 or later. For more information, review theContainer-Optimized OS release notes.
    • When youinstall the driver, specify the latest available version that works for the L4 GPUs. For example,sudo cos-extensions install gpu -- -version=525.60.13.
  • You must use the Google Cloud CLI or REST tocreate G2 instancesfor the following scenarios:
    • You want to specify custom memory values.
    • You want to customize the number of visible CPU cores.

G4 instances

N1-general purpose instances

This section covers how to add, modify, or remove GPUs from a N1-generalpurpose machine.

In summary, the process to add, modify, or remove GPUs from an existing instance is asfollows:

  1. Check that your instance has a boot disk size of at least 40 GB.
  2. Stop the instance.
  3. Add, modify, or remove the GPUs.

    If your N1 instance doesn't have any GPUs attached, you need to complete thefollowing steps:

    1. Prepare your instance for the modification.
    2. Modify the host maintenance setting for the instance. Instances with GPUs cannotlive migratebecause they are assigned to specific hardware devices. For more information,seeGPU restrictions.
    3. Change the machine type. GPUs are only supported onselect N1 machine types.
    4. Install a GPU driver on your instance,so that your system can use the GPU device.

Prepare your instance

When a GPU is added to an instance, the order of the network interface can change.

Most public images on Compute Engine don't have persistent networkinterface names and adjust to the new order.

However, if you are using either SLES or a custom image, you must update thesystem setting to prevent the network interface from persisting. To prevent thenetwork interface from persisting, run the following command on your instance:

 rm /etc/udev/rules.d/70-persistent-net.rules

Add GPUs or modify GPU type on existing instances

This section covers how to add GPUs, or modify the GPU type on an existing N1general-purpose instance. This procedure supports the following GPUtypes:

NVIDIA GPUs:

  • NVIDIA T4:nvidia-tesla-t4
  • NVIDIA P4:nvidia-tesla-p4
  • NVIDIA P100:nvidia-tesla-p100
  • NVIDIA V100:nvidia-tesla-v100

NVIDIA RTX Virtual Workstation (vWS) (formerly known as NVIDIA GRID):

  • NVIDIA T4 Virtual Workstation:nvidia-tesla-t4-vws
  • NVIDIA P4 Virtual Workstation:nvidia-tesla-p4-vws
  • NVIDIA P100 Virtual Workstation:nvidia-tesla-p100-vws

    For these virtual workstations, an NVIDIA RTX Virtual Workstation (vWS) licenseis automatically added to your instance.

Console

To add GPUs or modify the GPU type, complete the following steps.

  1. Verify that all of your critical applications are stopped on theinstance.

  2. In the Google Cloud console, go to theVM instances page to see your listof instances.

    Go to VM instances

  3. Click the name of the instance that you want to update.TheDetails page opens.

  4. Complete the following steps from theDetails page.

    1. If the instance is running, clickStop. If there isnoStop option, clickMore actions >Stop.

    2. ClickEdit.

    3. In theMachine configuration section, select theGPUs machinefamily, and then do the following:

      1. In theGPU type list, select or switch to any of the GPUtypes supported on N1 VMs.

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

      3. If your GPU model supportsNVIDIA RTX Virtual Workstations (vWS) for graphics workloads,and you plan on running graphics-intensive workloads on this instance,selectEnable Virtual Workstation (NVIDIA GRID).

    4. If your instance didn't have GPUs attached before, complete the following:

      1. If the instance has a shared-core machine type, you must change themachine type. In theMachine type list, select one of thepreset N1 machine types. Alternatively, you can also specifycustom machine type settings.

      2. In theManagement section, complete the following:

        1. In theOn host maintenance list, selectTerminate VM instance.instances with attached GPUs can't live migrate. SeeHandle GPU host events.

        2. In theAutomatic restart list, selectOn.

    5. To apply your changes, clickSave.

    6. To restart the VM, clickStart/Resume.

REST

You can add or modify GPUs on your instance by stopping the instance andchanging your instance's configuration through the API.

  1. Verify that all of your critical applications are stopped on the instanceand then create a POST command to stop the instance so it can move toa host system where GPUs are available.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/stop
  2. If your instance does not have any GPUs attached, complete the following steps:

    1. Identify the GPU type that you want to add to yourinstance. You can submit aGET request to list the GPU types that areavailable to your project in a specific zone.

      GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/acceleratorTypes
    2. If the instance has a shared-core machine type, you mustchange the machine typeto have one or more vCPUs. You cannot add accelerators to instances withshared-core machine types.

    3. Create a POST command to set the scheduling options for the instance.

      POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/setScheduling{"onHostMaintenance": "TERMINATE","automaticRestart": true}
  3. Create a POST request to add or modify the GPUs that are attached to yourinstance.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/setMachineResources    {     "guestAccelerators": [      {        "acceleratorCount":ACCELERATOR_COUNT,        "acceleratorType": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/acceleratorTypes/ACCELERATOR_TYPE"      }     ]    }
  4. Start the instance.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/start

    Replace the following:

    • PROJECT_ID: your project ID.
    • VM_NAME: the name of the instance that you want toadd GPUs to.
    • ZONE: the zone where the instance is located.
    • ACCELERATOR_COUNT: the number of GPUs that youwant attached to your instance. For a list of GPU limits based on themachine type of your instance, seeGPUs on Compute Engine.
    • ACCELERATOR_TYPE: theGPU model that you want to attach orswitch to.If you plan on running graphics-intensive workloads on this instance, use oneof thevirtual workstation models.

      Choose one of the following values:

      • NVIDIA GPUs:

        • NVIDIA T4:nvidia-tesla-t4
        • NVIDIA P4:nvidia-tesla-p4
        • NVIDIA P100:nvidia-tesla-p100
        • NVIDIA V100:nvidia-tesla-v100
      • NVIDIA RTX Virtual Workstation (vWS) (formerly known as NVIDIA GRID):

        • NVIDIA T4 Virtual Workstation:nvidia-tesla-t4-vws
        • NVIDIA P4 Virtual Workstation:nvidia-tesla-p4-vws
        • NVIDIA P100 Virtual Workstation:nvidia-tesla-p100-vws

        For these virtual workstations, an NVIDIA RTX Virtual Workstation (vWS)license is automatically added to your instance.

Install drivers

To install the drivers, choose one of the following options:

Remove GPUs

This section covers how to remove the following GPU types from anexisting N1 general-purpose instance.

NVIDIA GPUs:

  • NVIDIA T4:nvidia-tesla-t4
  • NVIDIA P4:nvidia-tesla-p4
  • NVIDIA P100:nvidia-tesla-p100
  • NVIDIA V100:nvidia-tesla-v100

NVIDIA RTX Virtual Workstation (vWS) (formerly known as NVIDIA GRID):

  • NVIDIA T4 Virtual Workstation:nvidia-tesla-t4-vws
  • NVIDIA P4 Virtual Workstation:nvidia-tesla-p4-vws
  • NVIDIA P100 Virtual Workstation:nvidia-tesla-p100-vws

    For these virtual workstations, an NVIDIA RTX Virtual Workstation (vWS) licenseis automatically added to your instance.

You can use theGoogle Cloud console to remove GPUs from an existing instance. To removeGPUs, complete the following steps:

  1. Verify that all of your critical applications are stopped on theinstance.

  2. In the Google Cloud console, go to theVM instances page to see your list ofinstances.

    Go to VM instances

  3. Click the name of the instance that you want to remove GPUs from.TheDetails page opens.

  4. Complete the following steps from theDetails page.

    1. If the instance is running, clickStopto stop the instance. If there is noStop option, clickMore actions >Stop.

    2. On the toolbar, clickEdit.

    3. In theMachine configuration section, select theGeneral purpose machine family, and then do the following:

      1. To view attached GPUs, expandAdvanced configurations.

      2. In theGPUs section, remove GPUs using one of thefollowing options:

        • To remove some GPUs, in theNumber of GPUs list,select a new number.

        • To remove all GPUs, clickDelete GPU.

    4. Optional: Modify the instance host maintenance policy setting.instances with GPUs must have the host maintenance policy set toTerminate VM instance. But if you removed all GPUs, you have theoption to live migrate this instance during host maintenance.For more information, seeSet VM host maintenance policy.

    5. To apply your changes, clickSave.

    6. To restart the instance, clickStart/Resume.

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.