如何使用Python删除部署到统一AI平台上端点的模型?

如何使用Python删除部署到统一AI平台上端点的模型?,python,google-cloud-platform,google-cloud-ml,google-ai-platform,Python,Google Cloud Platform,Google Cloud Ml,Google Ai Platform,我已经成功地在统一云AI平台上创建了一个端点,并在其上部署了两个Models-Model B和Model C,流量分别为20%和80%。我有第三个型号-型号a,我以前部署过,现在流量为0% 现在,在云控制台(UI)上,我可以选择取消部署这个模型A,我可以成功地这样做。但是,我不知道如何使用Python客户端API来实现这一点 以上提供的文件不足以理解我们如何做到这一点。任何帮助都将不胜感激。AI Platform Unified的文档中还没有关于如何在端点中取消部署模型的示例。您现在可以参考有关

我已经成功地在统一云AI平台上创建了一个端点,并在其上部署了两个
Model
s-
Model B
Model C
,流量分别为20%和80%。我有第三个
型号
-
型号a
,我以前部署过,现在流量为0%

现在,在云控制台(UI)上,我可以选择取消部署这个
模型A
,我可以成功地这样做。但是,我不知道如何使用Python客户端API来实现这一点


以上提供的文件不足以理解我们如何做到这一点。任何帮助都将不胜感激。

AI Platform Unified的文档中还没有关于如何在端点中取消部署模型的示例。您现在可以参考有关可用服务的信息。以下是代码:

注意:在运行代码之前,不要忘记更新end_point(endpoint ID)、project(project ID)、model_ID的值

from google.cloud import aiplatform
from google.cloud import aiplatform_v1


def undeploy_model_in_endpoint(
    end_point: str,
    project: str,
    model_id: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
    timeout: int = 7200,
):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.EndpointServiceClient(client_options=client_options)
    client_model = aiplatform_v1.services.model_service.ModelServiceClient(client_options=client_options)

    # Get deployed_model_id
    model_name = f'projects/{project}/locations/{location}/models/{model_id}'
    model_request = aiplatform_v1.types.GetModelRequest(name=model_name)
    model_info = client_model.get_model(request=model_request)
    deployed_models_info = model_info.deployed_models
    deployed_model_id=model_info.deployed_models[0].deployed_model_id

    name=f'projects/{project}/locations/{location}/endpoints/{end_point}'

    undeploy_request = aiplatform_v1.types.UndeployModelRequest(endpoint=name,deployed_model_id=deployed_model_id)
    client.undeploy_model(request=undeploy_request)

undeploy_model_in_endpoint(end_point='your-endpoint-id',project='your-project-id',model_id='your-model-id')

AI Platform Unified的文档还没有关于如何在端点中取消部署模型的示例。您现在可以参考有关可用服务的信息。以下是代码:

注意:在运行代码之前,不要忘记更新end_point(endpoint ID)、project(project ID)、model_ID的值

from google.cloud import aiplatform
from google.cloud import aiplatform_v1


def undeploy_model_in_endpoint(
    end_point: str,
    project: str,
    model_id: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
    timeout: int = 7200,
):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform.gapic.EndpointServiceClient(client_options=client_options)
    client_model = aiplatform_v1.services.model_service.ModelServiceClient(client_options=client_options)

    # Get deployed_model_id
    model_name = f'projects/{project}/locations/{location}/models/{model_id}'
    model_request = aiplatform_v1.types.GetModelRequest(name=model_name)
    model_info = client_model.get_model(request=model_request)
    deployed_models_info = model_info.deployed_models
    deployed_model_id=model_info.deployed_models[0].deployed_model_id

    name=f'projects/{project}/locations/{location}/endpoints/{end_point}'

    undeploy_request = aiplatform_v1.types.UndeployModelRequest(endpoint=name,deployed_model_id=deployed_model_id)
    client.undeploy_model(request=undeploy_request)

undeploy_model_in_endpoint(end_point='your-endpoint-id',project='your-project-id',model_id='your-model-id')

您提到可以在控制台中“取消部署”。使用python的原因是什么?有什么具体原因吗?我们正在寻找一种自动“取消部署”不再相关的模型的方法。您提到可以在控制台中“取消部署”。使用python的原因是什么?有什么具体原因吗?我们正在寻找一种自动“取消部署”不再相关的模型的方法。