Documentation Home
HeatWave User Guide
Related Documentation Download this Manual
PDF (US Ltr) - 3.8Mb
PDF (A4) - 3.8Mb


6.5.3 Load a Model

You must load a machine learning model from the model catalog into MySQL HeatWave before running MySQL HeatWave AutoML routines other than ML_TRAIN. A model remains loaded and can be called repetitively by MySQL HeatWave AutoML routines until it is unloaded using the ML_MODEL_UNLOAD routine, or until the MySQL HeatWave Cluster is restarted.

A model can only be loaded by the MySQL user that created the model unless you grant access to other users. For more information, see Grant Other Users Access to a Model.

MySQL 9.0.0 introduces support for large models that changes how MySQL HeatWave AutoML stores models. See The Model Object Catalog Table. ML_MODEL_LOAD upgrades older models.

For ML_MODEL_LOAD parameter descriptions, see ML_MODEL_LOAD.

Before You Begin

Load a Model with The Session Variable

After training a model, you set a session variable for the model handle that you can use until the current connection ends.

The following example loads a MySQL HeatWave AutoML model from the model catalog by using the session variable

mysql> CALL sys.ML_MODEL_LOAD(@census_model, NULL);

Where:

  • @census_model is the session variable that contains the model handle.

  • NULL is specified in place of the user name of the model owner. You are not required to specify a user name.

Load a Model Handle with The Defined Model Handle Name

Before training a machine learning model, it is good practice to define a model handle name instead of automatically generating one. This allows you to easily remember the model handle for future routines on the trained model instead of having to query it, or depending on the session variable that can no longer be used when the current connection terminates. See ML_TRAIN Example.

The following example uses the defined model handle name to load the model.

mysql> CALL sys.ML_MODEL_LOAD('census_test', NULL);

Load the Model with The Automatically Generated Model Handle

If you do not define a model handle name before training a machine learning model, it is automatically generated. If the connection for the session variable of a model handle ends, you need to load the model with the model name.

  1. Query the model handle, model owner, and the trained table name from the model catalog table. Replace user1 with your own user name.

    mysql> SELECT model_handle, model_owner, train_table_name FROM ML_SCHEMA_user1.MODEL_CATALOG;
    +-----------------------------------------------------+-------------+---------------------------------+
    | model_handle                                        | model_owner | train_table_name                |
    +-----------------------------------------------------+-------------+---------------------------------+
    | census_data.census_train_admin_1745261646953        | admin       | census_data.census_train        |
    | census_data.census_train_admin_1745334557047        | admin       | census_data.census_train        |
    | census_data.census_train_admin_1745336500455        | admin       | census_data.census_train        |
    +-----------------------------------------------------+-------------+---------------------------------+
    3 rows in set (0.0431 sec)
  2. Copy the appropriate model_handle and use it to load the machine learning model.

    mysql> CALL sys.ML_MODEL_LOAD('census_data.census_train_user1_1745261646953', NULL);

Verify Model is Loaded

You have the option to verify that model is loaded by using the ML_MODEL_ACTIVE routine.

The following example verifies the model previously loaded is active.

  1. Run ML_MODEL_ACTIVE on all active and loaded models and assign a session variable.

    mysql> CALL sys.ML_MODEL_ACTIVE('all', @variable);

    Replace variable with your own value. For example:

    mysql> CALL sys.ML_MODEL_ACTIVE('all', @models);
  2. Query the session variable previously created. Replace models with your own value.

    mysql> SELECT @models;
    +-------------------------------------------------------------------------------------------------------------------------+
    | @models                                                                                                                 |
    +-------------------------------------------------------------------------------------------------------------------------+
    | [{"total model size(bytes)": 388948}, {"admin": [{"census_test": {"format": "HWMLv2.0", "model_size(byte)": 388948}}]}] |
    +-------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.0431 sec)

    The output displays the loaded model with information on the user that trained the model, the size of the model, the model handle, and its format.

What's Next