Add or remove GPUs Stay organized with collections Save and categorize content based on your preferences.
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
- To review additional prerequisite steps such as selecting an OS image and checking GPU quota, review theoverview document.
- 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.
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.
Accelerator-optimized VMs
Each accelerator-optimized machine type has a specific model of NVIDIA GPUsattached to support the recommended workload type.
| AI and ML workloads | Graphics 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. |
|
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.
Verify that all of your critical applications are stopped on theinstance.
In the Google Cloud console, go to theVM instances page to see your listof instances.
Click the name of the instance that you want to modify the number of GPUs for.TheDetails page opens.
Complete the following steps from theDetails page.
If the instance is running, clickStopto stop the instance. If there is noStop option, clickMore actions >Stop.
ClickEdit.
In theMachine configuration section, select theGPUs machinefamily, and then do the following:
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.
To apply your changes, clickSave.
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.
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
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"}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 to add GPUs to.ZONE: the zone where the instance is located. This zone must supportGPUs.MACHINE_TYPE: the machine type that you want to use. It must be one of the following:- If your instance uses an A2 standard machine, select anotherA2 Standard machine type.
- If your instance uses a G4 machine, select anotherG4 machine type.
- If your instance uses a G2 machine type, select anotherG2 machine type.G2 machine types also support custom memory. Memory must be amultiple of 1024 MB and within the supported memory range. Forexample, the machine type name for an instance with 4 vCPUs and 19 GBof memory would be
g2-custom-4-19456.
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 the
a2-megagpu-16gmachine 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 specifying
format 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 version
525.60.13or 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.
- Use a Container-Optimized OS version that supports the minimum recommended NVIDIA driver version
- 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
- You can only request capacity by using thesupported consumption optionsfor a G4 machine type.
- You don't receivesustaineduse discounts andflexible committed usediscounts for instances that use a G4 machine type.
- You can only use a G4 machine type in certainregionsand zones.
- You can't usePersistent Disk (regional or zonal)on an instance that uses a G4 machine type.
- The G4 machine type is only available on theAMD EPYC Turin 5th Generation platform.
- You can't create Confidential VM instances that use a G4 machine type.
- You can't create G4 instances on sole-tenant nodes.
- You can't use Windows operating systems on
g4-standard-384instances.
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:
- Check that your instance has a boot disk size of at least 40 GB.
- Stop the instance.
Add, modify, or remove the GPUs.
If your N1 instance doesn't have any GPUs attached, you need to complete thefollowing steps:
- Prepare your instance for the modification.
- 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.
- Change the machine type. GPUs are only supported onselect N1 machine types.
- 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-vwsFor 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.
Verify that all of your critical applications are stopped on theinstance.
In the Google Cloud console, go to theVM instances page to see your listof instances.
Click the name of the instance that you want to update.TheDetails page opens.
Complete the following steps from theDetails page.
If the instance is running, clickStop. If there isnoStop option, clickMore actions >Stop.
ClickEdit.
In theMachine configuration section, select theGPUs machinefamily, and then do the following:
In theGPU type list, select or switch to any of the GPUtypes supported on N1 VMs.
In theNumber of GPUs list, select the number of GPUs.
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).
If your instance didn't have GPUs attached before, complete the following:
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.
In theManagement section, complete the following:
In theOn host maintenance list, selectTerminate VM instance.instances with attached GPUs can't live migrate. SeeHandle GPU host events.
In theAutomatic restart list, selectOn.
To apply your changes, clickSave.
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.
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
If your instance does not have any GPUs attached, complete the following steps:
Identify the GPU type that you want to add to yourinstance. You can submit a
GETrequest 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
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.
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}
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" } ] }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 T4:
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.
- NVIDIA T4 Virtual Workstation:
Install drivers
To install the drivers, choose one of the following options:
- If you plan to run graphics-intensive workloads, such as those for gaming andvisualization,install drivers for the NVIDIA RTX Virtual Workstation.
- For most workloads,install the GPU drivers.
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-vwsFor 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:
Verify that all of your critical applications are stopped on theinstance.
In the Google Cloud console, go to theVM instances page to see your list ofinstances.
Click the name of the instance that you want to remove GPUs from.TheDetails page opens.
Complete the following steps from theDetails page.
If the instance is running, clickStopto stop the instance. If there is noStop option, clickMore actions >Stop.
On the toolbar, clickEdit.
In theMachine configuration section, select theGeneral purpose machine family, and then do the following:
To view attached GPUs, expandAdvanced configurations.
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.
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.
To apply your changes, clickSave.
To restart the instance, clickStart/Resume.
What's next?
- Learn more aboutGPU platforms.
- Add Local SSDs to your instances.Local SSD devices pair well with GPUs when your apps requirehigh-performance storage.
- Create groups of GPU instances using instance templates.
- To monitor GPU performance, seeMonitoring GPU performance.
- To improve network performance, seeUse higher network bandwidth.
- To handle GPU host maintenance, seeHandling GPU host events.
- Try theRunning TensorFlow Inference Workloads at Scale with TensorRT5and NVIDIA T4 GPU tutorial.
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.