Vertex AI Pipelines 的資源標記

視元件、資源和 Google Cloud Pipeline Components SDK 版本而定,Vertex AI Pipelines 會自動將管道執行作業的標籤傳播至從 Google Cloud Pipeline Components 產生的資源,或要求您為產生的資源加上標籤。如果是使用者定義的元件,您需要撰寫元件程式碼,從環境變數附加標籤。詳情請參閱「從使用者定義的元件產生的資源」。

自動加上標籤的資源

無論 Pipeline Components SDK 版本為何,Vertex AI Pipelines 都會自動標記下列資源: Google Cloud

CustomJob 項資源

Vertex AI Pipelines 會自動將標籤從管線執行作業傳播至 CustomJob 資源。所有版本的 Google Cloud Pipeline Components SDK 都支援這項功能,包括下列元件:

在 Google Cloud Pipeline Components SDK 1.0.31 以上版本中,資源會自動加上標籤

如果您使用 Google Cloud Pipeline Components SDK 1.0.31 以上版本,Vertex AI Pipelines 會自動為下列資源加上標籤:

BatchPredictionJob 項資源

如果您使用 Google Cloud Pipeline Components SDK 1.0.31 以上版本,Vertex AI Pipelines 會自動將管道執行的標籤傳播至 ModelBatchPredictOp 元件產生的 BatchPredictionJob 資源。

Vertex AI endpoint 資源

如果您使用 Google Cloud Pipeline Components SDK 1.0.31 以上版本,Vertex AI Pipelines 會自動將標籤從管道執行作業傳播至 EndpointCreateOp 元件產生的 Vertex AI endpoint 資源。

HyperparameterTuningJob 項資源

如果您使用 Google Cloud Pipeline Components SDK 1.0.31 以上版本,Vertex AI Pipelines 會自動將管道執行的標籤傳播至 HyperparameterTuningJobRunOp 元件產生的 HyperparameterTuningJob 資源。

Vertex AI 資料集資源

如果您使用 Google Cloud Pipeline Components SDK 1.0.31 以上版本,Vertex AI Pipelines 會自動將管道執行作業中的標籤,傳播至下列 Vertex AI 元件產生的 Vertex AI 資料集資源:

Google Cloud BigQuery 工作資源

如果您使用 Google Cloud Pipeline Components SDK 1.0.31 以上版本,Vertex AI Pipelines 會自動將標籤從管線執行作業傳播至從任何 BigQuery ML 元件產生的 BigQuery 工作資源。 Google Cloud

Google Cloud Dataproc 工作資源

如果您使用 v1.0.31 以上版本的 Google Cloud 管道元件 SDK,Vertex AI Pipelines 會自動將管道執行的標籤傳播至 Google Cloud 從任何 Dataproc Serverless 元件產生的 Dataproc Job 資源。

TrainingPipelineModel 資源

如果您使用 Google Cloud Pipeline Components SDK 1.0.31 以上版本,Vertex AI Pipelines 會自動將標籤從管道執行作業傳播至下列 AutoML 元件產生的 TrainingPipelineModel 資源:

Google Cloud BigQuery 資料表資源

如果您使用 Google Cloud Pipeline Components SDK 1.0.31 以上版本,Vertex AI Pipelines 會自動將標籤從管道執行作業 Google Cloud BigQuery 表格資源傳播至 ForecastingPreprocessingOp 元件產生的資源。

未自動加上標籤的資源

無論 Pipeline Components SDK 版本為何,Vertex AI Pipelines 都不會自動標記下列資源: Google Cloud

Google Cloud Dataflow 資源

Vertex AI Pipelines 不會自動為 DataflowPythonJobOp 元件產生的 Dataflow 資源加上標籤。您可以在程式碼中加入標記資源的指令。

使用下列程式碼範例,將帳單標籤從管道執行作業傳播至使用 DataflowPythonJobOp 元件產生的任何 Google Cloud Dataflow 資源:

  import argparse
  import apache_beam as beam
  ...
  def run(argv=None):
    parser = argparse.ArgumentParser()
    # Don't add `--labels` to the argument list, so that they will be passed to the pipeline_options 
    parser.add_argument('--input', )
    parser.add_argument('--output', )
  ...
    known_args, pipeline_args = parser.parse_known_args(argv)
    pipeline_options = PipelineOptions(pipeline_args)
    with beam.Pipeline(options=pipeline_options) as p:

從使用者定義的元件產生的資源

Vertex AI Pipelines 不會自動為使用者定義的元件所產生的資源加上標籤 Google Cloud 。您可以在程式碼中加入指令,從環境變數 VERTEX_AI_PIPELINES_RUN_LABELS 擷取標籤,並在執行階段將這些標籤附加至使用元件產生的 Google Cloud 資源。

環境變數 VERTEX_AI_PIPELINE_RUN_LABELS 包含 JSON 格式的標籤,以鍵/值組合表示。

例如:{ "label1_key": "label1_value", "label2_key": "label2_value", ...}

如果您使用 Vertex AI SDK for Python,請在元件程式碼中使用下列程式碼範例,將標籤從環境變數傳播至元件產生的新資源:

import os
import json
from google.cloud import aiplatform

aiplatform.init(
  project='PROJECT_ID',
  location='LOCATION'
)

aiplatform.RESOURCE.create(
  ...ß
  json.loads(os.getenv("VERTEX_AI_PIPELINES_RUN_LABELS"))
)

更改下列內容:

  • PROJECT_ID:包含管道執行的 Google Cloud 專案。

  • LOCATION:管道執行的位置。

  • RESOURCE: Google Cloud 從元件產生的資源,例如 CustomJobModel

如要使用 Python 剖析環境變數,也可以使用 gcp_labels_util.attach_system_labels 公用程式。只有在您有權存取 Google Cloud 管道元件程式庫,且使用 Python 時,才能使用這項公用程式。詳情請參閱 GitHub 上的公用程式函式原始碼

不支援標籤的資源

Vertex AI Pipelines 不支援將帳單標籤傳播至下列資源:

機器學習中繼資料資源

系統會以商店層級計費機器學習中繼資料資源。您無法使用帳單標籤瞭解資源層級的費用。

Cloud Storage 資源

Vertex AI Pipelines 不會將帳單標籤傳播至 Cloud Storage 資源,例如 Cloud Storage 值區。

後續步驟