自動記錄資料至實驗執行作業

自動記錄是 Vertex AI SDK 的一項功能,可自動將模型訓練執行的參數和指標記錄到 Vertex AI Experiments。這樣一來,您就不必手動記錄這些資料,可節省時間和精力。自動記錄功能僅支援記錄參數和指標。

自動記錄資料

您可以透過以下兩種方式,將資料自動記錄到 Vertex AI Experiments。

  1. 讓 Vertex AI SDK 自動為您建立 ExperimentRun 資源。
  2. 指定要將自動記錄的參數和指標寫入的 ExperimentRun 資源。

自動建立

Python 適用的 Vertex AI SDK 會為您建立 ExperimentRun 資源。 系統自動建立的 ExperimentRun 資源會採用下列格式的執行名稱: {ml-framework-name}-{timestamp}-{uid}, 例如:「tensorflow-2023-01-04-16-09-20-86a88」。

下列範例使用 init 方法,來自 aiplatform Package 函式

Python

from typing import Optional, Union

from google.cloud import aiplatform


def autologging_with_auto_run_creation_sample(
    experiment_name: str,
    project: str,
    location: str,
    experiment_tensorboard: Optional[Union[str, aiplatform.Tensorboard]] = None,
):
    aiplatform.init(
        experiment=experiment_name,
        project=project,
        location=location,
        experiment_tensorboard=experiment_tensorboard,
    )

    aiplatform.autolog()

    # Your model training code goes here

    aiplatform.autolog(disable=True)

  • experiment_name:為實驗命名。如要查看實驗清單,請在 Google Cloud 控制台選取區段導覽中的「實驗」
  • experiment_tensorboard:(選用) 為 Vertex AI TensorBoard 執行個體命名。
  • project:。您可以在 Google Cloud 控制台歡迎頁面中找到這些專案 ID。
  • location:請參閱「支援的地區清單

使用者指定

提供您自己的 ExperimentRun 名稱,並將多個模型訓練執行作業的指標和參數記錄到同一個 ExperimentRun。呼叫 aiplatform.start_run("your-run-name") 直到呼叫 aiplatform.end_run() 為止,即可取得模型到目前執行階段的任何指標。

下列範例使用 aiplatform Package functions 中的 init 方法。

Python

from typing import Optional, Union

from google.cloud import aiplatform


def autologging_with_manual_run_creation_sample(
    experiment_name: str,
    run_name: str,
    project: str,
    location: str,
    experiment_tensorboard: Optional[Union[str, aiplatform.Tensorboard]] = None,
):
    aiplatform.init(
        experiment=experiment_name,
        project=project,
        location=location,
        experiment_tensorboard=experiment_tensorboard,
    )

    aiplatform.autolog()

    aiplatform.start_run(run=run_name)

    # Your model training code goes here

    aiplatform.end_run()

    aiplatform.autolog(disable=True)

  • experiment_name:提供實驗名稱。
  • run_name:為實驗執行作業命名。 如要查看實驗清單,請在控制台中選取區段導覽中的「實驗」 Google Cloud
  • project:。您可以在 Google Cloud 控制台的歡迎頁面中找到這些專案 ID。
  • location:請參閱「支援的地區清單
  • experiment_tensorboard:(選用) 為 Vertex AI TensorBoard 執行個體命名。

Vertex AI SDK 自動記錄功能在實作時會使用 MLFlow 的自動記錄功能。 啟用自動記錄功能後,系統會將下列架構的評估指標和參數記錄到 ExperimentRun。

  • Fastai
  • Gluon
  • Keras
  • LightGBM
  • Pytorch Lightning
  • Scikit-learn
  • Spark
  • Statsmodels
  • XGBoost

查看自動記錄的參數和指標

使用 Python 適用的 Vertex AI SDK 比較執行作業,並取得執行作業資料。Google Cloud 控制台提供簡單的方式來比較這些執行作業。

相關筆記本範例

網誌文章