add_models
Adds one or more models to the model registry. The registry is updated with the new model if a an entry with that name already exists.
Parameters
mb.add_models(models=, ...)
models
:Optional[Dict[str, Any]]
A dictionary of{ modelName: modelVariable }
. The keys of the dictionary must be strings. The values are the models to store. The values are Python variables, not paths to.pkl
files. Required unless using thefiles=
parameter.files
:Optional[Dict[str, str]]
A dictionary of{ modelName: pathToModelFile }
. The keys and values of the dictionary must be strings, and the values must be filepaths to local model files. Use this for file-based models instead ofmodels=
metrics
:Optional[str, Optional[Dict[str, Any]]]
Metrics to associate with the models getting added. Like themodels
parameter, themetrics
parameter is a dictionary of{ modelName: metricsDict }
. Metrics must be JSON-serializable withstr
values for keys.serializer
:Optional["cloudpickle"]
Specify a different serializer to use. Default value isNone
which uses thepickle
module. This setting applies to all models in this call. 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
and other_model
are instances of trained models:
my_model = ... # For example, an XGBoost model
other_model = ... # For example, a transformer
Adding a model
Add my_model
to the registry and name it example_model
:
mb.add_models({ "example_model": my_model })
Adding multiple models
Store multiple models in the registry. Store my_model
with the name example_model
, and other_model
with the name another_model
:
mb.add_models({ "example_model": my_model, "another_model": other_model })
Adding multiple model to the "finance" directory
Use forward slashes to organize models into subdirectories:
mb.add_models({ "finance/example_model": my_model, "finance/another_model": other_model })
Adding file-based models
Store file-based models in the registry when the model already exists as a local artifact:
mb.add_models(files={ "my_model": "path/to/model.gguf" })
Adding multiple models with metrics
Store multiple models with metrics using two dicts, one for the models and one for the metrics:
mb.add_models({
"example_model": my_model,
"another_model": other_model
},
metrics={
"example_model": { "precision": 0.95 },
"another_model": { "precision": 0.80 }
})
Adding multiple models with cloudpickle
For models that don't serialize well with pickle
, specify the cloudpickle
serializer:
mb.add_models({ "example_model": my_model, "another_model": other_model }, serializer="cloudpickle")