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

snowflake.ml.model.custom_model.ModelContext

class snowflake.ml.model.custom_model.ModelContext(*, artifacts: Optional[Dict[str, str]] = None, models: Optional[Dict[str, 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]]] = None)

Bases: object

Context for a custom model showing paths to artifacts and mapping between model name and object reference.

artifacts

A dictionary mapping the name of the artifact to its path.

model_refs

A dictionary mapping the name of the sub-model to its ModelRef object.

Initialize the model context.

Parameters:
  • artifacts – A dictionary mapping the name of the artifact to its currently available path. Defaults to None.

  • models – A dictionary mapping the name of the sub-model to the corresponding model object. Defaults to None.

Methods

model_ref(name: str) ModelRef

Get a ModelRef object of a sub-model containing the name and model object, allowing direct method calls.

Parameters:

name – The name of the sub-model.

Returns:

The ModelRef object representing the sub-model.

path(key: str) str
Get the actual path to a specific artifact. This could be used when defining a Custom Model to retrieve

artifacts.

Parameters:

key – The name of the artifact.

Returns:

The absolute path to the artifact.