如何使用 Python 删除部署到 Unified AI Platform 端点的模型?
How to delete Models deployed to an endpoint on Unified AI Platform using Python?
我已在 Unified Cloud AI Platform 上成功创建了一个端点并为其部署了两个 Model
- Model B
和 Model C
分别具有 20% 和 80% 的流量.我之前部署了第三个 Model
- Model A
,现在流量为 0%。
现在,在云控制台 (UI) 上,我可以选择 Undeploy 这个 Model A
我可以成功地这样做。但是我无法弄清楚如何使用 Python 客户端 API.
来做到这一点
here 提供的文档不足以理解我们如何做到这一点。任何帮助将不胜感激。
AI Platform Unified 的文档还没有关于如何在端点中取消部署模型的示例。您可以参考AI platform unified rpc reference目前可用的服务。这是相关代码:
注意:不要忘记在 运行 代码之前更新 end_point(端点 ID)、项目(项目 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')
我已在 Unified Cloud AI Platform 上成功创建了一个端点并为其部署了两个 Model
- Model B
和 Model C
分别具有 20% 和 80% 的流量.我之前部署了第三个 Model
- Model A
,现在流量为 0%。
现在,在云控制台 (UI) 上,我可以选择 Undeploy 这个 Model A
我可以成功地这样做。但是我无法弄清楚如何使用 Python 客户端 API.
here 提供的文档不足以理解我们如何做到这一点。任何帮助将不胜感激。
AI Platform Unified 的文档还没有关于如何在端点中取消部署模型的示例。您可以参考AI platform unified rpc reference目前可用的服务。这是相关代码:
注意:不要忘记在 运行 代码之前更新 end_point(端点 ID)、项目(项目 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')