You are viewing documentation about an older version (1.2.0). View latest version

snowflake.ml.registry.Registry

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

Bases: object

Opens a registry within a pre-created Snowflake schema.

Args:

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.

Raises:

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

Methods

delete_model(model_name: str) None

Delete the model by its name.

Args:

model_name: The name of the model to be deleted.

get_model(model_name: str) Model

Get the model object by its name.

Args:

model_name: The name of the model.

Returns:

The corresponding model object.

log_model(model: Union[CustomModel, sklearn.base.BaseEstimator, sklearn.pipeline.Pipeline, xgboost.XGBModel, xgboost.Booster, torch.nn.Module, torch.jit.ScriptModule, tensorflow.Module, base.BaseEstimator, mlflow.pyfunc.PyFuncModel, transformers.Pipeline, HuggingFacePipelineModel, snowflake.ml.model.models.llm.LLM], *, model_name: str, version_name: str, comment: Optional[str] = None, metrics: Optional[Dict[str, Any]] = None, conda_dependencies: Optional[List[str]] = None, pip_requirements: Optional[List[str]] = None, python_version: Optional[str] = None, signatures: Optional[Dict[str, ModelSignature]] = None, sample_input_data: Optional[Union[pd.DataFrame, ndarray[Any, dtype[Union[np.int8, np.int16, np.int32, np.int64, np.float32, np.float64, np.uint8, np.uint16, np.uint32, np.uint64, np.bool_, np.str_, np.bytes_]]], Sequence[Union[ndarray[Any, dtype[Union[np.int8, np.int16, np.int32, np.int64, np.float32, np.float64, np.uint8, np.uint16, np.uint32, np.uint64, np.bool_, np.str_, np.bytes_]]], torch.Tensor, tensorflow.Tensor, tensorflow.Variable]], Sequence[Union[int, float, bool, str, bytes, _SupportedBuiltinsList]], snowflake.snowpark.DataFrame]] = None, code_paths: Optional[List[str]] = None, ext_modules: Optional[List[module]] = None, options: Optional[Union[BaseModelSaveOption, CustomModelSaveOption, SKLModelSaveOptions, XGBModelSaveOptions, SNOWModelSaveOptions, PyTorchSaveOptions, TorchScriptSaveOptions, TensorflowSaveOptions, MLFlowSaveOptions, HuggingFaceSaveOptions, LLMSaveOptions]] = None) ModelVersion

Log a model with various parameters and metadata.

Args:

model: Model object of supported types such as Scikit-learn, XGBoost, Snowpark ML, PyTorch, TorchScript, Tensorflow, Tensorflow Keras, MLFlow, HuggingFace Pipeline, or Custom Model.

model_name: Name to identify the model.

version_name: Version identifier for the model. Combination of model_name and version_name must be unique.

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. 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.

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.

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

  • 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.

Returns:

ModelVersion: ModelVersion object corresponding to the model just logged.

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_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.