我正在尝试使用 Python SDK 在 Google Cloud Platform 上部署我使用 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...
后跟模型位置。
注意我用 <***> 交换了我的值以隐藏我的本地工作区变量的地方。