Vertex AI Model Registry からモデルを削除する

不要になったモデルを Vertex AI Model Registry から削除する方法について説明します。

Vertex AI Model Registry から BigQuery ML を削除するには、まず BigQuery ML から削除する必要があります。詳細については、BigQuery ML と Vertex AI Model Registry をご覧ください。

エンドポイントに現在デプロイされているモデルを削除するには、まずデプロイを解除する必要があります。そうしないと、モデルを削除することはできません。

モデルを削除する

コンソール

  1. Google Cloud コンソールの Vertex AI セクションから [Model Registry] ページに移動します。

    [Model Registry] ページに移動

  2. 削除するモデルから [その他の操作] を選択します。

  3. [モデルを削除] を選択します。モデルを削除すると、関連するすべてのモデル バージョンと評価が Google Cloud プロジェクトから削除されます。

  4. 確認画面で [削除] をクリックします。

API

Vertex AI SDK for Python を使用してモデルを削除します。

Vertex AI SDK for Python


from google.cloud import aiplatform

def delete_model_sample(model_id: str, project: str, location: str):
    """
    Delete a Model resource.
    Args:
        model_id: The ID of the model to delete. Parent resource name of the model is also accepted.
        project: The project.
        location: The region name.
    Returns
        None.
    """
    # Initialize the client.
    aiplatform.init(project=project, location=location)

    # Get the model 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(model_name=model_id)

    # Delete the model.
    model.delete()

モデル バージョンを削除する

コンソール

  1. Google Cloud コンソールの Vertex AI セクションから [Model Registry] ページに移動します。

    [Model Registry] ページに移動

  2. モデルを開いて、モデルのバージョンを表示します。削除するバージョンを選択します。

  3. モデル バージョンのメニュー から [その他の操作] を選択します。

  4. [バージョンを削除] を選択します。バージョンを削除すると、関連するすべてのモデル評価が削除されます。

API

Vertex AI SDK for Python


from google.cloud import aiplatform

def delete_model_version_sample(
    model_id: str, version_id: str, project: str, location: str
):
    """
    Delete a Model version.
    Args:
        model_id: The ID of the model to delete. Parent resource name of the model is also accepted.
        version_id: The version ID or version alias of the model to delete.
        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)

    # Delete the model version with the version 'version'.
    model_registry.delete_version(version=version_id)

デフォルトのエイリアスを持つモデル バージョンを削除する

コンソール

  1. Model Registry でモデル名を選択して、モデル バージョンを表示します。
  2. 目的のバージョンを選択し、[操作] ボタン から [削除] をクリックします。デフォルトのエイリアス バージョンを削除しようとすると、警告が表示されます。別のバージョンをデフォルトとして設定します。
  3. モデルのデフォルトにするバージョンをプルダウンから選択します。
  4. 確認画面で [設定と削除] をクリックします。

API

Vertex AI SDK for 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
    )