Stay organized with collections Save and categorize content based on your preferences.
Linux Windows
This document explains how to create a VM that has attached GPUs and uses an N1 machine family. You can use most N1 machine types except the N1 shared-core
.
Select the tab for how you plan to use the samples on this page:
ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloudInstall the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
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
.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:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
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 permissionsThe following permissions are required to create VMs:
compute.instances.create
on the project compute.images.useReadOnly
on the image compute.snapshots.useReadOnly
on the snapshot compute.instanceTemplates.useReadOnly
on the instance template compute.networks.use
on the project compute.addresses.use
on the project compute.networks.useExternalIp
on the project compute.subnetworks.use
on the project or on the chosen subnet compute.subnetworks.useExternalIp
on the project or on the chosen subnet compute.instances.setMetadata
on the project compute.instances.setTags
on the VM compute.instances.setLabels
on the VM compute.instances.setServiceAccount
on the VM compute.disks.create
on the project compute.disks.use
on the disk compute.disks.useReadOnly
on the diskYou might also be able to get these permissions with custom roles or other predefined roles.
OverviewThe following GPU models can be attached to VMs that use N1 machine families.
NVIDIA GPUs:
nvidia-tesla-t4
nvidia-tesla-p4
nvidia-tesla-p100
nvidia-tesla-v100
NVIDIA RTX Virtual Workstation (vWS) (formerly known as NVIDIA GRID):
nvidia-tesla-t4-vws
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.
You can create an N1 VM that has attached GPUs by using either the Google Cloud console, Google Cloud CLI, or REST.
ConsoleIn the Google Cloud console, go to the Create an instance page.
Specify a Name for your VM. See Resource naming convention.
Select a region and zone where GPUs are available. See the list of available GPU zones.
In the Machine configuration section, select the GPUs machine family, and then do the following:
If your GPU model supports NVIDIA RTX Virtual Workstations (vWS) for graphics workloads, and you plan on running graphics-intensive workloads on this VM, select Enable Virtual Workstation (NVIDIA GRID).
In the Machine type list, select one of the preset N1 machine types. Alternatively, you can also specify custom machine type settings.
In the Boot disk section, click Change. This opens the Boot disk configuration page.
On the Boot disk configuration page, do the following:
Optional: In the VM provisioning model list, select a provisioning model.
To create and start the VM, click Create.
To create and start a VM use the gcloud compute instances create
command with the following flags.
If your workload is fault-tolerant and can withstand possible VM preemption, consider using Spot VMs to reduce the cost of your VMs and the attached GPUs. For more information, see GPUs on Spot VMs. The --provisioning-model=SPOT
is an optional flag that configures your VMs as Spot VMs. For Spot VMs, the automatic restart and host maintenance options flags are disabled.
gcloud compute instances create VM_NAME \ --machine-type MACHINE_TYPE \ --zone ZONE \ --boot-disk-size DISK_SIZE \ --accelerator type=ACCELERATOR_TYPE,count=ACCELERATOR_COUNT \ [--image IMAGE | --image-family IMAGE_FAMILY] \ --image-project IMAGE_PROJECT \ --maintenance-policy TERMINATE \ [--provisioning-model=SPOT]
Replace the following:
VM_NAME
: the name for the new VM.MACHINE_TYPE
: the machine type that you selected for your VM.ZONE
: the zone for the VM. This zone must support the GPU type.DISK_SIZE
: the size of your boot disk in GB. Specify a boot disk size of at least 40 GB.IMAGE
or IMAGE_FAMILY
that supports GPUs. Specify one of the following:
IMAGE
: the required version of a public image. For example, --image debian-10-buster-v20200309
.IMAGE_FAMILY
: an image family. This creates the VM from the most recent, non-deprecated OS image. For example, if you specify --image-family debian-10
, Compute Engine creates a VM from the latest version of the OS image in the Debian 10 image family.You can also specify a custom image or Deep Learning VM Images.
IMAGE_PROJECT
: the Compute Engine image project that the image family belongs to. If using a custom image or Deep Learning VM Images, specify the project that those images belong to.
ACCELERATOR_COUNT
: the number of GPUs that you want to add to your VM. See GPUs on Compute Engine for a list of GPU limits based on the machine type of your VM.
ACCELERATOR_TYPE
: the GPU model that you want to use. If you plan on running graphics-intensive workloads on this VM, use one of the virtual workstation models.
Choose one of the following values:
NVIDIA GPUs:
nvidia-tesla-t4
nvidia-tesla-p4
nvidia-tesla-p100
nvidia-tesla-v100
NVIDIA RTX Virtual Workstation (vWS) (formerly known as NVIDIA GRID):
nvidia-tesla-t4-vws
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.
Example
For example, you can use the following gcloud
command to start an Ubuntu 22.04 VM with 1 NVIDIA T4 GPU and 2 vCPUs in the us-east1-d
zone.
gcloud compute instances create gpu-instance-1 \ --machine-type n1-standard-2 \ --zone us-east1-d \ --boot-disk-size 40GB \ --accelerator type=nvidia-tesla-t4,count=1 \ --image-family ubuntu-2204-lts \ --image-project ubuntu-os-cloud \ --maintenance-policy TERMINATEREST
Identify the GPU type that you want to add to your VM. Submit a GET request to list the GPU types that are available to your project in a specific zone.
If your workload is fault-tolerant and can withstand possible VM preemption, consider using Spot VMs to reduce the cost of your VMs and the attached GPUs. For more information, see GPUs on Spot VMs. The "provisioningModel": "SPOT"
is an optional parameter that configures your VMs as Spot VMs. For Spot VMs, the automatic restart and host maintenance options flags are disabled.
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/acceleratorTypes
Replace the following:
PROJECT_ID
: project ID.ZONE
: zone from which you want to list the available GPU types.Send a POST request to the instances.insert
method. Include the acceleratorType
parameter to specify which GPU type you want to use, and include the acceleratorCount
parameter to specify how many GPUs you want to add. Also set the onHostMaintenance
parameter to TERMINATE
.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances { "machineType": "projects/PROJECT_ID/zones/ZONE/machineTypes/MACHINE_TYPE", "disks": [ { "type": "PERSISTENT", "initializeParams": { "diskSizeGb": "DISK_SIZE", "sourceImage": "projects/IMAGE_PROJECT/global/images/family/IMAGE_FAMILY" }, "boot": true } ], "name": "VM_NAME", "networkInterfaces": [ { "network": "projects/PROJECT_ID/global/networks/NETWORK" } ], "guestAccelerators": [ { "acceleratorCount": ACCELERATOR_COUNT, "acceleratorType": "projects/PROJECT_ID/zones/ZONE/acceleratorTypes/ACCELERATOR_TYPE" } ], "scheduling": { ["automaticRestart": true], "onHostMaintenance": "TERMINATE", ["provisioningModel": "SPOT"] }, }
Replace the following:
VM_NAME
: the name of the VM.PROJECT_ID
: your project ID.ZONE
: the zone for the VM. This zone must support the GPU type.MACHINE_TYPE
: the machine type that you selected for the VM. See GPUs on Compute Engine to see what machine types are available based on your desired GPU count.IMAGE
or IMAGE_FAMILY
: specify one of the following:
IMAGE
: the required version of a public image. For example, "sourceImage": "projects/debian-cloud/global/images/debian-10-buster-v20200309"
IMAGE_FAMILY
: an image family. This creates the VM from the most recent, non-deprecated OS image. For example, if you specify "sourceImage": "projects/debian-cloud/global/images/family/debian-10"
, Compute Engine creates a VM from the latest version of the OS image in the Debian 10 image family.You can also specify a custom image or Deep Learning VM Images.
IMAGE_PROJECT
: the Compute Engine image project that the image family belongs to. If using a custom image or Deep Learning VM Images, specify the project that those images belong to.
DISK_SIZE
: the size of your boot disk in GB. Specify a boot disk size of at least 40 GB.
NETWORK
: the VPCnetwork that you want to use for the VM. You can specify default
to use your default network.
ACCELERATOR_COUNT
: the number of GPUs that you want to add to your VM. See GPUs on Compute Engine for a list of GPU limits based on the machine type of your VM.
ACCELERATOR_TYPE
: the GPU model that you want to use. If you plan on running graphics-intensive workloads on this VM, use one of the virtual workstation models.
Choose one of the following values:
NVIDIA GPUs:
nvidia-tesla-t4
nvidia-tesla-p4
nvidia-tesla-p100
nvidia-tesla-v100
NVIDIA RTX Virtual Workstation (vWS) (formerly known as NVIDIA GRID):
nvidia-tesla-t4-vws
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.
To install the drivers, choose one of the following options:
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This guide outlines how to create a virtual machine (VM) with attached GPUs using N1 machine families, excluding N1 shared-core."],["You can create these VMs using the Google Cloud console, the Google Cloud CLI (`gcloud`), or REST API, which can be done through authentication set up beforehand."],["The process involves selecting a supported GPU model (such as NVIDIA T4, P4, P100, V100, or RTX Virtual Workstation models), choosing a machine type, and configuring a boot disk with at least 40GB of space."],["It is possible to use spot VMs to reduce costs if the workload is fault-tolerant, and it is possible to install different types of drivers depending on the workload."],["Required permissions to create VMs are outlined, which include creating instances, using images and snapshots, specifying IP addresses and subnets, and setting metadata, labels, tags, service accounts, and disks."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4