从 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

使用 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. 选择删除版本。当您删除版本时,所有关联的模型评估都会被删除。

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
    )