从 Gemini Enterprise Agent Platform Model Registry 中删除模型

了解如何从 Gemini Enterprise Agent Platform Model Registry 中删除不再需要的模型。

如果要从 Gemini Enterprise Agent Platform Model Registry 中删除 BigQuery ML 模型,必须先从 BigQuery ML 中删除它。如需了解详情, 请参阅 BigQuery ML 和 Gemini Enterprise Agent Platform Model Registry

如果要删除已部署到端点的模型,需要先取消部署。否则,您将无法删除该模型。

删除模型

控制台

  1. 在控制台中,从 Agent Platform 部分进入 Model Registry 页面。 Google Cloud

    进入 Model Registry 页面

  2. 在要删除的模型上选择更多操作

  3. 选择删除模型。删除模型时,所有关联的模型版本和评估都会从 Google Cloud 项目中一并删除。

  4. 点击确认屏幕上的删除

gcloud

在使用下面的命令数据之前,请先进行以下替换:

  • MODEL_ID:您的模型的 ID。
  • PROJECT_ID:您的 Google Cloud 项目 ID
  • LOCATION:您的项目的区域。例如 us-central1。如果 API 端点网址中的区域与资源路径中的位置冲突,则系统会忽略路径中的位置。

执行以下命令:

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 版 Agent Platform 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。如果 API 端点网址中的区域与资源路径中的位置冲突,则系统会忽略路径中的位置。

执行以下命令:

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
    )