snowflake.ml.registry.Registry

class snowflake.ml.registry.Registry(session: Session, *, database_name: Optional[str] = None, schema_name: Optional[str] = None, options: Optional[Dict[str, Any]] = None)

Bases: object

Opens a registry within a pre-created Snowflake schema.

Parameters:
  • session – The Snowpark Session to connect with Snowflake.

  • database_name – The name of the database. If None, the current database of the session will be used. Defaults to None.

  • schema_name – The name of the schema. If None, the current schema of the session will be used. If there is no active schema, the PUBLIC schema will be used. Defaults to None.

  • options – Optional set of configurations to modify registry. Registry Options include: - enable_monitoring: Feature flag to indicate whether registry can be used for monitoring.

Raises:

ValueError – When there is no specified or active database in the session.

Methods

add_monitor(name: str, source_config: ModelMonitorSourceConfig, model_monitor_config: ModelMonitorConfig) ModelMonitor

Add a Model Monitor to the Registry.

Parameters:
  • name – Name of Model Monitor to create.

  • source_config – Configuration options of table for Model Monitor.

  • model_monitor_config – Configuration options of Model Monitor.

Returns:

The newly added Model Monitor object.

Raises:

ValueError – If monitoring is not enabled in the Registry.

This function or method is in private preview since 1.7.0.

delete_model(model_name: str) None

Delete the model by its name.

Parameters:

model_name – The name of the model to be deleted.

delete_monitor(name: str) None

Delete a Model Monitor by name from the Registry.

Parameters:

name – Name of the Model Monitor to delete.

Raises:

ValueError – If monitoring is not enabled in the registry.

This function or method is in private preview since 1.7.0.

get_model(model_name: str) Model

Get the model object by its name.

Parameters:

model_name – The name of the model.

Returns:

The corresponding model object.

get_monitor(model_version: ModelVersion) ModelMonitor
get_monitor(name: str) ModelMonitor

Get a Model Monitor from the Registry.

Parameters:
  • name – Name of Model Monitor to retrieve.

  • model_version – Model Version for which to retrieve the Model Monitor.

Returns:

The fetched Model Monitor.

Raises:

ValueError – If monitoring is not enabled in the Registry.

This function or method is in private preview since 1.7.0.

log_model(model: model_types.SupportedModelType, *, model_name: str, version_name: Optional[str] = None, comment: Optional[str] = None, metrics: Optional[Dict[str, Any]] = None, conda_dependencies: Optional[List[str]] = None, pip_requirements: Optional[List[str]] = None, target_platforms: Optional[List[model_types.SupportedTargetPlatformType]] = None, python_version: Optional[str] = None, signatures: Optional[Dict[str, ModelSignature]] = None, sample_input_data: Optional[model_types.SupportedDataType] = None, code_paths: Optional[List[str]] = None, ext_modules: Optional[List[ModuleType]] = None, options: Optional[model_types.ModelSaveOption] = None) ModelVersion
log_model(model: ModelVersion, *, model_name: str, version_name: Optional[str] = None) ModelVersion

Log a model with various parameters and metadata, or a ModelVersion object.

Parameters:
  • model – Supported model or ModelVersion object. - Supported model: Model object of supported types such as Scikit-learn, XGBoost, LightGBM, Snowpark ML, PyTorch, TorchScript, Tensorflow, Tensorflow Keras, MLFlow, HuggingFace Pipeline, Sentence Transformers, or Custom Model. - ModelVersion: Source ModelVersion object used to create the new ModelVersion object.

  • model_name – Name to identify the model.

  • version_name – Version identifier for the model. Combination of model_name and version_name must be unique. If not specified, a random name will be generated.

  • comment – Comment associated with the model version. Defaults to None.

  • metrics – A JSON serializable dictionary containing metrics linked to the model version. Defaults to None.

  • signatures – Model data signatures for inputs and outputs for various target methods. If it is None, sample_input_data would be used to infer the signatures for those models that cannot automatically infer the signature. If not None, sample_input_data should not be specified. Defaults to None.

  • sample_input_data – Sample input data to infer model signatures from. It would also be used as background data in explanation and to capture data lineage. Defaults to None.

  • conda_dependencies – List of Conda package specifications. Use “[channel::]package [operator version]” syntax to specify a dependency. It is a recommended way to specify your dependencies using conda. When channel is not specified, Snowflake Anaconda Channel will be used. Defaults to None.

  • pip_requirements – List of Pip package specifications. Defaults to None. Currently it is not supported since Model can only executed in Snowflake Warehouse where all dependencies are required to be retrieved from Snowflake Anaconda Channel.

  • target_platforms – List of target platforms to run the model. The only acceptable inputs are a combination of {“WAREHOUSE”, “SNOWPARK_CONTAINER_SERVICES”}. Defaults to None.

  • python_version – Python version in which the model is run. Defaults to None.

  • code_paths – List of directories containing code to import. Defaults to None.

  • ext_modules – List of external modules to pickle with the model object. Only supported when logging the following types of model: Scikit-learn, Snowpark ML, PyTorch, TorchScript and Custom Model. Defaults to None.

  • task – The task of the Model Version. It is an enum class Task with values TABULAR_REGRESSION, TABULAR_BINARY_CLASSIFICATION, TABULAR_MULTI_CLASSIFICATION, TABULAR_RANKING, or UNKNOWN. By default, it is set to Task.UNKNOWN and may be overridden by inferring from the Model Object.

  • options (Dict[str, Any], optional) –

    Additional model saving options.

    Model Saving Options include:

    • embed_local_ml_library: Embed local Snowpark ML into the code directory or folder.

      Override to True if the local Snowpark ML version is not available in the Snowflake Anaconda Channel. Otherwise, defaults to False

    • relax_version: Whether or not relax the version constraints of the dependencies when running in the

      Warehouse. It detects any ==x.y.z in specifiers and replaced with >=x.y, <(x+1). Defaults to True.

    • function_type: Set the method function type globally. To set method function types individually see function_type in model_options.

    • method_options: Per-method saving options including:
      • case_sensitive: Indicates whether the method and its signature should be case sensitive.

        This means when you refer the method in the SQL, you need to double quote it. This will be helpful if you need case to tell apart your methods or features, or you have non-alphabetic characters in your method or feature name. Defaults to False.

      • max_batch_size: Maximum batch size that the method could accept in the Snowflake Warehouse.

        Defaults to None, determined automatically by Snowflake.

      • function_type: One of supported model method function types (FUNCTION or TABLE_FUNCTION).

Returns:

ModelVersion object corresponding to the model just logged.

Return type:

ModelVersion

models() List[Model]

Get all models in the schema where the registry is opened.

Returns:

A list of Model objects representing all models in the opened registry.

show_model_monitors() List[Row]

Show all model monitors in the registry.

Returns:

List of snowpark.Row containing metadata for each model monitor.

Raises:

ValueError – If monitoring is not enabled in the Registry.

This function or method is in private preview since 1.7.0.

show_models() DataFrame

Show information of all models in the schema where the registry is opened.

Returns:

A Pandas DataFrame containing information of all models in the schema.

Attributes

location

Get the location (database.schema) of the registry.