Deploying a pure function

Within Verta, a "Model" can be any arbitrary function: a traditional ML model (e.g., sklearn, PyTorch, TF, etc); a function (e.g., squaring a number, making a DB function etc.); or a mixture of the above (e.g., pre-processing code, a DB call, and then a model application.

This tutorial provides an example of how to deploy any function on Verta.

As mention in the deploying models guide, deploying models via Verta Inference is a two step process: (1) first create an endpoint, and (2) update the endpoint with a model.

This tutorial explains how Verta Inference can be used to deploy a scikit-learn model.

1. Create an endpoint

Users can create an endpoint using Client.create_endpoint() as follows:

census_endpoint = client.create_endpoint(path="/census")

2. Updating the endpoint with a RMV

To deploy an arbitrary function within Verta, the function must be wrapped into a class that extends VertaModelBase (See this guide).

For example, suppose we have a cubic transform that we want to deploy to Verta. Note that this function could be absolutely anything -- make a database query, call a REST endpoint, use the associated artifacts to do further processing, etc.

def cubic_transform(x):
return 3*(x**3) + 2*x + 5
from verta.registry import VertaModelBase
class CubicFunction(VertaModelBase):
def __init__(self, artifacts=None):
pass
def predict(self, input_data):
output_data = []
for input_data_point in input_data:
output_data_point = cubic_transform(input_data_point)
output_data.append(output_data_point)
return output_data
from verta.environment import Python
model_version = registered_model.create_standard_model(
CubicFunction,
environment=Python(requirements=[]),
name="v1",
)

Regardless of how a Registered Model Version has been created, the endpoint defined above can now be upated and we can make predictions against it.

ccubic_function_endpoint = client.get_or_create_endpoint("cubic")
cubic_function_endpoint.update(model_version, wait=True)
deployed_model = cubic_function_endpoint.get_deployed_model()
deployed_model.predict([3, 0])

The full code for this tutorial can be found here.