I'm attempting to deploy a text classification model I trained with Vertex AI on the Google Cloud Platform using the Python SDK.
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>",
)
Unfortunately, when I run this code, I receive this error after the endpoint.deploy is triggered:
google.api_core.exceptions.InvalidArgument: 400 'dedicated_resources' is not supported for Model...
followed by the model location.
Note the places I've swapped my values with <***> to hide my local workspace variables.
You encounter the error since it is not possible to assign a custom machine to a Text Classification model. Only custom models and AutoML tabular models can use custom machines as per documentation. For AutoML models aside from tabular models, Vertex AI automatically configures the machine type.
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.
The workaround for this is to remove the machine related parameters on your endpoint.deploy()
and you should be able to deploy the model.
print("Deploying endpoint")
endpoint.deploy(model)