從 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. 按一下確認畫面上的「刪除」

gcloud

使用下列任何指令資料之前,請先替換以下項目:

  • MODEL_ID:模型的 ID。
  • PROJECT_ID:您的 Google Cloud 專案 ID
  • LOCATION:專案的區域。例如:us-central1

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud ai models delete MODEL_ID \
    --project=PROJECT_ID \
    --region=LOCATION

Windows (PowerShell)

gcloud ai models delete MODEL_ID `
    --project=PROJECT_ID `
    --region=LOCATION

Windows (cmd.exe)

gcloud ai models delete MODEL_ID ^
    --project=PROJECT_ID ^
    --region=LOCATION

API

使用 Python 適用的 Vertex AI SDK 刪除模型。

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. 選取「刪除版本」。刪除版本時,系統會一併刪除所有相關聯的模型評估。

gcloud

使用下列任何指令資料之前,請先替換以下項目:

  • MODEL_VERSION_ID:要刪除的模型版本 ID。
  • PROJECT_ID:您的 Google Cloud 專案 ID
  • LOCATION:專案的區域。例如:us-central1

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud ai models delete-version MODEL_VERSION_ID \
    --project=PROJECT_ID \
    --region=LOCATION

Windows (PowerShell)

gcloud ai models delete-version MODEL_VERSION_ID `
    --project=PROJECT_ID `
    --region=LOCATION

Windows (cmd.exe)

gcloud ai models delete-version MODEL_VERSION_ID ^
    --project=PROJECT_ID ^
    --region=LOCATION

API

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

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
    )