0

I've built a model in VertexAI and have deployed it to an endpoint. I'm trying to use tabular data stored in GBQ as input for this model. I've found this function -- create a batch prediction in GBQ using Python -- in Google's documentation:

from google.cloud import aiplatform_v1beta1
from google.protobuf import json_format
from google.protobuf.struct_pb2 import Value


def create_batch_prediction_job_bigquery_sample(
    project: str,
    display_name: str,
    model_name: str,
    instances_format: str,
    bigquery_source_input_uri: str,
    predictions_format: str,
    bigquery_destination_output_uri: str,
    location: str = "us-central1",
    api_endpoint: str = "us-central1-aiplatform.googleapis.com",
):
    # The AI Platform services require regional API endpoints.
    client_options = {"api_endpoint": api_endpoint}
    # Initialize client that will be used to create and send requests.
    # This client only needs to be created once, and can be reused for multiple requests.
    client = aiplatform_v1beta1.JobServiceClient(client_options=client_options)
    model_parameters_dict = {}
    model_parameters = json_format.ParseDict(model_parameters_dict, Value())

    batch_prediction_job = {
        "display_name": display_name,
        # Format: 'projects/{project}/locations/{location}/models/{model_id}'
        "model": model_name,
        "model_parameters": model_parameters,
        "input_config": {
            "instances_format": instances_format,
            "bigquery_source": {"input_uri": bigquery_source_input_uri},
        },
        "output_config": {
            "predictions_format": predictions_format,
            "bigquery_destination": {"output_uri": bigquery_destination_output_uri},
        },
        # optional
        "generate_explanation": True,
    }
    parent = f"projects/{project}/locations/{location}"
    response = client.create_batch_prediction_job(
        parent=parent, batch_prediction_job=batch_prediction_job
    )
    print("response:", response)

When I run this with the requisite input, I get the following error:

InvalidArgument: 400 List of found errors:  1.Field: batch_prediction_job.model; Message: Invalid Model resource name.   [field_violations {
  field: "batch_prediction_job.model"
  description: "Invalid Model resource name."
}
]

I'm pretty confused as to what's wrong -- I'm naming the correct model, and the other inputs (not listed due to nature of work) are accurate.

  • 1
    Try listing your models using this [list_models()](https://cloud.google.com/python/docs/reference/aiplatform/latest/google.cloud.aiplatform_v1beta1.services.model_service.ModelServiceClient#google_cloud_aiplatform_v1beta1_services_model_service_ModelServiceClient_list_models) and cross check the value of `model_name` to see if they are equal. – Ricco D May 06 '22 at 03:31
  • 1
    Could you please share your `model_name` format? Does it adhere to `projects/{project}/locations/{location}/models/{model_id}`? Or is it only the `{model_id}` part? Or are you inputting the actual "model name" that shows up in the UI? – sneekiesnek Mar 31 '23 at 10:26

0 Answers0