Trying to get a Vertex AI prediction in BigQuery using Python

584 views Asked by At

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.

0

There are 0 answers