從 Vertex AI Model Registry 中刪除模型

瞭解如何從 Vertex AI Model Registry 中刪除不再需要的模型。

如果您想從 Vertex AI Model Registry 刪除 BigQuery ML,必須先從 BigQuery ML 刪除該模型。如需瞭解詳情,請參閱 BigQuery ML 和 Vertex AI Model Registry

如要刪除已部署至端點的模型,請先取消部署。否則您將無法刪除模型。

已調校的 Gemini 模型無法刪除。不過,只要處於閒置狀態,就不會產生任何推論費用。

刪除模型

控制台

  1. 在 Google Cloud 控制台的 Vertex AI 專區中,前往「Model Registry」頁面。

    前往「Model Registry」頁面

  2. 在要刪除的模型中選取「更多動作」

  3. 選取「Delete model」(刪除模型)。刪除模型後,所有相關聯的模型版本和評估結果都會從 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 適用的 Vertex AI SDK


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 適用的 Vertex AI SDK


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 適用的 Vertex AI SDK


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
    )