モデル バージョンのエイリアスの使用方法

モデル エイリアスは、モデルリソースのモデル バージョンを一意に識別できる「変更可能」で「名前付き」の参照です。エイリアスは、モデル バージョン間で移動できるため「変更可能」であり、ユーザー定義の任意の文字列であるため「名前付き」になります。モデル エイリアスを使用すると、モデル ID を確認することなく、特定のモデル バージョンを取得またはデプロイできます。この点で、Git の Docker タグまたはブランチの参照と同じように機能します。

Model Registry で新しいモデルを作成すると、最初のバージョンに自動的にデフォルトのエイリアスが割り当てられます。デフォルトのエイリアスは、ユーザーが特定のバージョンを指定せずにモデルでコマンドを実行するときに使用されるモデル バージョンです。デフォルトのエイリアスを使用するには、1 つのモデル バージョンが必要です。それ以外の点では、デフォルトのエイリアスは他のユーザー定義のエイリアスと同じように動作します。

Google Cloud コンソールのエイリアス マーカーにより、どのモデルが安定版でデプロイ可能なのか一目で把握できます。デフォルトのエイリアスのほかに、独自のカスタム エイリアスを作成して Model Registry 内のモデルに割り当てることができます。

Model Registry では、エイリアス列を見ると、デフォルトのエイリアスがあるモデル バージョンを確認できます。

エイリアス列とデフォルトのエイリアスタグ。

エイリアスを別のモデル バージョンに再割り当てする場合、エイリアスを別のバージョンに簡単に移動できます。

エイリアスを使用する際の考慮事項:

  • バージョンのエイリアスは一意である必要があります。エイリアスは、モデルごとに一度に 1 つのバージョンにのみ割り当てることができます。
  • バージョンのエイリアスは数値以外で指定してください。
  • 本番環境用のモデル バージョンを指定しない場合、デフォルトのモデルが使用されます。
  • エイリアスはラベルとは異なります。モデルラベルについて詳しくは、こちらをご覧ください。
  • 別のモデル バージョンで使用されている既存のエイリアスを適用すると、そのエイリアスはそのバージョンから削除されます。

モデル バージョンをデフォルトに設定する

  1. Google Cloud コンソールで、Vertex AI [Model Registry] ページに移動します。

    [Model Registry] ページに移動

  2. Model Registry から、編集するモデルの名前を選択します。モデルの詳細ウィンドウが開きます。すべてのモデル バージョンが一覧表示されます。モデル バージョンの 1 つにデフォルトのエイリアスがあります。

  3. デフォルト バージョンを割り当てるモデル バージョンの [アクション] ボタンを選択します。

  4. [既定に設定] をクリックします。

モデル バージョンにエイリアスを追加する

  1. Google Cloud コンソールで、Vertex AI [Model Registry] ページに移動します。

    [Model Registry] ページに移動

  2. Model Registry から、編集するモデルの名前を選択します。モデルの詳細ウィンドウが開きます。

  3. 詳細ページで、目的のモデル バージョンを選択し、[さらに表示] をクリックします。

  4. [エイリアスを編集] をクリックします。[新しく追加] を選択します。

  5. エイリアスを編集: [エイリアスを追加] をクリックして、モデル バージョンに追加するエイリアスの名前を入力します。

  6. [保存] をクリックします。

エイリアスを追加した新しいモデル バージョンをアップロードする

API

Python


from typing import List

from google.cloud import aiplatform

def upload_new_aliased_model_version_sample(
    parent_name: str,
    artifact_uri: str,
    serving_container_image: str,
    is_default_version: bool,
    version_aliases: List[str],
    version_description: str,
    project: str,
    location: str,
):
    """
    Uploads a new aliased version of a model with ID 'model_id'.
    Args:
        parent_name: The parent resource name of an existing model.
        artifact_uri: The URI of the model artifact to upload.
        serving_container_image: The name of the serving container image to use.
        is_default_version: Whether this version is the default version of the model.
        version_aliases: The aliases of the model version.
        version_description: The description of the model 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)

    # Upload a new aliased version of the Model 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 = aiplatform.Model.upload(
        artifact_uri=artifact_uri,
        serving_container_image=serving_container_image,
        parent_name=parent_name,
        is_default_version=is_default_version,
        version_aliases=version_aliases,
        version_description=version_description,
    )

    return model

モデル エイリアスを削除する

デフォルト エイリアスが割り当てられたモデル バージョンを削除すると、そのエイリアスは次に最も新しいバージョンに自動的に割り当てられます。

コンソール

  1. Google Cloud コンソールで、Vertex AI [Model Registry] ページに移動します。

    [Model Registry] ページに移動

  2. Model Registry から、編集するモデルの名前を選択します。モデルの詳細ウィンドウが開きます。

  3. 詳細ページで、モデル バージョンの [アクション] ボタンをクリックします。

  4. [エイリアスを編集] をクリックします。

  5. モデル バージョンに関連付けられているエイリアスのリストが表示されます。ラベルの [エイリアス] テキスト ボックスの右にカーソルを合わせると、削除アイコンが表示されます。

  6. 削除するアドレスの削除アイコンをクリックします。

  7. [保存] をクリックします。

API

Python


from typing import List

from google.cloud import aiplatform

def delete_aliases_model_version_sample(
    model_id: str,
    version_aliases: List[str],
    version_id: str,
    project: str,
    location: str,
):
    """
    Delete aliases to a model version.
    Args:
        model_id: The ID of the model.
        version_aliases: The version aliases to assign.
        version_id: The version ID of the model to assign the aliases to.
        project: The project ID.
        location: The region name.
    Returns
        None.
    """
    # 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)

    # Remove the version aliases to the model version with the version 'version'.
    model_registry.remove_version_aliases(
        target_aliases=version_aliases, version=version_id
    )