繁体   English   中英

如何在不知道 Vertex AI 中的 id 的情况下从端点取消部署 model?

[英]How do I undeploy a model from an endpoint without knowing its id in Vertex AI?

我设法使用UndeployModelRequest从端点取消部署 model :

    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       
    
    undeploy_request = aiplatform_v1.types.UndeployModelRequest
                       (endpoint=end_point, deployed_model_id=deployed_model_id)

    client.undeploy_model(request=undeploy_request)

但这一切都取决于了解model_id 我希望能够在不知道模型 ID 的情况下从端点取消部署 model(每个端点永远只有一个 model)。 这是可能的,还是我可以通过某种方式从端点获取 model id?

您可以通过调用方法undeploy_all()从端点取消部署所有模型( 请参阅清理部分)。这里您不需要传递 model id。 此方法对您更有用,因为端点中只有一个 model。

以下是从特定端点取消部署所有模型的示例:

from google.cloud import aiplatform

def undeploy_model_from_endpoint(names):
    endpoints = aiplatform.Endpoint.list()
    for i in endpoints:
        if str(i.display_name)==names:
            i.undeploy_all()

undeploy_model_from_endpoint("Endpoint_name")

如果您希望从所有端点取消部署所有模型,只需删除if条件

endpoints = aiplatform.Endpoint.list()
for i in endpoints:
        i.undeploy_all()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM