Run the ML_MODEL_IMPORT
routine
to import a pre-trained model into the model catalog. MySQL
8.1.0 supports the import of HeatWave AutoML format models. MySQL
8.0.31 supports the import of ONNX, Open Neural Network
Exchange, format models. After import, all the HeatWave AutoML
routines can be used with the ONNX model.
Models in ONNX format, .onnx
. cannot be
loaded directly into a MySQL table. They require string
serialization and conversion to Base64 binary encoding. Before
running ML_MODEL_IMPORT
, follow
the instructions in Section 3.12.2, “ONNX Model Import” to
carry out the required pre-processing and then load the model
into a temporary table for import to MySQL HeatWave.
mysql> CALL sys.ML_MODEL_IMPORT (model_object, model_metadata, model_handle);
ML_MODEL_IMPORT
parameters:
model_object
: The preprocessed ONNX model object, which must be string serialized and BASE64 encoded. See Section 3.12.2, “ONNX Model Import”.model_metadata
: An optional JSON object that contains key-value pairs with model metadata. See Section 3.13.12, “Model Metadata”.model_handle
: The model handle for the model. The model is stored in the model catalog under this name and accessed using it. Specify a model handle that does not already exist in the model catalog.
-
An example that imports a HeatWave AutoML model with metadata:
mysql> SET @hwml_model = "hwml_model"; Query OK, 0 rows affected (0.00 sec) mysql> CALL sys.ML_TRAIN('mlcorpus.input_train', 'target', NULL, @hwml_model); Query OK, 0 rows affected (23.36 sec) mysql> SET @hwml_object = (SELECT model_object FROM ML_SCHEMA_root.MODEL_CATALOG WHERE model_handle=@hwml_model); Query OK, 0 rows affected (0.00 sec) mysql> SET @hwml_metadata = (SELECT model_metadata FROM ML_SCHEMA_root.MODEL_CATALOG WHERE model_handle=@hwml_model); Query OK, 0 rows affected (0.00 sec) mysql> CALL sys.ML_MODEL_IMPORT(@hwml_object, @hwml_metadata, @imported_model); Query OK, 0 rows affected (0.01 sec) mysql> model_metadata->>'$.task' AS task, model_owner, model_metadata->>'$.build_timestamp' AS build_timestamp, model_metadata->>'$.target_column_name' AS target_column_name, model_metadata->>'$.train_table_name' AS train_table_name, model_object_size, model_metadata->>'$.model_explanation' AS model_explanation FROM ML_SCHEMA_root.MODEL_CATALOG; +----------------+----------------+-----------------+--------------------+----------------------+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | task | model_owner | build_timestamp | target_column_name | train_table_name | model_object_size | model_explanation | +----------------+----------------+-----------------+--------------------+----------------------+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | classification | root | 1679202888 | target | mlcorpus.input_train | 4748 | {"permutation_importance": {"C0": 0.0, "C1": 0.0, "C2": 0.0, "C3": 0.0, "C4": 0.0, "C5": 0.0, "C6": 0.0, "C7": 0.0, "C8": 0.0, "C9": 0.0, "C10": 0.0, "C11": 0.0, "C12": 0.0, "C13": 0.0}} | | classification | root | 1679202888 | target | mlcorpus.input_train | 4748 | {"permutation_importance": {"C0": 0.0, "C1": 0.0, "C2": 0.0, "C3": 0.0, "C4": 0.0, "C5": 0.0, "C6": 0.0, "C7": 0.0, "C8": 0.0, "C9": 0.0, "C10": 0.0, "C11": 0.0, "C12": 0.0, "C13": 0.0}} | +----------------+----------------+-----------------+--------------------+----------------------+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql> SELECT model_metadata->>'$.column_names' AS column_names FROM ML_SCHEMA_root.MODEL_CATALOG WHERE model_handle LIKE 'hwml%'; +------------------------------------------------------------------------------------------+ | column_names | +------------------------------------------------------------------------------------------+ | ["C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C11", "C12", "C13"] | | ["C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C11", "C12", "C13"] | +------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
-
An example that imports an ONNX model without specifying metadata:
mysql> CALL sys.ML_MODEL_IMPORT(@onnx_encode, NULL, 'onnx_test');