設定自訂訓練工作的運算資源

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

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

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

本文說明可用於自訂訓練作業的各種運算資源,以及如何設定這些資源。

管理費用和供應情形

為協助管理費用或確保 VM 資源可用性,Vertex AI 提供下列功能:

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

  • 如要降低執行訓練工作的成本,可以使用 Spot VM。Spot VM 是虛擬機器 (VM) 執行個體,屬於 Compute Engine 的剩餘容量。Spot VM 的折扣幅度相當可觀,但 Compute Engine 可能會隨時搶占容量,因此預先停止或刪除 Spot VM。詳情請參閱搭配訓練作業使用 Spot VM

  • 對於要求 GPU 資源的自訂訓練工作,動態工作負載排程器可讓您根據所要求 GPU 資源的可用時間,排定工作時間。詳情請參閱「根據資源可用性安排訓練工作」。

指定運算資源的位置

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

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

機器類型

WorkerPoolSpec 中,您必須在 machineSpec.machineType 欄位中指定下列其中一種機器類型。工作站集區中的每個副本都會在具有指定機器類型的個別 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
  • 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
  • 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
  • c2-standard-4
  • c2-standard-8
  • c2-standard-16
  • c2-standard-30
  • c2-standard-60
  • ct5lp-hightpu-1t*
  • ct5lp-hightpu-4t*
  • ct5lp-hightpu-8t*
  • 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*
  • cloud-tpu*

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

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

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

控制台

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

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

在試用這個範例之前,請先按照Java使用用戶端程式庫的 Vertex AI 快速入門中的操作說明進行設定。 詳情請參閱 Vertex AI Java API 參考說明文件

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

 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

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

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

/**  * 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

如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 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,則可將工作站集區設定為在每個 VM 上使用一或多個 GPU。如要使用 GPU,必須使用 A2、N1 或 G2 機器類型。此外,使用較小的機器類型 (例如搭載 GPU 的 n1-highmem-2) 可能會因 CPU 限制,導致部分工作負載無法記錄。如果訓練工作停止傳回記錄,請考慮選取較大的機器類型。

Vertex AI 支援下列類型的 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
* 建議使用共用預訂搶占型 VM 取得容量。

+ 需要使用共用預留項目取得容量。

如要進一步瞭解各類 GPU 的技術規格,請參閱 Compute Engine 簡短說明文件,瞭解適用於運算工作負載的 GPU。如要瞭解使用各機器類型進行自訂訓練的費用,請參閱「定價」一文。

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

  • 所選 GPU 類型必須在執行自訂訓練的位置提供。並非所有區域都提供所有類型的 GPU。瞭解區域供應情形

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

  • 請務必確認 GPU 設定為使用的機器類型提供充足的虛擬 CPU 和記憶體。舉例來說,如果您在工作站集區中使用 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 SchedulerSpot VM,請將 CustomJobscheduling.strategy 欄位更新為所選策略。

下表列出 machineSpec.acceleratorCount 的有效值,具體取決於您為 machineSpec.machineTypemachineSpec.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
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

* 只有在使用 Dynamic Workload SchedulerSpot VM 時,才能使用指定的機器類型。

下列範例說明建立 CustomJob 時,可在哪些位置指定 GPU:

控制台

在 Google Cloud 控制台中,您無法直接建立 CustomJob。 不過,您可以建立 TrainingPipeline,藉此建立 CustomJob。在 Google Cloud 控制台中建立TrainingPipeline時,您可以在「Compute and pricing」(運算和價格)步驟中,為每個工作站集區指定 GPU。請先指定機器類型。接著,您可以在「加速器類型」和「加速器數量」欄位中指定 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

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

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

/**  * 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

如要瞭解如何安裝或更新 Python 適用的 Vertex AI SDK,請參閱「安裝 Python 適用的 Vertex AI SDK」。 詳情請參閱 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 over Converged Ethernet) 為大規模機器學習訓練工作負載的 GPU 通訊提供更高的網路效能

a3-ultragpu-8ga4-highgpu-8g 機器類型具有以下特點:

  • 每部機器 8 個 NVIDIA H200/B200 GPU
  • 2 個主機 NIC,提供 400 Gbps 的頻寬
  • 8 個 NIC,GPU 資料傳輸速度最高可達 3200 Gbps
  • GPUDirect-RDMA,可透過 RoCE (RDMA over Converged Ethernet) 為大規模機器學習訓練工作負載的 GPU 通訊提供更高的網路效能

TPU

如要在 Vertex AI 上使用 Tensor Processing Unit (TPU) 進行自訂訓練,您可以將工作站集區設定為使用 TPU VM

在 Vertex AI 中使用 TPU VM 時,自訂訓練只能使用單一工作站集區,且必須將這個工作站集區設定為只使用一個副本。

TPU v2 和 v3

如要在工作站集區中使用 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 v5e 設定 TPU VM,請在 WorkerPoolSpec 中指定下列欄位:

  • machineSpec.machineType 設為 ct5lp-hightpu-1tct5lp-hightpu-4tct5lp-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 以上版本、以 PJRT 做為預設執行階段的 PyTorch 2.1 以上版本,或是僅使用 tf-nightly 執行階段版本 2.18 以上版本的 TensorFlow。如要設定搭載 TPU v6e 的 TPU VM,請在 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
先占可能性

範例 CustomJob 指定 TPU VM

下列範例重點說明如何建立 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

在試用這個範例之前,請先按照Python使用用戶端程式庫的 Vertex AI 快速入門中的操作說明進行設定。 詳情請參閱 Vertex AI Python API 參考說明文件

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

如要使用 Python 適用的 Vertex AI SDK 指定 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 的開機磁碟。工作站集區中的所有 VM 都使用相同類型和大小的開機磁碟。

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

    您可以將這個欄位設為下列其中一項:

    • pd-standard 使用以標準硬碟為基礎的標準永久磁碟
    • pd-ssd,使用以固態硬碟備份的 SSD 永久磁碟
    • hyperdisk-balanced,以提高 IOPS 和總處理量。

    預設值為 pd-ssd (hyperdisk-balanceda3-ultragpu-8ga4-highgpu-8g 的預設值)。

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

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

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

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

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

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

控制台

在 Google Cloud 控制台中,您無法直接建立 CustomJob。 不過,您可以建立 TrainingPipeline,藉此建立 CustomJob。在 Google Cloud 控制台中建立 TrainingPipeline 時,您可以在「運算和價格」步驟中,透過「磁碟類型」下拉式清單和「磁碟大小 (GB)」欄位,為每個工作站集區指定開機磁碟選項。

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的指南。

後續步驟