Skip to main content

Deployments using the registry

To make a deployment that uses the models in the registry, call mb.get_model in your inference function.

Storing a model in the registry

First, store a model in the registry so your inference function has a model to fetch:

from sklearn import linear_model
model = linear_model.LinearRegression()
model.fit([[1], [2], [3]], [2, 4, 6])

# store the model, we'll call it "doubler_model"
mb.add_model("doubler_model", model)

Fetch the model in your inference function

Now that we have a model in the registry, we can build an inference function that uses it:

def double_number_example(a: int):
model = mb.get_model("doubler_model")
return model.predict([[a]])[0]

double_number_example(5)

At inference time the deployment will fetch the model and use it to make a prediction. Models are cached in the deployment so subsequent calls to get_model are instant.

Deploy

import sklearn

mb.deploy(double_number_example, python_packages=[f"scikit-learn=={sklearn.__version__}"])