Include a trained model in an app¶
This topic describes how to include a previously trained mode in a Snowflake Native App
Workflow - Add a model to an app¶
The following procedure outlines the typical workflow a provider follows create and add a Snowflake ML model to an app:
The provider develops a Snowflake ML model and logs it in the Snowflake Model Registry.
The provider exports the model artifacts from the Snowflake Model Registry and uploads them to a stage so that they are accessible to the application package.
The provider creates the model in the setup script of the app.
The app creates a model from these artifacts in the consumer account during installation or after an upgrade. Optionally, the app can grant access on the model to an application role.
The consumer uses the machine learning model if the provider configures the app to grant access to it.
Note
A provider is not required to grant access on the model to the consumer. The model can be created as an object that the app uses internally, but is not accessible to the consumer.
Develop a machine learning model¶
Providers can develop new machine learning models or include existing models in an app.
For information about developing models, see Snowflake ML Model Development.
For information about managing models in a Snowflake Model Registry, see Snowflake Model Registry.
Export the model artifacts and upload to a stage¶
To include a model in an app, providers must export the model artifacts and upload them to a stage where they are accessible to the application package.
Manually export the model artifacts and upload them to a stage¶
Download the model artifacts. See Snowflake Model Registry
Use one of the following methods to upload the machine learning artifacts to the stage where your app resources are located:
To upload the files using Snowsight, see Staging files using Snowsight.
To upload the files using the Snowflake CLI, use the
snow app deploycommand. See How to create an application package and an application object together.To upload the files using SQL, see Staging data files from a local file system.
Use a stored procedure to export the model artifacts and upload them to a stage¶
Providers can use the following stored procedure example as a template for automating the process of downloading the model artifacts and uploading them to a stage:
Create the model objects in the consumer account¶
To create the model objects in the consumer account, the provider adds the necessary SQL commands to the setup script as shown in the following example:
Optionally, providers can grant access on the model to consumers by granting the USAGE privilege on the model to an application role:
Access the model within the app¶
To use the model internally as part of the app, providers add a SELECT statement to the setup script as shown in the following example:
Use the model as a consumer¶
If a provider grants privilege on the model to a consumer, the consumer can run the following command to access the model:
To run this command, consumers must use a role that has one of the following:
The USAGE privilege granted on the model.
The OWNERSHIP privilege on the application object.