-1

i am trying to deploy a model in Vertex AI pipeline component using DeployModelRequest. I try to get the model using GetModelRequest

    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)       
    
    deploy_request = aiplatform_v1.types.DeployModelRequest(endpoint=end_point, 
                                                                deployed_model=model_info)
    client.deploy_model(request=deploy_request)

but this gives:

TypeError: Parameter to MergeFrom() must be instance of same class: expected 
google.cloud.aiplatform.v1.DeployedModel got Model

I have also tried deployed_model=model_info.deployed_models[0] but this gave:

TypeError: Parameter to MergeFrom() must be instance of same class: expected
 google.cloud.aiplatform.v1.DeployedModel got DeployedModelRef.

So what do I use for deployed_model?

schoon
  • 2,858
  • 3
  • 46
  • 78
  • I'm unfamiliar with Vertex API so unable to be of much help but... A generally-good approach to understanding the shape of Google's services is to use [APIs Explorer](https://developers.google.com/apis-explorer) to search for service|method|type documentation. Unfortunately, Vertex API is not surfaced by APIs Explorer but it is documented [Vertex API](https://cloud.google.com/vertex-ai/docs/reference). – DazWilkin Sep 15 '22 at 15:40
  • The method [`projects.locations.models.get`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.models/get) returns a [`Model`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.models#Model) – DazWilkin Sep 15 '22 at 15:41
  • The method [`projects.locations.endpoints.deployModel`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/deployModel) [request](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/deployModel#request-body) includes a [`DeployedModel`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints#DeployedModel). – DazWilkin Sep 15 '22 at 15:41
  • Hopefully you can determine how to create the latter from the former. – DazWilkin Sep 15 '22 at 15:41
  • Hi @schoon, Is your issue resolved? – Prajna Rai T Sep 16 '22 at 09:13
  • Nope. I have tried some alternatives and failed so far. – schoon Sep 16 '22 at 10:22

1 Answers1

1

As simple as:

machine_spec = MachineSpec(machine_type="n1-standard-2")
dedicated_resources = DedicatedResources(machine_spec=machine_spec, 
                                         min_replica_count=1, 
                                         max_replica_count=1)
depmodel= DeployedModel(model=model_name, dedicated_resources=dedicated_resources) 

deploy_request = aiplatform_v1.types.DeployModelRequest(
                   endpoint=end_point, deployed_model=depmodel, 
                   traffic_split={'0':100})
client.deploy_model(request=deploy_request)
schoon
  • 2,858
  • 3
  • 46
  • 78