library(googleAuthR)
library(googleCloudVertexAIR)

options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/cloud-platform")

gar_auth_service(json_file = Sys.getenv("GAR_SERVICE_JSON"))

Set global arguements

projectId <- Sys.getenv("GCVA_DEFAULT_PROJECT_ID")
gcva_region_set(region = "us-central1")
## 2024-07-08 12:34:59.807027> Region set to 'us-central1'
gcva_project_set(projectId = projectId)
## 2024-07-08 12:34:59.807553> ProjectId set to 'gc-vertex-ai-r'
# hard code model that we know has a state = completed for demonstration purposes.
(model <- Sys.getenv("GCVA_TEST_MODEL_NAME"))
## [1] ""

Make the batch prediction request

set constants

(bq_source_uri <- sprintf("bq://%s.california_housing.batch_02", projectId))
## [1] "bq://gc-vertex-ai-r.california_housing.batch_02"
(bq_destination_prefix <- sprintf("bq://%s.california_housing", projectId))
## [1] "bq://gc-vertex-ai-r.california_housing"

execute request

batch_prediction_job <- gcva_batch_predict(
  jobDisplayName = "california-housing-batch-02",
  model = model, 
  bigquerySource = bq_source_uri,
  instancesFormat = "bigquery",
  predictionsFormat = "bigquery",
  bigqueryDestinationPrefix = bq_destination_prefix
)

batch_prediction_job

Get a batch prediction job

To view more details and current state.

gcva_batch_prediction_job(
  batchPredictionJob = Sys.getenv("GCVA_BATCH_PREDICTION")
  )
## $name
## [1] "projects/442003009360/locations/us-central1/batchPredictionJobs/1215288140596510720"
## 
## $displayName
## [1] "california-housing-batch-02"
## 
## $model
## [1] "projects/442003009360/locations/us-central1/models/2734102788232445952"
## 
## $inputConfig
## $inputConfig$instancesFormat
## [1] "bigquery"
## 
## $inputConfig$bigquerySource
## $inputConfig$bigquerySource$inputUri
## [1] "bq://gc-vertex-ai-r.california_housing.batch_02"
## 
## 
## 
## $outputConfig
## $outputConfig$predictionsFormat
## [1] "bigquery"
## 
## $outputConfig$bigqueryDestination
## $outputConfig$bigqueryDestination$outputUri
## [1] "bq://gc-vertex-ai-r.california_housing"
## 
## 
## 
## $dedicatedResources
## $dedicatedResources$machineSpec
## $dedicatedResources$machineSpec$machineType
## [1] "n1-highmem-8"
## 
## 
## $dedicatedResources$startingReplicaCount
## [1] 40
## 
## $dedicatedResources$maxReplicaCount
## [1] 40
## 
## 
## $manualBatchTuningParameters
## $manualBatchTuningParameters$batchSize
## [1] 1000
## 
## 
## $outputInfo
## $outputInfo$bigqueryOutputDataset
## [1] "bq://gc-vertex-ai-r.california_housing"
## 
## $outputInfo$bigqueryOutputTable
## [1] "predictions_2022_12_17T06_43_18_132Z_951"
## 
## 
## $state
## [1] "JOB_STATE_SUCCEEDED"
## 
## $completionStats
## $completionStats$successfulCount
## [1] "10"
## 
## 
## $createTime
## [1] "2022-12-17T14:43:18.157716Z"
## 
## $startTime
## [1] "2022-12-17T14:43:18.215815Z"
## 
## $endTime
## [1] "2022-12-17T15:03:39Z"
## 
## $updateTime
## [1] "2022-12-17T15:07:01.161203Z"
## 
## $labels
## $labels$vertex_product_name
## [1] "vertex_tabular"
## 
## 
## $modelVersionId
## [1] "1"
## 
## attr(,"class")
## [1] "gcva_batchPredictionJob"