Model Registry によるモデルのバージョニング

モデルのバージョニングにより、同じモデルの複数のバージョンを作成できます。これにより、モデルを整理して、どの変更がモデルにどのような影響を与えたかをモデルを見ながら把握できます。Model Registry を使用すると、モデルとそのすべてのバージョンを 1 つのビューで表示できます。特定のモデル バージョンをドリルダウンすると、そのパフォーマンスを正確に確認できます。

新しいモデル バージョンをインポートする

Model Registry から、既存モデルの新しいバージョンとしてモデルをインポートできます。

コンソール

  1. Google Cloud コンソールで、[Model Registry] ページに移動します。
    Model Registry に移動
  2. ページの上部で [インポート] を選択します。
  3. [新しいバージョンとしてインポート] を選択します。
  4. プルダウンから、新しいバージョンであるモデルを選択します。バージョンの説明を追加します(省略可)。
  5. 必要に応じて、このモデルをデフォルト バージョンとして設定します。モデルを予測に使用する場合は必ず、デフォルトのバージョンがあらかじめ選択されます(他のバージョンを選択することもできます)。
  6. 地域を選択します。
  7. [続行] を選択します。
  8. モデル設定で、使用するコンテナを定義します。モデル アーティファクトを新しいビルド済みコンテナにインポートするか、既存のカスタム コンテナにインポートするかを選択できます。コンテナの詳細については、Agent Platform にモデルをインポートするをご覧ください。
  9. [続行] を選択します。
  10. 省略可: モデルに説明可能性のサポートを追加します。
  11. [インポート] を選択します。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: プロジェクト ID。
  • LOCATION: ロケーション。
  • MODEL_DISPLAY_NAME: モデル名。
  • ARTIFACT_URI: モデル アーティファクトとそのサポート ファイルを含むディレクトリのパス。
  • IMAGE_URI: 予測を行うカスタム コンテナとして使用される Docker イメージ。
  • PARENT_MODEL: バージョンをアップロードするモデルのリソース名。

HTTP メソッドと URL:

POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/models:upload

リクエストの本文(JSON):

{

  "model": {
    "displayName": "MODEL_DISPLAY_NAME",
    "artifactUri": "ARTIFACT_URI",
    "containerSpec": {
       "imageUri": "IMAGE_URI"
    }
   },
 "parentModel": "PARENT_MODEL"
}

リクエストを送信するには、次のいずれかのオプションを展開します。

成功したことを示すステータス コード(2xx)と空のレスポンスが返されます。

Python

Python


from typing import List

from google.cloud import aiplatform


def upload_new_model_version_using_custom_training_pipeline(
    display_name: str,
    script_path: str,
    container_uri,
    model_serving_container_image_uri: str,
    dataset_id: str,
    replica_count: int,
    machine_type: str,
    accelerator_type: str,
    accelerator_count: int,
    parent_model: str,
    args: List[str],
    model_version_aliases: List[str],
    model_version_description: str,
    is_default_version: bool,
    project: str,
    location: str,
):
    """
    Uploads a new model version using a custom training pipeline.
    Args:
        display_name: The display name of the model version.
        script_path: The path to the Python script that trains the model.
        container_uri: The URI of the container to use for training.
        model_serving_container_image_uri: The URI of the serving container image to use.
        dataset_id: The ID of the dataset to use for training.
        replica_count: The number of replicas to use for training.
        machine_type: The machine type to use for training.
        accelerator_type: The accelerator type to use for training.
        accelerator_count: The number of accelerators to use for training.
        parent_model: The parent resource name of an existing model.
        args: A list of arguments to pass to the training script.
        model_version_aliases: The aliases of the model version to create.
        model_version_description: The description of the model version.
        is_default_version: Whether the model version is the default version.
        project: The project ID.
        location: The region name.
    Returns:
        The new version of the model.
    """
    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Create the training job.
    # This job will upload a new, non-default version of the my-training-job model
    job = aiplatform.CustomTrainingJob(
        display_name=display_name,
        script_path=script_path,
        container_uri=container_uri,
        model_serving_container_image_uri=model_serving_container_image_uri,
    )

    # Create dataset
    # This examples uses a TabularDataset, but you can use any dataset type.
    dataset = aiplatform.TabularDataset(dataset_id) if dataset_id else None

    # Run the training job.
    model = job.run(
        dataset=dataset,
        args=args,
        replica_count=replica_count,
        machine_type=machine_type,
        accelerator_type=accelerator_type,
        accelerator_count=accelerator_count,
        parent_model=parent_model,
        model_version_aliases=model_version_aliases,
        model_version_description=model_version_description,
        is_default_version=is_default_version,
    )

    return model

新しいモデル バージョンをトレーニングする

Model Registry から、新しいバージョンのモデルをトレーニングできます。

コンソール

Model Registry から、既存のモデルのバージョンを作成できます。トレーニング パイプラインでモデル バージョンを追加または作成する方法については、CustomJob とモデルのアップロードをご覧ください。

  1. Google Cloud コンソールで、[Model Registry] ページに移動します。
    Model Registry に移動
  2. ページの上部で [作成] を選択します。トレーニング方法の詳細を入力し、モデルのトレーニング方法を選択します。
  3. [続行] をクリックします。
  4. [モデルの詳細] で、[新しいバージョンをトレーニング] オプションを選択します。新しいバージョンを追加するモデルをプルダウンから選択します。バージョンの説明を追加します。[続行] をクリックします。
  5. [コンピューティングと料金] セクションで予算を入力し、準備ができたら [トレーニングを開始] を選択します。モデルのトレーニングが完了すると、Model Registry に新しいバージョンが表示されます。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • TRAINING_PIPELINE_NAME: trainingPipeline の表示名。
  • TRAINING_TASK_INPUT: トレーニング タスクのパラメータ。
  • PARENT_MODEL: バージョンをアップロードするモデルのリソース名。

HTTP メソッドと URL:

POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/trainingPipelines

リクエストの本文(JSON):

{
  "displayName": "TRAINING_PIPELINE_NAME",
  "trainingTaskDefinition": "gs://google-cloud-aiplatform/schema/trainingjob/definition/custom_task_1.0.0.yaml",
  "trainingTaskInputs":"TRAINING_TASK_INPUT"
  },
  "modelToUpload": {
    "displayName": "MODEL_DISPLAY_NAME",
    "containerSpec": {
       "imageUri": "IMAGE_URI"
    },
  },
  "parentModel": "PARENT_MODEL",

リクエストを送信するには、次のいずれかのオプションを展開します。

成功したことを示すステータス コード(2xx)と空のレスポンスが返されます。

Python

Python


from google.cloud import aiplatform


def create_default_model_sample(model_id: str, project: str, location: str):
    """
    Initialize a Model resource to represent an existing model version with alias 'default'.
    Args:
        model_id: The ID of the model to initialize. Parent resource name of the model is also accepted.
        project: The project ID.
        location: The region name.
    Returns:
        Model resource.
    """
    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Initialize the Model resource with the ID 'model_id'. The parent_name of the Model resource can be also
    # 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
    default_model = aiplatform.Model(model_name=model_id)

    return default_model

モデルのすべてのバージョンのリストを表示する方法

モデル バージョンの詳細ページから、モデルタイプに応じて、モデルのデプロイとテスト、バッチ推論の設定、評価を行うことができます。また、モデル バージョンのトレーニングに使用されたデータセットをバージョンの詳細ページに直接表示することもできます。

コンソール

Model Registry では、モデルのすべてのバージョンのリストを表示できます。これにより、一目で状況を把握し、モデルを整理できます。

  1. Google Cloud コンソールで、[Model Registry] ページに移動します。
    Model Registry に移動
  2. [名前] 列で、複数のバージョンを持つモデルの名前を選択します。バージョンのページが開きます。
  3. すべてのバージョンとそれに関連するバージョン ID のリストが表示されます。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: このモデルに関連付けられたプロジェクト ID。
  • LOCATION: Agent Platform を使用しているリージョン。
  • MODEL_ID: 特定のモデルに関連付けられた ID。

HTTP メソッドと URL:

GET https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/models/MODEL_ID

リクエストを送信するには、次のいずれかのオプションを展開します。

成功したことを示すステータス コード(2xx)と空のレスポンスが返されます。

Python

Python


from google.cloud import aiplatform


def list_model_versions_sample(model_id: str, project: str, location: str):
    """
    List all model versions of a model.
    Args:
        model_id: The ID of the model to list. Parent resource name of the model is also accepted.
        project: The project ID.
        location: The region name.
    Returns:
        versions: List of model versions.
    """
    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also
    # 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
    model_registry = aiplatform.models.ModelRegistry(model=model_id)

    # List all model versions of the model.
    versions = model_registry.list_versions()

    return versions

モデル バージョンの詳細の表示方法

Model Registry で、自分のモデルとすべてのモデル バージョンを確認できます。Model Registry からモデルを選択すると、モデルの詳細と特定のバージョンの詳細が詳細ページに表示されます。この詳細画面から、モデル バージョンの評価とテスト、バッチ推論の実行、オンライン推論用エンドポイントへのモデルのデプロイを行うことができます。

コンソール

モデルの詳細ページを表示するには、次の操作を行います。バージョンの詳細を表示するには、バージョン名をクリックします。

  1. Google Cloud コンソールで、[Model Registry] ページに移動します。
    Model Registry に移動
  2. Gemini Enterprise Agent Platform Model Registry でモデル名をクリックして、モデルの詳細ページを開きます。
  3. すべてのバージョンとそれに関連するバージョン ID のリストが表示されます。モデル バージョンが行ごとに表示されます。モデル バージョンの詳細には、バージョン ID、モデル エイリアス、ステータス、説明、ラベルが含まれます。
  4. いずれかのモデル バージョンの詳細を表示するには、バージョン ID を選択します。モデルの詳細ページが開きます。
  5. 詳細ページでは、評価、デプロイ、テスト、バッチ予測の使用、バージョンの詳細確認を行えます。 また、このページから Agent Platform Model Evaluation を使用してモデル バージョンを比較できます。

Python

Python


from google.cloud import aiplatform


def get_model_version_info_sample(
    model_id: str, version_id: str, project: str, location: str
):
    """
    Get model version info.
    Args:
        model_id: The ID of the model.
        version_id: The version ID of the model version.
        project: The project ID.
        location: The region name.
    Returns:
        VersionInfo resource.
    """

    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Initialize the Model Registry resource with the ID 'model_id'.The parent_name of Model resource can be also
    # 'projects/<your-project-id>/locations/<your-region>/models/<your-model-id>'
    model_registry = aiplatform.models.ModelRegistry(model=model_id)

    # Get model version info with the version 'version_id'.
    model_version_info = model_registry.get_version_info(version=version_id)

    return model_version_info