Skip to main content

add_model

Adds or replaces a model to the model registry.

Multiple models

When adding multiple models to the registry, use mb.add_models instead.

Parameters

mb.add_model(name=, ...)
  • name: str The name of the model in the registry. Models are stored by paths, like files, so forward slashes can be used for organization.
  • model: Optional[Any] The model object to store in the registry. A Python variable, not a path to a .pkl file. Required unless using file=.
  • file: Optional[str] The filepath where the model is stored. Use this for file-based models instead of model=
  • metrics: Optional[Dict[str, Any]] Optional, the metrics to associate with this model. Metrics must be JSON-serializable with str values for keys.
  • serializer: Optional["cloudpickle"] Optional, specify a different serializer to use. Default value is None which uses the pickle module. Learn mode

Returns

No value is returned. A success status message is printed if the command is successful.

Examples

For the examples below, assume my_model is an instance of a trained model:

my_model = ... # For example, an XGBoost model

Adding a model

Add my_model to the registry and name it example_model:

mb.add_model("example_model", my_model)

Adding a model in a "finance" directory

Organize models by sub-directory using forward slashes in the name:

mb.add_model("finance/example_model", my_model)

Adding a model stored as a file

Use the file= argument when storing file-based models:

mb.add_model("my_model", file="path/to/model.gguf")

Adding a model with metrics

Associate metrics with the model in the registry. Metrics are viewable and comparable in the model browser:

mb.add_model("example_model", model=my_model, metrics={ "precision": 0.95 })

Storing a model with cloudpickle

For model instances that cannot be serialized with pickle (e.g. Keras models), use the cloudpickle serializer:

mb.add_model("my_model", model=my_model, serializer="cloudpickle")

See also