Google Cloud Vertex AI - 模型不支持 400 'dedicated_resources'

Google Cloud Vertex AI - 400 'dedicated_resources' is not supported for Model

我正在尝试使用 Python SDK 在 Google 云平台上部署我使用 Vertex AI 训练的文本分类模型。

from google.cloud import aiplatform

import os

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "<key location>"

def create_endpoint(
    project_id: str,
    display_name: str,
    location: str,
    sync: bool = True,
):
    endpoint = aiplatform.Endpoint.create(
        display_name=display_name, project=project_id, location=location,
    )

    print(endpoint.display_name)
    print(endpoint.resource_name)
    return endpoint

def deploy_model(project_id, location, model_id):
    model_location = "projects/{}/locations/{}/models/{}".format(project_id, location, model_id)

    print("Initializing Vertex AI")
    aiplatform.init(project=project_id, location=location)

    print("Getting model from {}".format(model_location))
    model = aiplatform.Model(model_location)

    print("Creating endpoint.")
    endpoint = create_endpoint(project_id, "{}_endpoint".format(model_id), location)

    print("Deploying endpoint")
    endpoint.deploy(
        model,
        machine_type="n1-standard-4",
        min_replica_count=1,
        max_replica_count=5,
        accelerator_type='NVIDIA_TESLA_K80',
        accelerator_count=1
    )

    return endpoint

endpoint = deploy_model(
    "<project name>",
    "us-central1",
    "<model id>",
)

不幸的是,当我 运行 这段代码时,我在 endpoint.deploy 被触发后收到这个错误: google.api_core.exceptions.InvalidArgument: 400 'dedicated_resources' is not supported for Model... 后跟模型位置。

注意我用 <***> 交换值以隐藏本地工作区变量的地方。

您遇到错误是因为无法将自定义机器分配给文本分类模型。根据 documentation,只有自定义模型和 AutoML 表格模型可以使用自定义机器。对于表格模型之外的 AutoML 模型,Vertex AI 会自动配置机器类型。

If you want to use a custom-trained model or an AutoML tabular model to serve online predictions, you must specify a machine type when you deploy the Model resource as a DeployedModel to an Endpoint. For other types of AutoML models, Vertex AI configures the machine types automatically.

解决方法是删除 endpoint.deploy() 上与机器相关的参数,您应该能够部署模型。

print("Deploying endpoint")
endpoint.deploy(model)