Manage BigQuery ML models in Vertex AI

You can register BigQuery ML models with the Vertex AI Model Registry, in order to manage them alongside your Vertex AI models without needing to export them. When you register models with Model Registry, you can version, evaluate, and deploy the models for online prediction by using a single interface, and without needing a serving container. If you aren't familiar with Vertex AI and how it integrates with BigQuery ML, see Vertex AI for BigQuery users.

To learn more about Vertex AI prediction, see Overview of getting predictions on Vertex AI.

To learn how to manage your BigQuery ML models from Vertex AI Model Registry, see Introduction to Vertex AI Model Registry.

Before you begin

Enable the Vertex AI API.

Enable the API

Required permissions

To get the permissions that you need to register BigQuery ML models to the Model Registry, ask your administrator to grant you the Vertex AI Administrator (roles/aiplatform.admin) IAM role on your project. For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

Register models

When you create a BigQuery ML model by using the CREATE MODEL statement, you can use the following options to register the model to the Model Registry:

  • MODEL_REGISTRY: register the model to the Model Registry.
  • VERTEX_AI_MODEL_ID: specify a model ID to use for the model in the Model Registry. The model ID is associated with your BigQuery ML model, and is visible from the Model Registry. Each BigQuery ML model can only be registered to one model ID in the Model Registry.
  • VERTEX_AI_MODEL_VERSION_ALIASES: specify one or more model version aliases, which you can use to streamline deployment, manage models, and enable Vertex Explainable AI on models.

If you set the MODEL_REGISTRY option when creating a model, the model is registered to the Model Registry, and automatically displays there once it has completed training in BigQuery ML. You can use the Source column in the Model Registry page of the Google Cloud console to see where a model is sourced from.

Once a BigQuery ML model is registered, you can use the following Model Registry capabilities with your model:

All models created using BigQuery ML still display in the BigQuery user interface, regardless of whether they are registered to the Model Registry.

The following example shows how to create and register a k-means model:

CREATE OR REPLACE MODEL `mydataset.my_kmeans_model`
  MODEL_TYPE = 'KMEANS',
  MODEL_REGISTRY = 'VERTEX_AI',
  VERTEX_AI_MODEL_ID = 'customer_clustering';

Register an existing BigQuery ML model to the Model Registry

If you don't register a model to Vertex AI when you create it, you can use SQL, the bq command-line tool, or the BigQuery API to register it afterwards.

The following examples show how to register an existing model:

SQL

Use the ALTER MODEL statement:

ALTER MODEL IF EXISTS mymodel SET OPTIONS (vertex_ai_model_id='my_vertex_ai_model_id');

bq

Use the bq update command with the --model flag:

  bq update --model --vertex_ai_model_id 'my_vertex_ai_model_id' myproject:mydataset.mymodel

API

Use the models.patch method. Pass in an Model object that contains a trainingRuns object with a populated vertexAiModelId field:

{
  "trainingRuns": [
    {
      "vertexAiModelId": my_vertex_ai_model_id
    }
}

Register multiple versions of BigQuery ML models

The first BigQuery ML model that you register under a given model ID displays as version 1 of that model in the Model Registry. You can register additional BigQuery ML models as different versions of that registered model by specifying the same Vertex AI model ID when you create or alter those BigQuery ML models.

For example, you could create model1 in BigQuery ML and register it in Model Registry as regression_model. model1 displays as version 1 of regression_model in Model Registry. If you then create model2 in BigQuery ML and register it in Model Registry as regression_model. model2 displays as version 2 of regression_model in Model Registry.

If you create or replace a BigQuery ML model and use a BigQuery ML model name that is already associated with a model in the Model Registry, the existing Model Registry model version is deleted and replaced with the new model. Building on the prior example, if you create or replace model2 in BigQuery ML by using the CREATE OR REPLACE MODEL statement with the MODEL_REGISTRY and VERTEX_AI_MODEL_ID options, version 2 of regression_model in the Model Registry is replaced, and Model Registry displays version 1 and version 3 of regression_model model.

Change the model ID of a registered BigQuery ML model

Once a BigQuery ML model is registered to the Model Registry, you can't change the VERTEX_AI_MODEL_ID value. To register the model with a new VERTEX_AI_MODEL_ID, use one of the following options:

  • Delete the model and recreate it, specifying a new value for the VERTEX_AI_MODEL_ID option. This approach incurs re-training costs.

  • Copy the model, and then use the ALTER MODEL statement to register the new model with a new VERTEX_AI_MODEL_ID value.

Location considerations

If you register a multi-region BigQuery ML model to Model Registry, the model becomes a regional model in Vertex AI. A BigQuery ML US multi-region model is synced to Vertex AI (us-central1) and a BigQuery ML multi-region EU model is synced to Vertex AI (europe-west4). For single region models, there are no changes.

For information about how to update model locations, see Choosing your location.

Deploy a model in Vertex AI

You can use a variety of methods to deploy a model to an endpoint in Vertex AI. For more information, see Deploy a model to an endpoint.

Delete BigQuery ML models from the Model Registry

To delete a BigQuery ML model from the Model Registry, delete the model in BigQuery ML. The model is automatically removed from the Model Registry.

There are multiple ways you can delete a BigQuery ML model. For more information, see Delete models.

If you want to delete a model in BigQuery ML that has been registered in the Model Registry and deployed to an endpoint, you must first use Model Registry to undeploy the model. You can then return to BigQuery ML and delete the model. For more information on how to undeploy a model, see Delete an endpoint.