snowflake.ml.model.ModelVersion

class snowflake.ml.model.ModelVersion

Bases: object

Model Version Object representing a specific version of the model that could be run.

Methods

delete_metric(metric_name: str) None

Delete a metric from metric storage.

Parameters:

metric_name – The name of the metric to be deleted.

Raises:

KeyError – When the requested metric name does not exist.

export(target_path: str, *, export_mode: ExportMode = ExportMode.MODEL) None

Export model files to a local directory.

Parameters:
  • target_path – Path to a local directory to export files to. A directory will be created if does not exist.

  • export_mode – The mode to export the model. Defaults to ExportMode.MODEL. ExportMode.MODEL: All model files including environment to load the model and model weights. ExportMode.FULL: Additional files to run the model in Warehouse, besides all files in MODEL mode,

Raises:

ValueError – Raised when the target path is a file or an non-empty folder.

get_metric(metric_name: str) Any

Get the value of a specific metric.

Parameters:

metric_name – The name of the metric.

Raises:

KeyError – When the requested metric name does not exist.

Returns:

The value of the metric.

load(*, force: bool = False, options: Optional[ModelLoadOption] = None) Union[catboost.CatBoost, lightgbm.LGBMModel, lightgbm.Booster, 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, sentence_transformers.SentenceTransformer, HuggingFacePipelineModel, snowflake.ml.model.models.llm.LLM]
Load the underlying original Python object back from a model.

This operation requires to have the exact the same environment as the one when logging the model, otherwise, the model might be not functional or some other problems might occur.

Parameters:
  • force – Bypass the best-effort environment validation. Defaults to False.

  • options – Options to specify when loading the model, check snowflake.ml.model.type_hints for available options. Defaults to None.

Raises:

ValueError – Raised when the best-effort environment validation fails.

Returns:

The original Python object loaded from the model object.

run(X: Union[DataFrame, DataFrame], *, function_name: Optional[str] = None, partition_column: Optional[str] = None, strict_input_validation: bool = False) Union[DataFrame, DataFrame]

Invoke a method in a model version object.

Parameters:
  • X – The input data, which could be a pandas DataFrame or Snowpark DataFrame.

  • function_name – The function name to run. It is the name used to call a function in SQL. Defaults to None. It can only be None if there is only 1 method.

  • partition_column – The partition column name to partition by.

  • strict_input_validation – Enable stricter validation for the input data. This will result value range based type validation to make sure your input data won’t overflow when providing to the model.

Raises:
  • ValueError – When no method with the corresponding name is available.

  • ValueError – When the partition column is not a valid Snowflake identifier.

Returns:

The prediction data. It would be the same type dataframe as your input.

set_metric(metric_name: str, value: Any) None

Set the value of a specific metric.

Parameters:
  • metric_name – The name of the metric.

  • value – The value of the metric.

show_functions() List[ModelFunctionInfo]

Show all functions information in a model version that is callable.

Returns:

  • name: The name of the function to be called (both in SQL and in Python SDK).

  • target_method: The original method name in the logged Python object.

  • signature: Python signature of the original method.

Return type:

A list of ModelFunctionInfo objects containing the following information

show_metrics() Dict[str, Any]

Show all metrics logged with the model version.

Returns:

A dictionary showing the metrics.

Attributes

comment

The comment to the model version.

description

The description for the model version. This is an alias of comment.

fully_qualified_model_name

Return the fully qualified name of the model to which the model version belongs.

model_name

Return the name of the model to which the model version belongs, usable as a reference in SQL.

version_name

Return the name of the version to which the model version belongs, usable as a reference in SQL.