Creating registered model versions from artifacts
Many times, a model may require artifact dependencies that are not capture in the model inference code. For example, a model class may require weights, a checkpoint, or a serialized version of the model. As a result, VertaModelBase has the ability to specify and use artifact dependencies.
This guide explains how you can use artifacts within your model class definition.
Basic model definition
As defined in the API reference, a Verta Standard Model must extend VertaModelBase
. Specifically, the __init__()
function of VertaModelBase takes as input an artifact dictionary which is a mapping from the name of an artifact to where the artifact is located on the filesystem. This information allows the end user to handle the artifacts as required by the system.
Artifacts from files
Assume that our model is a linear regression model (ax + b) and its weights have been stored in a JSON file called "weights.json" which looks as follows:
Then a model using those weights may look as follows, using json.load()
to read the JSON file:
That's it. Now we can create a Registered Model Version encapsulating the model code as well as the artifact by mapping its local filepath to its key (used to open()
the file in the model code) through the artifacts
parameter:
Artifacts from Python objects
Python objects can also be passed as artifacts, so long as they are serializable by cloudpickle
.
Let's say we were working with our weights as a Python dict
rather than an on-disk JSON file:
This will be made available to the deployed model as a pickle
d file, so we must call pickle.load()
to use it:
Finally, instead of passing a filepath string, we pass the object itself. As mentioned before, the client will pickle
this object for the deployed model to load:
An executable Notebook for this guide is available here.
Last updated