snowflake.ml.model.custom_model.ModelContext

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

Bases: object

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

Attributes:

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.

Args:

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.

Args:

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.

Args:

key: The name of the artifact.

Returns:

The absolute path to the artifact.