設定 Gemini Enterprise Agent Platform 無伺服器訓練的運算資源

執行無伺服器訓練時,訓練程式碼會在一或多個虛擬機器 (VM) 執行個體上執行。您可以設定要用於訓練的 VM 類型:使用運算資源較多的 VM 可加快訓練速度,並處理較大的資料集,但也會產生較高的訓練費用。

在某些情況下,您也可以使用 GPU 加快訓練速度。GPU 會產生額外費用。

您也可以視需要自訂訓練 VM 開機磁碟的類型和大小。

本文說明可用於無伺服器訓練的不同運算資源,以及如何設定這些資源。

管理費用和可用性

為協助管理成本或確保 VM 資源可用性,Agent Platform 提供下列功能:

  • 為確保訓練工作需要時能取得 VM 資源,您可以使用 Compute Engine 預留項目。預留項目可確保您取得 Compute Engine 資源的容量。詳情請參閱「使用預留項目搭配訓練工作」。

  • 如要降低執行訓練工作的成本,可以使用 Spot VM。Spot VM 是虛擬機器 (VM) 執行個體,屬於 Compute Engine 的多餘容量。Spot VM 提供大幅折扣,但 Compute Engine 可能會隨時先占停止或刪除 Spot VM,以取回資源。詳情請參閱「使用 Spot VM 進行訓練」。

  • 如果無伺服器訓練工作要求 GPU 資源,Dynamic Workload Scheduler 可讓您根據要求的 GPU 資源何時可用,安排工作排程。詳情請參閱「根據資源可用性排定訓練工作」。

指定運算資源的位置

在 WorkerPoolSpec 中指定設定詳細資料。視您執行無伺服器訓練的方式而定,請將這個 WorkerPoolSpec 放入下列其中一個 API 欄位:

如果您要執行分散式訓練,可以為每個 worker 集區使用不同的設定。

機型

在 WorkerPoolSpec 中,您必須在 machineSpec.machineType 欄位中指定下列其中一種機型。worker 集區中的每個副本都會在具有指定機型的獨立 VM 上執行。

  • a4x-highgpu-4g*
  • a4-highgpu-8g*
  • a3-ultragpu-8g*
  • a3-megagpu-8g*
  • a3-highgpu-1g*
  • a3-highgpu-2g*
  • a3-highgpu-4g*
  • a3-highgpu-8g*
  • a2-ultragpu-1g*
  • a2-ultragpu-2g*
  • a2-ultragpu-4g*
  • a2-ultragpu-8g*
  • a2-highgpu-1g*
  • a2-highgpu-2g*
  • a2-highgpu-4g*
  • a2-highgpu-8g*
  • a2-megagpu-16g*
  • e2-standard-4
  • e2-standard-8
  • e2-standard-16
  • e2-standard-32
  • e2-highmem-2
  • e2-highmem-4
  • e2-highmem-8
  • e2-highmem-16
  • e2-highcpu-16
  • e2-highcpu-32
  • n4-standard-2
  • n4-standard-4
  • n4-standard-8
  • n4-standard-16
  • n4-standard-32
  • n4-standard-48
  • n4-standard-64
  • n4-standard-80
  • n4-highmem-2
  • n4-highmem-4
  • n4-highmem-8
  • n4-highmem-16
  • n4-highmem-32
  • n4-highmem-48
  • n4-highmem-64
  • n4-highmem-80
  • n4-highcpu-2
  • n4-highcpu-4
  • n4-highcpu-8
  • n4-highcpu-16
  • n4-highcpu-32
  • n4-highcpu-48
  • n4-highcpu-64
  • n4-highcpu-80
  • n4d-standard-4†
  • n4d-standard-8†
  • n4d-standard-16†
  • n4d-standard-32†
  • n4d-standard-48†
  • n4d-standard-64†
  • n4d-standard-80†
  • n4d-standard-96†
  • n4d-highmem-2†
  • n4d-highmem-4†
  • n4d-highmem-8†
  • n4d-highmem-16†
  • n4d-highmem-32†
  • n4d-highmem-48†
  • n4d-highmem-64†
  • n4d-highmem-80†
  • n4d-highmem-96†
  • n4d-highcpu-8†
  • n4d-highcpu-16†
  • n4d-highcpu-32†
  • n4d-highcpu-48†
  • n4d-highcpu-64†
  • n4d-highcpu-80†
  • n4d-highcpu-96†
  • n2-standard-4
  • n2-standard-8
  • n2-standard-16
  • n2-standard-32
  • n2-standard-48
  • n2-standard-64
  • n2-standard-80
  • n2-highmem-2
  • n2-highmem-4
  • n2-highmem-8
  • n2-highmem-16
  • n2-highmem-32
  • n2-highmem-48
  • n2-highmem-64
  • n2-highmem-80
  • n2-highcpu-16
  • n2-highcpu-32
  • n2-highcpu-48
  • n2-highcpu-64
  • n2-highcpu-80
  • n2d-standard-4†
  • n2d-standard-8†
  • n2d-standard-16†
  • n2d-standard-32†
  • n2d-standard-48†
  • n2d-standard-64†
  • n2d-standard-80†
  • n2d-standard-96†
  • n2d-standard-128†
  • n2d-standard-224†
  • n2d-highmem-2†
  • n2d-highmem-4†
  • n2d-highmem-8†
  • n2d-highmem-16†
  • n2d-highmem-32†
  • n2d-highmem-48†
  • n2d-highmem-64†
  • n2d-highmem-80†
  • n2d-highmem-96†
  • n2d-highcpu-16†
  • n2d-highcpu-32†
  • n2d-highcpu-48†
  • n2d-highcpu-64†
  • n2d-highcpu-80†
  • n2d-highcpu-96†
  • n2d-highcpu-128†
  • n2d-highcpu-224†
  • n1-standard-4
  • n1-standard-8
  • n1-standard-16
  • n1-standard-32
  • n1-standard-64
  • n1-standard-96
  • n1-highmem-2
  • n1-highmem-4
  • n1-highmem-8
  • n1-highmem-16
  • n1-highmem-32
  • n1-highmem-64
  • n1-highmem-96
  • n1-highcpu-16
  • n1-highcpu-32
  • n1-highcpu-64
  • n1-highcpu-96
  • c4-standard-8†
  • c4-standard-16†
  • c4-standard-24†
  • c4-standard-32†
  • c4-standard-48†
  • c4-standard-96†
  • c4-standard-144†
  • c4-standard-192†
  • c4-standard-288†
  • c4-highmem-8†
  • c4-highmem-16†
  • c4-highmem-24†
  • c4-highmem-32†
  • c4-highmem-48†
  • c4-highmem-96†
  • c4-highmem-144†
  • c4-highmem-192†
  • c4-highmem-288†
  • c4-highcpu-8†
  • c4-highcpu-16†
  • c4-highcpu-24†
  • c4-highcpu-32†
  • c4-highcpu-48†
  • c4-highcpu-96†
  • c4-highcpu-144†
  • c4-highcpu-192†
  • c4-highcpu-288†
  • c4d-standard-8†
  • c4d-standard-16†
  • c4d-standard-32†
  • c4d-standard-48†
  • c4d-standard-64†
  • c4d-standard-96†
  • c4d-standard-192†
  • c4d-standard-384†
  • c4d-highmem-8†
  • c4d-highmem-16†
  • c4d-highmem-32†
  • c4d-highmem-48†
  • c4d-highmem-64†
  • c4d-highmem-96†
  • c4d-highmem-192†
  • c4d-highmem-384†
  • c4d-highcpu-16†
  • c4d-highcpu-32†
  • c4d-highcpu-48†
  • c4d-highcpu-64†
  • c4d-highcpu-96†
  • c4d-highcpu-192†
  • c4d-highcpu-384†
  • c3-standard-4†
  • c3-standard-8†
  • c3-standard-22†
  • c3-standard-44†
  • c3-standard-88†
  • c3-standard-176†
  • c3-highmem-4†
  • c3-highmem-8†
  • c3-highmem-22†
  • c3-highmem-44†
  • c3-highmem-88†
  • c3-highmem-176†
  • c3-highcpu-8†
  • c3-highcpu-22†
  • c3-highcpu-44†
  • c3-highcpu-88†
  • c3-highcpu-176†
  • c2-standard-4
  • c2-standard-8
  • c2-standard-16
  • c2-standard-30
  • c2-standard-60
  • cloud-tpu*
  • ct5lp-hightpu-1t*
  • ct5lp-hightpu-4t*
  • ct5lp-hightpu-8t*
  • ct6e-standard-1t*
  • ct6e-standard-4t*
  • ct6e-standard-8t *
  • tpu7x-standard-4t*
  • m1-ultramem-40
  • m1-ultramem-80
  • m1-ultramem-160
  • m1-megamem-96
  • g2-standard-4*
  • g2-standard-8*
  • g2-standard-12*
  • g2-standard-16*
  • g2-standard-24*
  • g2-standard-32*
  • g2-standard-48*
  • g2-standard-96*
  • g4-standard-48*
  • g4-standard-96*
  • g4-standard-192*
  • g4-standard-384*

* 上述清單中標有星號的機型必須搭配特定 GPU 或 TPU 使用。請參閱本指南的下列各節。

† 上述清單中標有劍號的機型僅適用於 us-central1、us-east1 和 us-west1 區域。

如要瞭解各機型的技術規格,請參閱 Compute Engine 機器類型說明文件。如要瞭解使用各個機器類型進行無伺服器訓練的費用,請參閱「定價」。

以下範例說明建立 CustomJob 時,指定機器的位置:

控制台

在 Google Cloud 控制台中,您無法直接建立CustomJob。不過,您可以建立 TrainingPipeline,以建立 CustomJob。在 Google Cloud 控制台建立TrainingPipeline時,請在「Compute and pricing」(運算和定價) 步驟的「Machine type」(機器類型) 欄位中,為每個 worker 集區指定機器類型。

gcloud

gcloud ai custom-jobs create \
  --region=LOCATION \
  --display-name=JOB_NAME \
  --worker-pool-spec=machine-type=MACHINE_TYPE,replica-count=REPLICA_COUNT,container-image-uri=CUSTOM_CONTAINER_IMAGE_URI

Java

在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Java 設定說明操作。詳情請參閱 Agent Platform Java API 參考文件。

如要向 Agent Platform 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


import com.google.cloud.aiplatform.v1.AcceleratorType;
import com.google.cloud.aiplatform.v1.ContainerSpec;
import com.google.cloud.aiplatform.v1.CustomJob;
import com.google.cloud.aiplatform.v1.CustomJobSpec;
import com.google.cloud.aiplatform.v1.JobServiceClient;
import com.google.cloud.aiplatform.v1.JobServiceSettings;
import com.google.cloud.aiplatform.v1.LocationName;
import com.google.cloud.aiplatform.v1.MachineSpec;
import com.google.cloud.aiplatform.v1.WorkerPoolSpec;
import java.io.IOException;

// Create a custom job to run machine learning training code in Vertex AI
public class CreateCustomJobSample {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String project = "PROJECT";
    String displayName = "DISPLAY_NAME";

    // Vertex AI runs your training application in a Docker container image. A Docker container
    // image is a self-contained software package that includes code and all dependencies. Learn
    // more about preparing your training application at
    // https://cloud.google.com/vertex-ai/docs/training/overview#prepare_your_training_application
    String containerImageUri = "CONTAINER_IMAGE_URI";
    createCustomJobSample(project, displayName, containerImageUri);
  }

  static void createCustomJobSample(String project, String displayName, String containerImageUri)
      throws IOException {
    JobServiceSettings settings =
        JobServiceSettings.newBuilder()
            .setEndpoint("us-central1-aiplatform.googleapis.com:443")
            .build();
    String location = "us-central1";

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests.
    try (JobServiceClient client = JobServiceClient.create(settings)) {
      MachineSpec machineSpec =
          MachineSpec.newBuilder()
              .setMachineType("n1-standard-4")
              .setAcceleratorType(AcceleratorType.NVIDIA_TESLA_T4)
              .setAcceleratorCount(1)
              .build();

      ContainerSpec containerSpec =
          ContainerSpec.newBuilder().setImageUri(containerImageUri).build();

      WorkerPoolSpec workerPoolSpec =
          WorkerPoolSpec.newBuilder()
              .setMachineSpec(machineSpec)
              .setReplicaCount(1)
              .setContainerSpec(containerSpec)
              .build();

      CustomJobSpec customJobSpecJobSpec =
          CustomJobSpec.newBuilder().addWorkerPoolSpecs(workerPoolSpec).build();

      CustomJob customJob =
          CustomJob.newBuilder()
              .setDisplayName(displayName)
              .setJobSpec(customJobSpecJobSpec)
              .build();
      LocationName parent = LocationName.of(project, location);
      CustomJob response = client.createCustomJob(parent, customJob);
      System.out.format("response: %s\n", response);
      System.out.format("Name: %s\n", response.getName());
    }
  }
}

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱 Agent Platform Node.js API 參考文件。

如要向 Agent Platform 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */

// const customJobDisplayName = 'YOUR_CUSTOM_JOB_DISPLAY_NAME';
// const containerImageUri = 'YOUR_CONTAINER_IMAGE_URI';
// const project = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';

// Imports the Google Cloud Job Service Client library
const {JobServiceClient} = require('@google-cloud/aiplatform');

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};

// Instantiates a client
const jobServiceClient = new JobServiceClient(clientOptions);

async function createCustomJob() {
  // Configure the parent resource
  const parent = `projects/${project}/locations/${location}`;
  const customJob = {
    displayName: customJobDisplayName,
    jobSpec: {
      workerPoolSpecs: [
        {
          machineSpec: {
            machineType: 'n1-standard-4',
            acceleratorType: 'NVIDIA_TESLA_T4',
            acceleratorCount: 1,
          },
          replicaCount: 1,
          containerSpec: {
            imageUri: containerImageUri,
            command: [],
            args: [],
          },
        },
      ],
    },
  };
  const request = {parent, customJob};

  // Create custom job request
  const [response] = await jobServiceClient.createCustomJob(request);

  console.log('Create custom job response:\n', JSON.stringify(response));
}
createCustomJob();

Python

如要瞭解如何安裝或更新 Vertex AI SDK for Python,請參閱「安裝 Vertex AI SDK for Python」。 詳情請參閱 Python API 參考文件。

from google.cloud import aiplatform


def create_custom_job_sample(
    project: str,
    display_name: str,
    container_image_uri: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.JobServiceClient(client_options=client_options)
    custom_job = {
        "display_name": display_name,
        "job_spec": {
            "worker_pool_specs": [
                {
                    "machine_spec": {
                        "machine_type": "n1-standard-4",
                        "accelerator_type": aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_K80,
                        "accelerator_count": 1,
                    },
                    "replica_count": 1,
                    "container_spec": {
                        "image_uri": container_image_uri,
                        "command": [],
                        "args": [],
                    },
                }
            ]
        },
    }
    parent = f"projects/{project}/locations/{location}"
    response = client.create_custom_job(parent=parent, custom_job=custom_job)
    print("response:", response)

如需更多背景資訊,請參閱建立 CustomJob 的指南。

GPU

如果您編寫的訓練程式碼會使用 GPU,則可設定 worker 集區,在每個 VM 上使用一或多個 GPU。如要使用 GPU,您必須使用 A2、N1 或 G2 機型。此外,如果使用較小的機器類型 (例如 n1-highmem-2) 搭配 GPU,可能會因為 CPU 限制而導致某些工作負載無法記錄。如果訓練工作停止傳回記錄,建議您選取較大的機器類型。

Agent Platform 支援下列類型的 GPU,可用於無伺服器訓練:

  • NVIDIA_GB200+ (包含 GPUDirect-RDMA)
  • NVIDIA_B200* (包含 GPUDirect-RDMA)
  • NVIDIA_H100_MEGA_80GB* (包含 GPUDirect-TCPXO)
  • NVIDIA_H100_80GB
  • NVIDIA_H200_141GB* (包含 GPUDirect-RDMA)
  • NVIDIA_A100_80GB
  • NVIDIA_TESLA_A100 (NVIDIA A100 40GB)
  • NVIDIA_TESLA_P4
  • NVIDIA_TESLA_P100
  • NVIDIA_TESLA_T4
  • NVIDIA_TESLA_V100
  • NVIDIA_L4
  • NVIDIA_RTX_PRO_6000
* 建議使用共用預留項目或 Spot VM 取得運算資源。

+ 必須使用共用預留項目取得容量。

如要進一步瞭解各類 GPU 的技術規格,請參閱 Compute Engine 說明文件中有關運算工作負載專用 GPU 的部分。如要瞭解使用各類機器進行無伺服器訓練的費用,請參閱「定價」。

在 WorkerPoolSpec 中,於 machineSpec.acceleratorType 欄位指定要使用的 GPU 類型,並在 machineSpec.acceleratorCount 欄位指定 worker 集區中每個 VM 要使用的 GPU 數量。不過,您對這些欄位的選擇必須符合下列限制:

  • 您選擇的 GPU 類型必須在執行無伺服器訓練的位置可用。某些區域可能只提供部分類型的 GPU。瞭解區域供應情形。

  • 只能在設定中使用特定數量的 GPU。舉例來說,您可以在 VM 上使用 2 或 4 個 NVIDIA_TESLA_T4 GPU,但不能使用 3 個。如要瞭解各類型 GPU 的有效 acceleratorCount 值,請參閱下方的相容性表格。

  • 您必須確保 GPU 設定為所搭配的機型提供足夠的虛擬 CPU 和記憶體。舉例來說,如果您在 worker 集區中使用 n1-standard-32 機型,則每個 VM 都有 32 個虛擬 CPU 和 120 GB 的記憶體。由於每個 NVIDIA_TESLA_V100 GPU 最多可提供 12 個虛擬 CPU 和 76 GB 記憶體,因此每個 n1-standard-32 VM 至少須使用 4 個 GPU,才能滿足其需求。(2 個 GPU 提供的資源不足,且無法指定 3 個 GPU)。

    下方的相容性表格已考量這項規定。

    請注意,使用 GPU 進行自訂訓練時,還有下列限制,與在 Compute Engine 使用 GPU 不同:

    • 在「所有」區域和可用區中,搭載 4 個 NVIDIA_TESLA_P100 GPU 的設定最多只能提供 64 個虛擬 CPU 和 208 GB 記憶體。
  • 如果工作使用 Dynamic Workload Scheduler 或 Spot VM,請將 CustomJob 的 scheduling.strategy 欄位更新為所選策略。

下方的相容性表格列出 machineSpec.acceleratorCount 的有效值,具體取決於您對 machineSpec.machineType 和 machineSpec.acceleratorType 的選擇:

各機器類型的有效 GPU 數量
機型 NVIDIA_H100_MEGA_80GB NVIDIA_H100_80GB NVIDIA_A100_80GB NVIDIA_TESLA_A100 NVIDIA_TESLA_P4 NVIDIA_TESLA_P100 NVIDIA_TESLA_T4 NVIDIA_TESLA_V100 NVIDIA_L4 NVIDIA_H200_141GB NVIDIA_B200 NVIDIA_GB200 NVIDIA_RTX_PRO_6000
a3-megagpu-8g 8
a3-highgpu-1g 1
a3-highgpu-2g 2
a3-highgpu-4g 4
a3-highgpu-8g 8
a3-ultragpu-8g 8
a4-highgpu-8g 8
a4x-highgpu-4g 4
a2-ultragpu-1g 1
a2-ultragpu-2g 2
a2-ultragpu-4g 4
a2-ultragpu-8g 8
a2-highgpu-1g 1
a2-highgpu-2g 2
a2-highgpu-4g 4
a2-highgpu-8g 8
a2-megagpu-16g 16
n1-standard-4 1、2、4 1、2、4 1、2、4 1、2、4、8
n1-standard-8 1、2、4 1、2、4 1、2、4 1、2、4、8
n1-standard-16 1、2、4 1、2、4 1、2、4 2、4、8
n1-standard-32 2、4 2、4 2、4 4、8
n1-standard-64 4 4 8
n1-standard-96 4 4 8
n1-highmem-2 1、2、4 1、2、4 1、2、4 1、2、4、8
n1-highmem-4 1、2、4 1、2、4 1、2、4 1、2、4、8
n1-highmem-8 1、2、4 1、2、4 1、2、4 1、2、4、8
n1-highmem-16 1、2、4 1、2、4 1、2、4 2、4、8
n1-highmem-32 2、4 2、4 2、4 4、8
n1-highmem-64 4 4 8
n1-highmem-96 4 4 8
n1-highcpu-16 1、2、4 1、2、4 1、2、4 2、4、8
n1-highcpu-32 2、4 2、4 2、4 4、8
n1-highcpu-64 4 4 4 8
n1-highcpu-96 4 4 8
g2-standard-4 1
g2-standard-8 1
g2-standard-12 1
g2-standard-16 1
g2-standard-24 2
g2-standard-32 1
g2-standard-48 4
g2-standard-96 8
g4-standard-48 1
g4-standard-96 2
g4-standard-192 4
g4-standard-384 8

以下範例說明建立 CustomJob 時,可以在何處指定 GPU:

控制台

在 Google Cloud 控制台中,您無法直接建立CustomJob。不過,您可以建立 TrainingPipeline,用來建立 CustomJob。在 Google Cloud 控制台建立TrainingPipeline時,您可以在「Compute and pricing」(運算和定價) 步驟中為每個 worker 集區指定 GPU。請先指定機器類型。接著,您可以在「Accelerator type」(加速器類型) 和「Accelerator count」(加速器數量) 欄位中指定 GPU 詳細資料。

gcloud

如要使用 Google Cloud CLI 工具指定 GPU,必須使用 config.yaml 檔案。例如:

config.yaml

workerPoolSpecs:
  machineSpec:
    machineType: MACHINE_TYPE
    acceleratorType: ACCELERATOR_TYPE
    acceleratorCount: ACCELERATOR_COUNT
  replicaCount: REPLICA_COUNT
  containerSpec:
    imageUri: CUSTOM_CONTAINER_IMAGE_URI

然後執行類似下列的指令:

gcloud ai custom-jobs create \
  --region=LOCATION \
  --display-name=JOB_NAME \
  --config=config.yaml

Node.js

在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Node.js 設定說明操作。詳情請參閱 Agent Platform Node.js API 參考文件。

如要向 Agent Platform 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

/**
 * TODO(developer): Uncomment these variables before running the sample.\
 * (Not necessary if passing values as arguments)
 */

// const customJobDisplayName = 'YOUR_CUSTOM_JOB_DISPLAY_NAME';
// const containerImageUri = 'YOUR_CONTAINER_IMAGE_URI';
// const project = 'YOUR_PROJECT_ID';
// const location = 'YOUR_PROJECT_LOCATION';

// Imports the Google Cloud Job Service Client library
const {JobServiceClient} = require('@google-cloud/aiplatform');

// Specifies the location of the api endpoint
const clientOptions = {
  apiEndpoint: 'us-central1-aiplatform.googleapis.com',
};

// Instantiates a client
const jobServiceClient = new JobServiceClient(clientOptions);

async function createCustomJob() {
  // Configure the parent resource
  const parent = `projects/${project}/locations/${location}`;
  const customJob = {
    displayName: customJobDisplayName,
    jobSpec: {
      workerPoolSpecs: [
        {
          machineSpec: {
            machineType: 'n1-standard-4',
            acceleratorType: 'NVIDIA_TESLA_T4',
            acceleratorCount: 1,
          },
          replicaCount: 1,
          containerSpec: {
            imageUri: containerImageUri,
            command: [],
            args: [],
          },
        },
      ],
    },
  };
  const request = {parent, customJob};

  // Create custom job request
  const [response] = await jobServiceClient.createCustomJob(request);

  console.log('Create custom job response:\n', JSON.stringify(response));
}
createCustomJob();

Python

如要瞭解如何安裝或更新 Vertex AI SDK for Python,請參閱「安裝 Vertex AI SDK for Python」。 詳情請參閱 Python API 參考文件。

from google.cloud import aiplatform


def create_custom_job_sample(
    project: str,
    display_name: str,
    container_image_uri: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.JobServiceClient(client_options=client_options)
    custom_job = {
        "display_name": display_name,
        "job_spec": {
            "worker_pool_specs": [
                {
                    "machine_spec": {
                        "machine_type": "n1-standard-4",
                        "accelerator_type": aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_K80,
                        "accelerator_count": 1,
                    },
                    "replica_count": 1,
                    "container_spec": {
                        "image_uri": container_image_uri,
                        "command": [],
                        "args": [],
                    },
                }
            ]
        },
    }
    parent = f"projects/{project}/locations/{location}"
    response = client.create_custom_job(parent=parent, custom_job=custom_job)
    print("response:", response)

如需更多背景資訊,請參閱建立 CustomJob 的指南。

GPUDirect 網路

在 Vertex Training,部分 H100、H200、B200 和 GB200 系列機器已預先設定 GPUDirect 網路堆疊。與不支援 GPUDirect 的 GPU 相比,GPUDirect 可將 GPU 之間的網路速度提高多達 2 倍。

GPUDirect 的做法是減少在 GPU 之間移轉封包酬載所需的負擔,大幅提升大規模處理量。

GPUDirect-TCPXO

a3-megagpu-8g 機型具有:

  • 每部機器 8 個 NVIDIA H100 GPU
  • 主要 NIC 的頻寬最高可達 200 Gbps
  • 8 個次要 NIC,每個最多支援 200 Gbps 的 GPU 資料移轉
  • GPUDirect-TCPXO,可進一步改善 GPU 對 VM 的通訊

具備 GPUDirect 的 GPU 特別適合用於大型模型的分散式訓練。

GPUDirect-RDMA

a4x-highgpu-4g 機型具備以下規格:

  • 每部機器 4 個 GB200 GPU
  • 2 個主機 NIC,提供 400 Gbps 的頻寬
  • 6 個 NIC,GPU 資料移轉速度最高可達 2400 Gbps
  • GPUDirect-RDMA:透過 RoCE (基於融合乙太網路的 RDMA),為大規模機器學習訓練工作負載的 GPU 通訊提供更高的網路效能

a3-ultragpu-8g 和 a4-highgpu-8g 機型具備:

  • 每部機器 8 個 NVIDIA H200/B200 GPU
  • 2 個主機 NIC,提供 400 Gbps 的頻寬
  • 8 個網路介面卡,提供高達 3200 Gbps 的 GPU 資料移轉速度
  • GPUDirect-RDMA:透過 RoCE (基於融合乙太網路的 RDMA),為大規模機器學習訓練工作負載的 GPU 通訊提供更高的網路效能

TPU

如要在 Agent Platform 上使用 Tensor Processing Unit (TPU) 進行自訂訓練,您可以設定 worker 集區來使用 TPU VM。

在 Agent Platform 中使用 TPU VM 時,您只能使用單一 worker 集區進行自訂訓練,且必須將這個 worker 集區設為僅使用一個副本。

TPU v2 和 v3

如要在 worker 集區中使用 TPU v2 或 v3 VM,必須採用下列其中一種設定:

  • 如要使用 TPU v2 設定 TPU VM,請在 WorkerPoolSpec 中指定下列欄位:

    • 將 machineSpec.machineType 設為 cloud-tpu。
    • 將 machineSpec.acceleratorType 設為 TPU_V2。
    • 將 machineSpec.acceleratorCount 設為 8 (單一 TPU) 或 32 or multiple of 32 (TPU Pod)。
    • 將 replicaCount 設為 1。
  • 如要使用 TPU v3 設定 TPU VM,請在 WorkerPoolSpec 中指定下列欄位:

    • 將 machineSpec.machineType 設為 cloud-tpu。
    • 將 machineSpec.acceleratorType 設為 TPU_V3。
    • 將 machineSpec.acceleratorCount 設為 8 (單一 TPU) 或 32+ (TPU Pod)。
    • 將 replicaCount 設為 1。

如要瞭解 TPU 的區域可用性,請參閱「使用加速器」。

TPU v5e

TPU v5e 必須使用 JAX 0.4.6 以上版本、TensorFlow 2.15 以上版本,或 PyTorch 2.1 以上版本。如要設定 TPU VM 搭配 TPU v5e,請在 WorkerPoolSpec 中指定下列欄位:

  • 將 machineSpec.machineType 設為 ct5lp-hightpu-1t、ct5lp-hightpu-4t 或 ct5lp-hightpu-8t。
  • 將 machineSpec.tpuTopology 設為機型支援的拓撲。詳情請參閱下表。
  • 將 replicaCount 設為 1。

下表列出自訂訓練支援的 TPU v5e 機型和拓撲:

機型 拓撲 TPU 晶片數量 VM 數量 建議用途
ct5lp-hightpu-1t 1x1 1 1 中小型訓練
ct5lp-hightpu-4t 2x2 4 1 中小型訓練
ct5lp-hightpu-8t 2x4 8 1 中小型訓練
ct5lp-hightpu-4t 2x4 8 2 中小型訓練
ct5lp-hightpu-4t 4x4 16 4 大規模訓練
ct5lp-hightpu-4t 4x8 32 8 大規模訓練
ct5lp-hightpu-4t 8x8 64 16 大規模訓練
ct5lp-hightpu-4t 8x16 128 32 大規模訓練
ct5lp-hightpu-4t 16x16 256 64 大規模訓練

在 TPU v5e VM 上執行的自訂訓練工作,已針對處理量和可用性進行最佳化。詳情請參閱「v5e 訓練加速器類型」。

如要瞭解 TPU 的區域可用性,請參閱「使用加速器」。如要進一步瞭解 TPU v5e,請參閱「Cloud TPU v5e 訓練」。

機型比較:

機型 ct5lp-hightpu-1t ct5lp-hightpu-4t ct5lp-hightpu-8t
v5e 晶片數量 1 4 8
vCPU 數量 24 112 224
RAM (GB) 48 192 384
NUMA 節點數量 1 1 2
先占可能性 高 中 低

TPU v6e

TPU v6e 必須使用 Python 3.10 以上版本、JAX 0.4.37 以上版本、PyTorch 2.1 以上版本 (預設執行階段為 PJRT),或 TensorFlow (僅限 tf-nightly 執行階段 2.18 以上版本)。如要設定 TPU VM 並使用 TPU v6e,請在 WorkerPoolSpec 中指定下列欄位:

  • 將 machineSpec.machineType 設為 ct6e。
  • 將 machineSpec.tpuTopology 設為機型支援的拓撲。詳情請參閱下表。
  • 將 replicaCount 設為 1。

下表列出自訂訓練支援的 TPU v6e 機型和拓撲:

機型 拓撲 TPU 晶片數量 VM 數量 建議用途
ct6e-standard-1t 1x1 1 1 中小型訓練
ct6e-standard-8t 2x4 8 1 中小型訓練
ct6e-standard-4t 2x2 4 1 中小型訓練
ct6e-standard-4t 2x4 8 2 中小型訓練
ct6e-standard-4t 4x4 16 4 大規模訓練
ct6e-standard-4t 4x8 32 8 大規模訓練
ct6e-standard-4t 8x8 64 16 大規模訓練
ct6e-standard-4t 8x16 128 32 大規模訓練
ct6e-standard-4t 16x16 256 64 大規模訓練

如要瞭解 TPU 的區域可用性,請參閱「使用加速器」。如要進一步瞭解 TPU v6e,請參閱「Cloud TPU v6e 訓練」。

機型比較:

機型 ct6e-standard-1t ct6e-standard-4t ct6e-standard-8t
v6e 晶片數量 1 4 8
vCPU 數量 44 180 180
RAM (GB) 48 720 1440
NUMA 節點數量 2 1 2
先占可能性 高 中 低

TPU 7x

TPU7x 需要 Python 3.12 以上版本。

建議您採用下列穩定組合,進行功能測試和工作負載遷移:

  • JAX + JAX Lib:jax-0.8.1.dev20251104、jaxlib-0.8.1.dev2025104
  • 穩定版 libtpu:libtpu-0.0.27

如要設定 TPU 7x 的 TPU VM,請在 WorkerPoolSpec 中指定下列欄位:

  • 將 machineSpec.machineType 設為 tpu7x-standard-4t。
  • 將 machineSpec.tpuTopology 設為機型支援的拓撲。詳情請參閱下表。
  • 將 replicaCount 設為 1。

下表列出自訂訓練支援的 TPU 7x 拓撲。所有拓撲都使用 tpu7x-standard-4t 機型。

拓撲 TPU 晶片數量 VM 數量 範圍
2x2x1 4 1 單一主機
2x2x2 8 2 多主機
2x2x4 16 4 多主機
2x4x4 32 8 多主機
4x4x4 64 16 多主機
4x4x8 128 32 多主機
4x8x8 256 64 多主機
8x8x8 512 128 多主機
8x8x16 1024 256 多主機

如要瞭解 TPU 的區域可用性,請參閱「使用加速器」。如要進一步瞭解 TPU7x,請參閱「Cloud TPU7x 訓練」。

指定 TPU VM 的 CustomJob 範例

以下範例說明如何在建立 CustomJob 時指定 TPU VM:

gcloud

如要使用 gcloud CLI 工具指定 TPU VM,您必須使用 config.yaml 檔案。選取下列任一分頁標籤,即可查看範例:

TPU v2/v3

workerPoolSpecs:
  machineSpec:
    machineType: cloud-tpu
    acceleratorType: TPU_V2
    acceleratorCount: 8
  replicaCount: 1
  containerSpec:
    imageUri: CUSTOM_CONTAINER_IMAGE_URI

TPU v5e

workerPoolSpecs:
  machineSpec:
    machineType: ct5lp-hightpu-4t
    tpuTopology: 4x4
  replicaCount: 1
  containerSpec:
    imageUri: CUSTOM_CONTAINER_IMAGE_URI

然後執行類似下列的指令:

gcloud ai custom-jobs create \
  --region=LOCATION \
  --display-name=JOB_NAME \
  --config=config.yaml

Python

在試用這個範例之前,請先按照「使用用戶端程式庫的 Agent Platform 快速入門導覽課程」中的 Python 設定說明操作。詳情請參閱 Agent Platform Python API 參考文件。

如要向 Agent Platform 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

如要使用 Agent Platform SDK for Python 指定 TPU VM,請參考下列範例:

from google.cloud.aiplatform import aiplatform

job = aiplatform.CustomContainerTrainingJob(
    display_name='DISPLAY_NAME',
    location='us-west1',
    project='PROJECT_ID',
    staging_bucket="gs://CLOUD_STORAGE_URI",
    container_uri='CONTAINER_URI')

job.run(machine_type='ct5lp-hightpu-4t', tpu_topology='2x2')

如要進一步瞭解如何建立自訂訓練工作,請參閱「建立自訂訓練工作」。

開機磁碟選項

您可以視需要自訂訓練 VM 的開機磁碟。worker 集區中的所有 VM 都使用相同類型和大小的開機磁碟。

  • 如要自訂各個訓練 VM 使用的開機磁碟類型,請在 WorkerPoolSpec 中指定 diskSpec.bootDiskType 欄位。

    這個欄位可設為下列其中一個值:

    • pd-standard:使用標準硬碟支援的標準永久磁碟
    • pd-ssd:使用由固態硬碟支援的 SSD 永久磁碟
    • hyperdisk-balanced,以提高 IOPS 和處理量。

    預設值為 pd-ssd (hyperdisk-balanced 是 a3-ultragpu-8g、a4-highgpu-8g 和 N4D、C4 和 C4D 機型的預設值)。

    如果訓練程式碼會讀取及寫入磁碟,使用 pd-ssd 或 hyperdisk-balanced 可能會提升效能。瞭解磁碟類型。另請參閱支援 Hyperdisk 的機器。

  • 如要自訂每個訓練 VM 使用的開機磁碟大小 (以 GB 為單位),請在 WorkerPoolSpec 中指定 diskSpec.bootDiskSizeGb 欄位。

    這個欄位可設為 100 到 64,000 之間的整數 (含首尾)。預設值為 100。

    如果訓練程式碼會將大量暫存資料寫入磁碟,建議您增加開機磁碟大小。請注意,寫入開機磁碟的任何資料都是暫時性的,訓練完成後就無法擷取。

變更開機磁碟的類型和大小會影響自訂訓練定價。

下列範例說明建立 CustomJob 時,可在何處指定開機磁碟選項:

控制台

在 Google Cloud 控制台中,您無法直接建立CustomJob。不過,您可以建立 TrainingPipeline,用來建立 CustomJob。在 Google Cloud 控制台建立TrainingPipeline時,您可以在「Compute and pricing」(運算和定價) 步驟中,透過「Disk type」(磁碟類型) 下拉式選單和「Disk size (GB)」(磁碟大小 (GB)) 欄位,為每個 worker 集區指定開機磁碟選項。

gcloud

如要使用 Google Cloud CLI 工具指定開機磁碟選項,您必須使用 config.yaml 檔案。例如:

config.yaml

workerPoolSpecs:
  machineSpec:
    machineType: MACHINE_TYPE
  diskSpec:
    bootDiskType: DISK_TYPE
    bootDiskSizeGb: DISK_SIZE
  replicaCount: REPLICA_COUNT
  containerSpec:
    imageUri: CUSTOM_CONTAINER_IMAGE_URI

然後執行類似下列的指令:

gcloud ai custom-jobs create \
  --region=LOCATION \
  --display-name=JOB_NAME \
  --config=config.yaml

如需更多背景資訊,請參閱建立 CustomJob 的指南。

後續步驟