The CREATE MODEL statement for importing TensorFlow models
This document describes theCREATE MODEL statement for importingTensorFlow models intoBigQuery by using SQL. Alternatively, you can use theGoogle Cloud console user interface tocreate a model by using a UI(Preview) instead of constructing the SQLstatement yourself.
For more information about supported SQL statements and functions for thismodel, seeEnd-to-end user journeys for imported models.
CREATE MODEL syntax
{CREATE MODEL |CREATE MODEL IF NOT EXISTS |CREATE OR REPLACE MODEL}model_nameOPTIONS(MODEL_TYPE = 'TENSORFLOW', MODEL_PATH =string_value [, KMS_KEY_NAME =string_value ]);CREATE MODEL
Creates and trains a new model in the specified dataset. If the model nameexists,CREATE MODEL returns an error.
CREATE MODEL IF NOT EXISTS
Creates and trains a new model only if the model doesn't exist in thespecified dataset.
CREATE OR REPLACE MODEL
Creates and trains a model and replaces an existing model with the same name inthe specified dataset.
model_name
The name of the model you're creating or replacing. The modelname must be unique in the dataset: no other model or table can have the samename. The model name must follow the same naming rules as aBigQuery table. A model name can:
- Contain up to 1,024 characters
- Contain letters (upper or lower case), numbers, and underscores
model_name is case-sensitive.
If you don't have a default project configured, then you must prepend theproject ID to the model name in the following format, including backticks:
`[PROJECT_ID].[DATASET].[MODEL]`
For example, `myproject.mydataset.mymodel`.
MODEL_TYPE
Syntax
MODEL_TYPE='TENSORFLOW'Description
Specifies the model type. This option is required.
MODEL_PATH
Syntax
MODEL_PATH=string_valueDescription
Specifies theCloud Storage URIof the TensorFlow model to import. This option is required.
Arguments
ASTRING value specifying the URI of a Cloud Storage bucket that containsthe model to import.
BigQuery ML imports the model from Cloud Storage by using thecredentials of the user who runs theCREATE MODEL statement.
Example
MODEL_PATH='gs://bucket/path/to/saved_model/*'KMS_KEY_NAME
Syntax
KMS_KEY_NAME =string_value
Description
The Cloud Key Management Servicecustomer-managed encryption key (CMEK) touse to encrypt the model.
Arguments
ASTRING value containing the fully-qualified name of the CMEK. For example,
'projects/my_project/locations/my_location/keyRings/my_ring/cryptoKeys/my_key'Supported data types for input and output columns
BigQuery ML converts some TensorFlow model inputand output columns to BigQuery ML types, and someTensorFlow typesaren't supported. Supported data types for input and output columns includethe following:
| TensorFlow types | Supported | BigQuery ML type |
|---|---|---|
tf.int8, tf.int16, tf.int32, tf.int64, tf.uint8, tf.uint16, tf.uint32, tf.uint64 | Supported | INT64 |
tf.float16, tf.float32, tf.float64, tf.bfloat16 | Supported | FLOAT64 |
tf.complex64, tf.complex128 | Unsupported | N/a |
tf.qint8, tf.quint8, tf.qint16, tf.quint16, tf.qint32 | Unsupported | N/A |
tf.bool | Supported | BOOL |
tf.string | Supported | STRING |
tf.resource | Unsupported | N/A |
tf.variant | Unsupported | N/A |
SparseTensor of a supported TensorFlow type | Supported | ANULL, the associated BigQuery ML type, or anARRAY of the associated BigQuery ML type. |
tf.train.Example containing supported TensorFlow types | Supported | BigQuery ML automatically takes features and converts into atf.train.Example. |
The model input columns can be either dense Tensors or SparseTensors;RaggedTensors aren't supported. You can pass SparseTensors as dense arrays andBigQuery ML automatically converts them into Sparse format topass into TensorFlow.
If the model expects input columns intf.train.Example format,then BigQuery ML automatically determines the feature names andconverts the input BigQuery columns into the model's expectedformat.
Locations
For information about supported locations, seeLocations for non-remote models.
Limitations
Imported TensorFlow models have the following limitations:
- The TensorFlow model must already exist before you can importit into BigQuery ML.
- Models must be stored in Cloud Storage.
- Models are frozen at the time of model creation.
- TensorFlow models must be inSavedModel format.
- The following functions don't support TensorFlow models:
ML.CONFUSIONML.EVALUATEML.FEATUREML.ROC_CURVEML.TRAINING_INFOML.WEIGHTS
- Models are limited to 450 MB in size.
- Models trained using a version of GraphDef earlier than version 20 aren'tsupported.
- Models trained using an unreleased version of TensorFlow aren'tsupported.
- Only core TensorFlow operations are supported; models that usecustom or
tf.contriboperations aren't supported. - RaggedTensors aren't supported.
- You can only use an imported TensorFlow model with an objecttable when you use capacity-based pricing through reservations. On-demandpricing isn't supported.
Example
The following example imports a TensorFlow model intoBigQuery ML as a BigQuery ML model. The exampleassumes that there is an existing TensorFlow model located atgs://bucket/path/to/saved_model/*.
CREATEMODEL`project_id.mydataset.mymodel`OPTIONS(MODEL_TYPE='TENSORFLOW',MODEL_PATH="gs://bucket/path/to/saved_model/*")
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.