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 stored in variables
If your models are already loaded into RAM as variables in your Python environment, add them to Modelbit using 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.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
Models stored in files
If your models are stored on disk as files, add them to Modelbit using files=
or directory=
:
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=
directory
:Optional[str]
A path to one or more model files to upload to the registry as files. Must also specifyregistry_prefix
when usingdirectory=
.registry_prefix
:Optional[str]
Specify a path in the model registry to contain the uploaded models. Required when usingdirectory=
and ignored otherwise.
Specifying model metrics
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.
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 a directory of models
Suppose there is a local directory foo/my_models
with two files, model_a.pt
and model_b.pt
. To upload both models and store them in the registry as example_models/model_a.pt
and example_models/model_b.pt
use directory=
and registry_prefix=
:
mb.add_models(directory="foo/my_models", registry_prefix="example_models")
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")