When you pin a job to a specific machine type using the [`workerMachineType` pipeline option](https://docs.cloud.google.com/dataflow/docs/guides/configure-worker-vm.md.txt#machine-type), you risk experiencing delays or job failures due to resource stockouts. Auto VM Selection addresses this problem by automatically choosing workers from a pool of compatible and available machine types using Compute Engine [instance flexibility](https://docs.cloud.google.com/compute/docs/instance-groups/about-instance-flexibility.md.txt). This helps to ensure that your Dataflow pipelines acquire capacity reliably, helping you maintain consistent performance and avoid interruptions.

## Unsupported configurations

Auto VM Selection is turned off if your pipeline is configured with any of the following:

- [Dataflow Prime](https://docs.cloud.google.com/dataflow/docs/guides/enable-dataflow-prime.md.txt) is enabled.
- The `min_cpu_platform` pipeline option is set.
- [Hyperdisk Balanced](https://docs.cloud.google.com/compute/docs/disks/hd-types/hyperdisk-balanced.md.txt) disks or custom provisioned performance (IOPS and throughput) are used. Jobs started with these configurations will fail.
- [Confidential VM](https://docs.cloud.google.com/confidential-computing/confidential-vm/docs/about-cvm) is enabled.
- Accelerators (GPUs or TPUs) are required.
- Jobs that don't use Dataflow Shuffle or Streaming Engine.

> [!NOTE]
> **Note:** To ensure maximum compatibility and allow the use of newer machine generations, don't specify a disk type when using Auto VM Selection.

## Enable Auto VM Selection

Auto VM Selection is enabled automatically in any of the following scenarios:

- If you set `min_ram` or `cpu_count` [resource hints](https://docs.cloud.google.com/dataflow/docs/guides/right-fitting.md.txt) for pipeline steps that don't require accelerators (GPUs or TPUs). For information about how to use resource hints with template-based jobs, see [Pipeline resource hints](https://docs.cloud.google.com/dataflow/docs/guides/right-fitting.md.txt#pipeline_resource_hints).

## Auto VM Selection behavior

Configure `min_ram` and `cpu_count` resource hints either in isolation or in combination. For example:

1. A job with only `cpu_count=2` may provision instances with `n4-standard-2` (2 vCPUs, 8 GB RAM), `c4-standard-2` (2 vCPUs, 7 GB RAM) and other machine types.
2. A job with both `cpu_count=4` and `min_ram=16GB` may provision instances with `n4-standard-4` (4 vCPUs, 16 GB RAM), `c4-highmem-4` (4 vCPUs, 31 GB RAM) and other machine types.

Auto VM Selection optimizes VM selection for resource obtainability. This means that you might experience reduced performance while using Auto VM Selection to improve the obtainability of some of your highly-tuned jobs. We recommend that you test Auto VM Selection on a subset of your existing jobs before gradually deploying them more broadly. For more information about obtainability, see [Improve resource obtainability for jobs](https://docs.cloud.google.com/batch/docs/improve-obtainability-overview.md.txt) in the Batch documentation.

Dataflow attempts to use 4th generation machine families first (for example, N4 or C4) to offer better efficiency. If 4th generation machines are unavailable in your region, lack sufficient quota, or are incompatible with your configurations, Dataflow automatically falls back to widely available 2nd generation machine families (for example, N2 or E2) to ensure your job can start without capacity delays.

By default, Dataflow chooses one machine generation for the
entire worker pool when the job starts, and the worker pool can't switch
generations later. To let a batch job use multiple generations in the same
worker pool, see [Cross-generation Auto VM Selection](https://docs.cloud.google.com/dataflow/docs/guides/auto-vm-selection.md.txt#cross-generation).

If you specify a disk type such as `pd-ssd` or `pd-standard` when enabling Auto VM Selection using resource hints (right fitting), Dataflow only provisions compatible 2nd generation machine families. To ensure maximum compatibility and allow the use of newer machine generations, don't assign a disk type.

## View selected machine types

Because Auto VM Selection chooses machine types when it creates worker VMs, the
workers of a job can use different machine types. To see which machine types
your jobs use, query worker VM metrics with the Cloud Monitoring API.
Cloud Monitoring records the machine type of each worker VM in the
`machine_type` system metadata label. Dataflow adds a
`dataflow_job_id` label to each worker VM.

To run the following command, you need the Google Cloud CLI and curl. To get the
permission that you need to query metrics, ask your administrator to grant you
the
[Monitoring Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/monitoring.md.txt#monitoring.viewer)
(`roles/monitoring.viewer`) role on the project.

The following command lists the machine types that the workers of a
Dataflow job used. The command calls the
[`projects.timeSeries.list`](https://docs.cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list.md.txt)
method and formats the response as a table by using only built-in shell
commands:

```bash
PROJECT_ID="PROJECT_ID"
JOB_ID="JOB_ID"
START_TIME="${JOB_ID%%_*}T00:00:00Z"
END_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"

TOKEN="$(gcloud auth print-access-token)" &&
RESPONSE="$(curl -fsS --get \
    "https://monitoring.googleapis.com/v3/projects/${PROJECT_ID}/timeSeries" \
    -H "Authorization: Bearer ${TOKEN}" \
    --data-urlencode "filter=metric.type=\"compute.googleapis.com/instance/cpu/utilization\" resource.type=\"gce_instance\" metadata.user_labels.\"dataflow_job_id\"=\"${JOB_ID}\"" \
    --data-urlencode "interval.startTime=${START_TIME}" \
    --data-urlencode "interval.endTime=${END_TIME}" \
    --data-urlencode "aggregation.alignmentPeriod=60s" \
    --data-urlencode "aggregation.perSeriesAligner=ALIGN_MEAN" \
    --data-urlencode "aggregation.crossSeriesReducer=REDUCE_COUNT" \
    --data-urlencode 'aggregation.groupByFields=metadata.system_labels."machine_type"' \
    --data-urlencode "view=FULL" \
    --data-urlencode "prettyPrint=true" \
    --data-urlencode "fields=timeSeries.metadata,timeSeries.points.value,nextPageToken")" &&
printf '%s\n' "$RESPONSE" | {
  printf '%-22s%s\n' MACHINE_TYPE PEAK_INSTANCES
  type= peak=0
  while IFS= read -r line; do
    case $line in
      *'"int64Value": "'*)
        v=${line#*'"int64Value": "'}; v=${v%%'"'*}
        [ "$v" -gt "$peak" ] && peak=$v ;;
      *'"machine_type": "'*)
        type=${line#*'"machine_type": "'}; type=${type%%'"'*} ;;
      '    }' | '    },')
        [ -n "$type" ] && printf '%-22s%s\n' "$type" "$peak"
        type= peak=0 ;;
      *'"nextPageToken":'*)
        printf 'Warning: output is incomplete; use a shorter time range.\n' >&2 ;;
    esac
  done
}
```

Replace the following:

- `PROJECT_ID`: the ID of the project that runs the job
- `JOB_ID`: the ID of the Dataflow job

The output has a row for each machine type that the job's workers used. The
`PEAK_INSTANCES` column shows the maximum number of workers of that machine type
that ran at the same time. The output is similar to the following:

    MACHINE_TYPE          PEAK_INSTANCES
    c4-standard-2         1
    n4-standard-2         4

The command counts the job's VMs of each machine type in each minute, based on
the `compute.googleapis.com/instance/cpu/utilization` metric, which every
running VM reports. Metric data can take up to 4 minutes to appear in
Monitoring, and the command might not count VMs that run for less
than 1 minute.

A job ID starts with the job's creation date in Pacific Time. By default,
`START_TIME` is midnight UTC on that date, which is always before the job
started, and `END_TIME` is the current time. To query a different time range,
set `START_TIME` and `END_TIME` to UTC timestamps in RFC 3339 format. For
example, `START_TIME="2026-11-04T18:00:00Z"` and
`END_TIME="2026-11-05T18:00:00Z"`.

If the command prints a warning that the output is incomplete, run the command
for shorter time ranges. This warning can appear for jobs that run for several
weeks.

Monitoring stores data that's older than 6 weeks at 10-minute
intervals. To query that data, change `aggregation.alignmentPeriod` to `600s`.

## Limitations

When using Auto VM Selection, [Portable Runner container image updates](https://docs.cloud.google.com/dataflow/docs/guides/common-errors.md.txt#portable_runner_harness_update) are disabled for streaming jobs that use the [Portable Runner](https://docs.cloud.google.com/dataflow/docs/portable-runner.md.txt).

## Compute Engine reservations

If you use Compute Engine reservations with Auto VM Selection, note the following:

- If you have reservations configured to be [consumed automatically](https://docs.cloud.google.com/compute/docs/instances/reservations-consume.md.txt#auto-reservations), they might be used if Auto VM Selection provisions machine types that match the reservation.
- Auto VM Selection consumes compute instances as they are available. Consequently, you can't specify that the service [consume instances from a specific reservation](https://docs.cloud.google.com/compute/docs/instances/reservations-consume.md.txt#consuming_instances_from_a_specific_reservation).

## Cross-generation Auto VM Selection

> [!WARNING]
>
> **Preview
> --- Cross-generation Auto VM Selection**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

Cross-generation Auto VM Selection lets batch jobs use capacity from 4th
generation and 2nd generation Compute Engine machines in the same worker
pool. Dataflow prioritizes 4th generation machines and uses 2nd
generation machines when 4th generation machines are unavailable (or have
insufficient quota).

### Requirements and limitations

Cross-generation Auto VM Selection has the following requirements and
limitations:

- **Batch jobs only:** Streaming jobs aren't supported. If you enable cross-generation Auto VM Selection for a streaming job, the job will be rejected by Dataflow.
- **Auto VM Selection required:** The job must use Auto VM Selection. If Auto VM Selection is turned off for the job, for example because you set a worker machine type or use one of the [unsupported configurations](https://docs.cloud.google.com/dataflow/docs/guides/auto-vm-selection.md.txt#unsupported-configurations), the job can't use cross-generation Auto VM Selection.
- **No worker disk type:** Don't set the `workerDiskType` (Java), `worker_disk_type` (Python), or `disk_type` (Go) pipeline option. If you set the `pd-standard` or `pd-ssd` disk type, Dataflow uses only 2nd generation machines. If you set the `hyperdisk-balanced` disk type, the job fails shortly after launch because Hyperdisk Balanced disks aren't compatible with Auto VM Selection.
- **4th generation availability:** Your job can only use 4th generation machines if they're [offered in the job's region](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt), they aren't stocked out, and your project has sufficient [quota](https://docs.cloud.google.com/compute/resource-usage.md.txt#cpu_quota) for them.
- **Autoscaling with heterogeneous workers:** When a job uses both 4th generation and 2nd generation machines, worker performance can vary significantly, which could affect autoscaling responsiveness. We recommend that you verify the performance of your pipeline with Cross-generation Auto VM Selection before you use it in production.

### Pricing

When a job runs 4th generation and 2nd generation workers at the same time,
Dataflow bills the boot disk of each worker according to the disk
type that the worker uses:

- 4th generation workers are billed for Hyperdisk Balanced disks.
- 2nd generation workers are billed for Standard Persistent Disk disks.

As a result, the billing data for a single job can include both Persistent Disk
and Hyperdisk Balanced SKUs. The proportion of each disk type depends on how many workers
of each generation the job uses and how long they run. For more information,
see [Dataflow pricing](https://docs.cloud.google.com/dataflow/pricing).

### Enable cross-generation Auto VM Selection

To enable cross-generation Auto VM Selection, do the following when you launch
a new batch job:

1. Make sure that the job uses Auto VM Selection. For example, set `min_ram` or `cpu_count` [resource hints](https://docs.cloud.google.com/dataflow/docs/guides/right-fitting.md.txt), and don't set a worker machine type or a worker disk type.
2. Set the `enable_cross_gen_auto_vm`
   [service option](https://docs.cloud.google.com/dataflow/docs/reference/service-options.md.txt).

   ### Java

       --dataflowServiceOptions=enable_cross_gen_auto_vm

   ### Python

       --dataflow_service_options=enable_cross_gen_auto_vm

   ### Go

       --dataflow_service_options=enable_cross_gen_auto_vm

   ### gcloud

   When you run a template using the
   [`gcloud dataflow jobs run`](https://docs.cloud.google.com/sdk/gcloud/reference/dataflow/jobs/run.md.txt)
   command or a Flex Template using the
   [`gcloud dataflow flex-template run`](https://docs.cloud.google.com/sdk/gcloud/reference/dataflow/flex-template/run.md.txt)
   command, include the `--additional-experiments` flag:

       --additional-experiments=enable_cross_gen_auto_vm

When Dataflow must use 2nd generation machines, the job logs
might show resource availability errors or quota errors for 4th generation
machine types. These errors are expected and don't indicate a problem with the
job. To confirm that the job is still getting workers, check the
[Autoscaling section](https://docs.cloud.google.com/dataflow/docs/guides/using-monitoring-intf.md.txt#autoscaling)
of the **Job metrics** tab. If the number of workers keeps up with the target
number of workers, you can ignore these errors.

### Disable cross-generation Auto VM Selection

Dataflow might enable cross-generation Auto VM Selection for
some batch jobs that use Auto VM Selection, even if you don't set the
`enable_cross_gen_auto_vm` service option. To prevent a batch job from using
cross-generation Auto VM Selection, set the `enable_cross_gen_auto_vm` service
option to `false` when you launch the job:

### Java

    --dataflowServiceOptions=enable_cross_gen_auto_vm=false

### Python

    --dataflow_service_options=enable_cross_gen_auto_vm=false

### Go

    --dataflow_service_options=enable_cross_gen_auto_vm=false

### gcloud

When you run a template using the
[`gcloud dataflow jobs run`](https://docs.cloud.google.com/sdk/gcloud/reference/dataflow/jobs/run.md.txt)
command or a Flex Template using the
[`gcloud dataflow flex-template run`](https://docs.cloud.google.com/sdk/gcloud/reference/dataflow/flex-template/run.md.txt)
command, include the `--additional-experiments` flag:

    --additional-experiments=enable_cross_gen_auto_vm=false

When cross-generation Auto VM Selection is disabled, Dataflow
chooses one machine generation for the entire worker pool when the job starts,
as described in [Auto VM Selection behavior](https://docs.cloud.google.com/dataflow/docs/guides/auto-vm-selection.md.txt#behavior).

## Known issues

When using Auto VM Selection, be aware of the following known issues:

### Unexpected parallelism

If you observe low CPU utilization or unexpected parallelism on worker VMs when
using Auto VM Selection with right fitting, check the following settings.

#### Horizontal Autoscaling

If you disable Horizontal Autoscaling, your job might run with lower parallelism
than expected. To avoid this issue, keep Horizontal Autoscaling enabled. For
more information, see
[Right fitting support and limitations](https://docs.cloud.google.com/dataflow/docs/guides/right-fitting.md.txt#limitations_and_requirements).

#### Worker harness threads

By default, Dataflow sets the number of threads per worker based
on the vCPU count of the selected machine type. If you still observe low CPU
utilization or unexpected parallelism, you can override the default by setting
the `numberOfWorkerHarnessThreads` or `number_of_worker_harness_threads`
[pipeline option](https://docs.cloud.google.com/dataflow/docs/reference/pipeline-options.md.txt#resource_utilization).
This option applies globally to all worker pools in the pipeline.