Batch Prediction¶
Serve batch predictions from your models using Vertex AI Batch Predictions.
Components:
|
Creates a Google Cloud Vertex BatchPredictionJob and waits for it to complete. |
-
v1.batch_predict_job.ModelBatchPredictOp(job_display_name: str, gcp_resources: dsl.OutputPath(str), batchpredictionjob: dsl.Output[google.VertexBatchPredictionJob], bigquery_output_table: dsl.Output[google.BQTable], gcs_output_directory: dsl.Output[system.Artifact], model: dsl.Input[google.VertexModel] =
None, unmanaged_container_model: dsl.Input[google.UnmanagedContainerModel] =None, location: str ='us-central1', instances_format: str ='jsonl', predictions_format: str ='jsonl', gcs_source_uris: list[str] =[], bigquery_source_input_uri: str ='', instance_type: str ='', key_field: str ='', included_fields: list[str] =[], excluded_fields: list[str] =[], model_parameters: dict[str, str] ={}, gcs_destination_output_uri_prefix: str ='', bigquery_destination_output_uri: str ='', machine_type: str ='', accelerator_type: str ='', accelerator_count: int =0, starting_replica_count: int =0, max_replica_count: int =0, manual_batch_tuning_parameters_batch_size: int =0, generate_explanation: bool =False, explanation_metadata: dict[str, str] ={}, explanation_parameters: dict[str, str] ={}, labels: dict[str, str] ={}, encryption_spec_key_name: str ='', project: str ='{{$.pipeline_google_cloud_project_id}}')¶ Creates a Google Cloud Vertex BatchPredictionJob and waits for it to complete.
For more details, see BatchPredictionJob.Create.
- Parameters¶
given, must be one of the Model’s supportedInputStorageFormats. For more details about this input config, see InputConfig :param predictions_format: The format in which Vertex AI gives the predictions. Must be one of the Model’s supportedOutputStorageFormats. For more details about this output config, see OutputConfig. :param model: The Model used to get predictions via this job. Must share the same ancestor Location. Starting this job has no impact on any existing deployments of the Model and their resources. Either this or
unmanaged_container_modelmust be specified. :param unmanaged_container_model: The unmanaged container model used to get predictions via this job. This should be used for models that are not uploaded to Vertex. Either this or model must be specified. :param gcs_source_uris: Google Cloud Storage URI(-s) to your instances to run batch prediction on. They must matchinstances_format. May contain wildcards. For more information on wildcards, see WildcardNames. For more details about this input config, see InputConfig. :param bigquery_source_input_uri: BigQuery URI to a table, up to 2000 characters long. For example:projectId.bqDatasetId.bqTableIdFor more details about this input config, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.batchPredictionJobs#InputConfig. :param model_parameters: The parameters that govern the predictions. The schema of the parameters :param instance_type: The format of the instance that the Model accepts. Vertex AI will convert compatible InstancesFormat to the specified format. Supported values are:object: Each input is converted to JSON object format. * Forbigquery, each row is converted to an object. * Forjsonl, each line of the JSONL input must be an object. * Does not apply tocsv,file-list,tf-record, ortf-record-gzip.array: Each input is converted to JSON array format. * Forbigquery, each row is converted to an array. The order of columns is determined by the BigQuery column order, unless included_fields is populated.included_fieldsmust be populated for specifying field orders. * Forjsonl, if each line of the JSONL input is an object,included_fieldsmust be populated for specifying field orders. * Does not apply tocsv,file-list,tf-record, ortf-record-gzip. If not specified, Vertex AI converts the batch prediction input as follows: * Forbigqueryandcsv, the behavior is the same asarray. The order of columns is the same as defined in the file or table, unless included_fields is populated. * Forjsonl, the prediction instance format is determined by each line of the input. * Fortf-record/tf-record-gzip, each record will be converted to an object in the format of{"b64": <value>}, where<value>is the Base64-encoded string of the content of the record. * Forfile-list, each file in the list will be converted to an object in the format of{"b64": <value>}, where<value>is the Base64-encoded string of the content of the file. :param key_field: The name of the field that is considered as a key. The values identified by the key field is not included in the transformed instances that is sent to the Model. This is similar to specifying this name of the field in excluded_fields. In addition, the batch prediction output will not include the instances. Instead the output will only include the value of the key field, in a field namedkeyin the output: * Forjsonloutput format, the output will have akeyfield instead of theinstancefield. * Forcsv/bigqueryoutput format, the output will have have akeycolumn instead of the instance feature columns. The input must be JSONL with objects at each line, CSV, BigQuery or TfRecord. :param included_fields: Fields that will be included in the prediction instance that is sent to the Model. Ifinstance_typeisarray, the order of field names inincluded_fieldsalso determines the order of the values in the array. Whenincluded_fieldsis populated,excluded_fieldsmust be empty. The input must be JSONL with objects at each line, CSV, BigQuery or TfRecord. :param excluded_fields: Fields that will be excluded in the prediction instance that is sent to the Model. Excluded will be attached to the batch prediction output if key_field is not specified. Whenexcluded_fieldsis populated,included_fieldsmust be empty. The input must be JSONL with objects at each line, CSV, BigQuery or TfRecord. may be specified via the Model’sparameters_schema_uri. :param gcs_destination_output_uri_prefix: The Google Cloud Storage location of the directory where the output is to be written to. In the given directory a new directory is created. Its name isprediction-<model-display-name>-<job-create-time>, where timestamp is in YYYY-MM-DDThh:mm:ss.sssZ ISO-8601 format. Inside of it filespredictions_0001.<extension>,predictions_0002.<extension>, …,predictions_N.<extension>are created where<extension>depends on chosenpredictions_format, and N may equal 0001 and depends on the total number of successfully predicted instances. If the Model has bothinstanceandpredictionschemata defined then each such file contains predictions as per thepredictions_format. If prediction for any instance failed (partially or completely), then an additionalerrors_0001.<extension>,errors_0002.<extension>,…,errors_N.<extension>files are created (N depends on total number of failed predictions). These files contain the failed instances, as per their schema, followed by an additionalerrorfield which as value hasgoogle.rpc.Statuscontaining onlycodeandmessagefields. For more details about this output config, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.batchPredictionJobs#OutputConfig. :param bigquery_destination_output_uri: The BigQuery project location where the output is to be written to. In the given project a new dataset is created with nameprediction_<model-display-name>_<job-create-time>where is made BigQuery-dataset-name compatible (for example, most special characters become underscores), and timestamp is in YYYY_MM_DDThh_mm_ss_sssZ “based on ISO-8601” format. In the dataset two tables will be created,predictions, anderrors. If the Model has bothinstanceandpredictionschemata defined then the tables have columns as follows: Thepredictionstable contains instances for which the prediction succeeded, it has columns as per a concatenation of the Model’s instance and prediction schemata. Theerrorstable contains rows for which the prediction has failed, it has instance columns, as per the instance schema, followed by a single “errors” column, which as values has google.rpc.Status represented as a STRUCT, and containing onlycodeandmessage. For more details about this output config, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.batchPredictionJobs#OutputConfig. :param machine_type: The type of machine for running batch prediction on dedicated resources. If the Model supports DEDICATED_RESOURCES this config may be provided (and the job will use these resources). If the Model doesn’t support AUTOMATIC_RESOURCES, this config must be provided. For more details about the BatchDedicatedResources, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.batchPredictionJobs#BatchDedicatedResources. For more details about the machine spec, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/MachineSpec :param accelerator_type: The type of accelerator(s) that may be attached to the machine as peraccelerator_count. Only used ifmachine_typeis set. For more details about the machine spec, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/MachineSpec :param accelerator_count: The number of accelerators to attach to themachine_type. Only used ifmachine_typeis set. For more details about the machine spec, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/MachineSpec :param starting_replica_count: The number of machine replicas used at the start of the batch operation. If not set, Vertex AI decides starting number, not greater thanmax_replica_count. Only used ifmachine_typeis set. :param max_replica_count: The maximum number of machine replicas the batch operation may be scaled to. Only used ifmachine_typeis set. :param manual_batch_tuning_parameters_batch_size: The number of the records (e.g. instances) of the operation given in each batch to a machine replica. Machine type, and size of a single record should be considered when setting this parameter, higher value speeds up the batch operation’s execution, but too high value will result in a whole batch not fitting in a machine’s memory, and the whole operation will fail. :param generate_explanation: Generate explanation along with the batch prediction results. This will cause the batch prediction output to include explanations based on theprediction_format: -bigquery: output includes a column namedexplanation. The value is a struct that conforms to the [aiplatform.gapic.Explanation] object. -jsonl: The JSON objects on each line include an additional entry keyedexplanation. The value of the entry is a JSON object that conforms to the [aiplatform.gapic.Explanation] object. -csv: Generating explanations for CSV format is not supported. If this field is set to true, either the Model.explanation_spec or explanation_metadata and explanation_parameters must be populated. :param explanation_metadata: Explanation metadata configuration for this BatchPredictionJob. Can be specified only ifgenerate_explanationis set toTrue. This value overrides the value ofModel.explanation_metadata. All fields ofexplanation_metadataare optional in the request. If a field of theexplanation_metadataobject is not populated, the corresponding field of theModel.explanation_metadataobject is inherited. For more details, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/ExplanationSpec#explanationmetadata. :param explanation_parameters: Parameters to configure explaining for Model’s predictions. Can be specified only ifgenerate_explanationis set toTrue. This value overrides the value ofModel.explanation_parameters. All fields ofexplanation_parametersare optional in the request. If a field of theexplanation_parametersobject is not populated, the corresponding field of theModel.explanation_parametersobject is inherited. For more details, see https://cloud.google.com/vertex-ai/docs/reference/rest/v1/ExplanationSpec#ExplanationParameters. :param labels: The labels with user-defined metadata to organize your BatchPredictionJobs. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. International characters are allowed. See https://goo.gl/xmQnxf for more information and examples of labels. :param encryption_spec_key_name: Customer-managed encryption key options for a BatchPredictionJob. If this is set, then all resources created by the BatchPredictionJob will be encrypted with the provided encryption key. Has the form:projects/my-project/locations/my-location/keyRings/my-kr/cryptoKeys/my-key. The key needs to be in the same region as where the compute resource is created. :param project: Project to create the BatchPredictionJob. Defaults to the project in which the PipelineJob is run.- Returns¶
``batchpredictionjob: dsl.Output[google.VertexBatchPredictionJob]`` [**Deprecated. Use gcs_output_directory and bigquery_output_tableinstead.**] Artifact representation of the created batch prediction job.
gcs_output_directory: dsl.Output[system.Artifact]Artifact tracking the batch prediction job output. This is only available if gcs_destination_output_uri_prefix is specified.bigquery_output_table: dsl.Output[google.BQTable]Artifact tracking the batch prediction job output. This is only available if bigquery_output_table is specified.gcp_resources: dsl.OutputPath(str)Serialized gcp_resources proto tracking the batch prediction job. For more details, see https://github.com/kubeflow/pipelines/blob/master/components/google-cloud/google_cloud_pipeline_components/proto/README.md.