Create a Flex-start VM (original) (raw)

This document explains how to create a Flex-start virtual machine (VM) instance. Flex-start VMs run for up to seven days and help you acquire high-demand resources like GPUs at a discounted price. These features make Flex-start VMs a cost-effective solution for running short-duration workloads, such as model fine-tuning and batch inference.

To learn more about the key characteristics of Flex-start VMs, including the requirements and limitations that you apply when you create them, seeAbout Flex-start VMs.

Before you begin

Required roles

To get the permissions that you need to create a standalone Flex-start VM, ask your administrator to grant you theCompute 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 a standalone Flex-start VM. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create a standalone Flex-start VM:

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

If you want to create a Flex-start VM that uses a machine type other than A2, G4, G2, or N1, then see the following:

To create an A2 or G2 Flex-start VM that specifies acompact placement policyfor minimal network latency, use the gcloud CLI or REST API. Otherwise, select one of the following options:

Console

  1. In the Google Cloud console, go to the Create an instance page.
    Go to Create an instance
  2. In the Machine configuration pane, complete the following steps:
    1. In the Name field, enter a name for the Flex-start VM.
    2. Specify the Region and Zone where you want to create your VM. To review the regions and zones where the machine type that you want to use is available, seeAvailable regions and zones.
    3. Based on the workload that you want to run, specify a machine type as follows:
      • To specify an accelerator-optimized machine type, do the following:
        1. Click the GPUs tab.
        2. In the GPU type list, select a GPU type, exceptNVIDIA GB200 192GB.
        3. In the Number of GPUs list, select the number of GPUs to attach to your VM.
        4. Optional: If your GPU model supportsNVIDIA RTX Virtual Workstations (vWS) for graphics workloads, and you plan to run graphics-intensive workloads, selectEnable Virtual Workstation (NVIDIA GRID).
      • To specify an H4D machine type, do the following:
        1. Click the Compute optimized tab.
        2. In the Series column, select H4D.
  3. In the navigation menu, click Advanced. In the Advanced pane that appears, complete the following steps:
    1. In the Provisioning model section, in theVM provisioning model list, select Flex-start.
    2. In the Enter number of hours field, enter the maximum amount of time that you want the VM to run. The value must be between 0.01(0.01 hours, or 36 seconds) or 168 (168 hours, or seven days).
    3. Select the Set a wait time for VM creation checkbox. Then, based on the zonal requirements for your workload, specify one of the following durations to help increase the chances that your VM creation request succeeds:
      • If your workload requires you to create the VM in a specific zone, then specify a duration between 90 seconds and2 hours. Longer durations give you higher chances of obtaining resources.
      • If the VM can run in any zone within the region, then specify a duration of 0 seconds or clear theSet a wait time for VM creation checkbox. This action specifies that Compute Engine only allocates resources if they are immediately available. If the VM creation request fails because resources are unavailable, then retry the request in a different zone.
    4. In the On VM termination field, select whether to stop or delete the Flex-start VM at the end of its run duration:
      • To delete the VM, select Delete.
      • To stop the VM, select Stop.
  4. To create the Flex-start VM, click Create.

gcloud

To create an A2, G4, G2, or N1 Flex-start VM, use thegcloud compute instances create commandwith the following flags:

To create a Flex-start VM, run the following command:

gcloud compute instances create VM_NAME \
    --machine-type=MACHINE_TYPE \
    --zone=ZONE \
    --request-valid-for-duration=VALID_FOR_DURATION \
    --provisioning-model=FLEX_START \
    --instance-termination-action=TERMINATION_ACTION \
    --max-run-duration=RUN_DURATION \
    --maintenance-policy=TERMINATE \
    --reservation-affinity=none

Replace the following:

If you want to apply a compact placement policy to an A2 or G2 Flex-start VM, then include the --resource-policies flag in the command:

gcloud compute instances create VM_NAME \
    --machine-type=MACHINE_TYPE \
    --zone=ZONE \
    --request-valid-for-duration=VALID_FOR_DURATION \
    --provisioning-model=FLEX_START \
    --instance-termination-action=TERMINATION_ACTION \
    --max-run-duration=RUN_DURATION \
    --maintenance-policy=TERMINATE \
    --reservation-affinity=none \
    --resource-policies=POLICY_NAME

Replace POLICY_NAME with the name of an existing compact placement policy. You can only create your Flex-start VM in the same region as the placement policy.

REST

To create an A2, G4, G2, or N1 Flex-start VM, make a POSTrequest to theinstances.insert method. In the request body, include the following fields:

To create a Flex-start VM, make a POST request as follows:

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

{
  "name": "VM_NAME",
  "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
  "disks": [
    {
      "initializeParams": {
        "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
      },
      "boot": true
    }
  ],
  "networkInterfaces": [
    {
      "network": "global/networks/default"
    }
  ],
  "params": {
    "requestValidForDuration": {
      "seconds": VALID_FOR_DURATION
    }
  },
  "scheduling": {
    "provisioningModel": "FLEX_START",
    "instanceTerminationAction": "TERMINATION_ACTION",
    "maxRunDuration": {
      "seconds": RUN_DURATION
    },
    "onHostMaintenance": "TERMINATE"
  },
  "reservationAffinity": {
    "consumeReservationType": "NO_RESERVATION"
  }
}

Replace the following:

If you want to apply a compact placement policy to an A2 or G2 Flex-start VM, then include the resourcePolicies field in the request:

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

{
  "name": "VM_NAME",
  "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
  "disks": [
    {
      "initializeParams": {
        "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
      },
      "boot": true
    }
  ],
  "networkInterfaces": [
    {
      "network": "global/networks/default"
    }
  ],
  "params": {
    "requestValidForDuration": {
      "seconds": VALID_FOR_DURATION
    }
  },
  "scheduling": {
    "provisioningModel": "FLEX_START",
    "instanceTerminationAction": "TERMINATION_ACTION",
    "maxRunDuration": {
      "seconds": RUN_DURATION
    },
    "onHostMaintenance": "TERMINATE"
  },
  "reservationAffinity": {
    "consumeReservationType": "NO_RESERVATION"
  },
  "resourcePolicies": [
    "projects/PROJECT_ID/regions/REGION/resourcePolicies/POLICY_NAME"
  ]
}

Replace the following:

What's next

Try it for yourself

If you're new to Google Cloud, create an account to evaluate how Compute Engine performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.

Try Compute Engine free