RegisteredModel

class verta.registry.entities.RegisteredModel(conn, conf, msg)

Object representing a registered model.

There should not be a need to instantiate this class directly; please use Client.get_or_create_registered_model()

Variables:
  • id (int) – ID of this registered model.

  • name (str) – Name of this registered model.

  • url (str) – Verta web app URL.

  • versions (iterable of RegisteredModelVersion) – Versions of this RegisteredModel.

  • pii (bool) – Whether the registered_model ingests personally identifiable information.

add_label(label)

Adds a label to this registered model.

Parameters:

label (str) – Label to add.

add_labels(labels)

Adds multiple labels to this registered model.

Parameters:

labels (list of str) – Labels to add.

create_containerized_model(docker_image, model_api=None, name=None, desc=None, labels=None, attrs=None, lock_level=None, input_description=None, hide_input_label=False, output_description=None, hide_output_label=False)

Create a Containerized Model version from a Docker image.

New in version 0.20.0.

Note

This feature may require an upgrade to the platform; please reach out to the Verta team at support@verta.ai to verify its availability in your version of the system.

Parameters:
  • docker_image (DockerImage) – Docker image information.

  • model_api (ModelAPI, optional) – Model API specifying the model’s expected input and output

  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • desc (str, optional) – Description of the model version.

  • labels (list of str, optional) – Labels of the model version.

  • attrs (dict of str to {None, bool, float, int, str}, optional) – Attributes of the model version.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

  • input_description (str, optional) – Description of the model version’s input.

  • hide_input_label (bool, default False) – Whether to hide the model version’s input label.

  • output_description (str, optional) – Description of the model version’s output.

  • hide_output_label (bool, default False) – Whether to hide the model version’s output label.

Returns:

RegisteredModelVersion

Examples

from verta.registry import DockerImage

docker_image = DockerImage(
    port=5000,
    request_path="/predict_json",
    health_path="/health",

    repository="012345678901.dkr.ecr.apne2-az1.amazonaws.com/models/example",
    tag="example",

    env_vars={"CUDA_VISIBLE_DEVICES": "0,1"},
)

model_ver = reg_model.create_containerized_model(
    docker_image,
)
endpoint.update(model_ver, wait=True)
endpoint.get_deployed_model().predict(input)
create_standard_model(model_cls, environment, code_dependencies=None, model_api=None, artifacts=None, name=None, desc=None, labels=None, attrs=None, lock_level=None, input_description=None, hide_input_label=False, output_description=None, hide_output_label=False, check_model_dependencies=False)

Create a Standard Verta Model version from a Verta Model Specification.

New in version 0.22.2: The check_model_dependencies parameter.

New in version 0.18.2.

Note

The following artifact keys are reserved for internal use within the Verta system:

  • "custom_modules"

  • "model"

  • "model.pkl"

  • "model_api.json"

  • "requirements.txt"

  • "train_data"

  • "tf_saved_model"

  • "setup_script"

Note

If using an XGBoost model from their scikit-learn API, "scikit-learn" must also be specified in environment (in addition to "xgboost").

Parameters:
  • model_cls (subclass of VertaModelBase) – Model class that implements VertaModelBase.

  • environment (Python) – pip and apt dependencies.

  • code_dependencies (list of str, optional) – Paths to local Python code files that model_cls depends on. This parameter has the same behavior as custom_modules in RegisteredModelVersion.log_model().

  • model_api (ModelAPI, optional) – Model API specifying the model’s expected input and output

  • artifacts (dict of str to obj) – A mapping from artifact keys to artifacts. These will be logged and uploaded, then provided to the model when deployed.

  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • desc (str, optional) – Description of the model version.

  • labels (list of str, optional) – Labels of the model version.

  • attrs (dict of str to {None, bool, float, int, str}, optional) – Attributes of the model version.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

  • input_description (str, optional) – Description of the model version’s input.

  • hide_input_label (bool, default False) – Whether to hide the model version’s input label.

  • output_description (str, optional) – Description of the model version’s output.

  • hide_output_label (bool, default False) – Whether to hide the model version’s output label.

  • check_model_dependencies (bool, default False) – Whether to verify the model’s dependencies are specified in the environment and raise an exception if any are missing.

Raises:

RuntimeError – If check_model_dependencies is True and any dependencies detected in the model class are not specified in the environment.

Returns:

RegisteredModelVersion

Examples

from verta.environment import Python
from verta.registry import VertaModelBase

class VertaModel(VertaModelBase):
    def __init__(self, artifacts):
        import pickle

        with open(artifacts["weights"], "rb") as f:
            self.weights = pickle.load(f)

    def predict(self, input):
        import numpy as np

        return np.matmul(self.weights, input)

model_ver = reg_model.create_standard_model(
    VertaModel,
    Python(["numpy"]),
    artifacts={"weights": np.array(weights)},
)
endpoint.update(model_ver, wait=True)
endpoint.get_deployed_model().predict(input)
create_standard_model_from_keras(obj, environment, model_api=None, name=None, desc=None, labels=None, attrs=None, lock_level=None, input_description=None, hide_input_label=False, output_description=None, hide_output_label=False)

Create a Standard Verta Model version from a TensorFlow-backend Keras model.

New in version 0.18.2.

Parameters:
  • obj (tf.keras.Sequential or functional API keras.Model) – Keras model.

  • environment (Python) – pip and apt dependencies.

  • model_api (ModelAPI, optional) – Model API specifying the model’s expected input and output

  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • desc (str, optional) – Description of the model version.

  • labels (list of str, optional) – Labels of the model version.

  • attrs (dict of str to {None, bool, float, int, str}, optional) – Attributes of the model version.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

  • input_description (str, optional) – Description of the model version’s input.

  • hide_input_label (bool, default False) – Whether to hide the model version’s input label.

  • output_description (str, optional) – Description of the model version’s output.

  • hide_output_label (bool, default False) – Whether to hide the model version’s output label.

Returns:

RegisteredModelVersion

Examples

from tensorflow import keras
from verta.environment import Python

inputs = keras.Input(shape=(3,))
x = keras.layers.Dense(2, activation="relu")(inputs)
outputs = keras.layers.Dense(1, activation="sigmoid")(x)
model = keras.Model(inputs=inputs, outputs=outputs)
train(model, data)

model_ver = reg_model.create_standard_model_from_keras(
    model,
    Python(["tensorflow"]),
)
endpoint.update(model_ver, wait=True)
endpoint.get_deployed_model().predict(input)
create_standard_model_from_sklearn(obj, environment, model_api=None, name=None, desc=None, labels=None, attrs=None, lock_level=None, input_description=None, hide_input_label=False, output_description=None, hide_output_label=False)

Create a Standard Verta Model version from a scikit-learn model.

New in version 0.18.2.

Parameters:
  • obj (sklearn.base.BaseEstimator) – scikit-learn model.

  • environment (Python) – pip and apt dependencies.

  • model_api (ModelAPI, optional) – Model API specifying the model’s expected input and output

  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • desc (str, optional) – Description of the model version.

  • labels (list of str, optional) – Labels of the model version.

  • attrs (dict of str to {None, bool, float, int, str}, optional) – Attributes of the model version.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

  • input_description (str, optional) – Description of the model version’s input.

  • hide_input_label (bool, default False) – Whether to hide the model version’s input label.

  • output_description (str, optional) – Description of the model version’s output.

  • hide_output_label (bool, default False) – Whether to hide the model version’s output label.

Returns:

RegisteredModelVersion

Examples

from sklearn.svm import LinearSVC
from verta.environment import Python

model = LinearSVC(**hyperparams)
model.fit(X_train, y_train)

model_ver = reg_model.create_standard_model_from_sklearn(
    model,
    Python(["scikit-learn"]),
)
endpoint.update(model_ver, wait=True)
endpoint.get_deployed_model().predict(input)
create_standard_model_from_torch(obj, environment, model_api=None, name=None, desc=None, labels=None, attrs=None, lock_level=None, input_description=None, hide_input_label=False, output_description=None, hide_output_label=False)

Create a Standard Verta Model version from a PyTorch model.

New in version 0.18.2.

Parameters:
  • obj (torch.nn.Module) – PyTorch model.

  • environment (Python) – pip and apt dependencies.

  • model_api (ModelAPI, optional) – Model API specifying the model’s expected input and output

  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • desc (str, optional) – Description of the model version.

  • labels (list of str, optional) – Labels of the model version.

  • attrs (dict of str to {None, bool, float, int, str}, optional) – Attributes of the model version.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

  • input_description (str, optional) – Description of the model version’s input.

  • hide_input_label (bool, default False) – Whether to hide the model version’s input label.

  • output_description (str, optional) – Description of the model version’s output.

  • hide_output_label (bool, default False) – Whether to hide the model version’s output label.

Returns:

RegisteredModelVersion

Examples

import torch
from verta.environment import Python

class Model(torch.nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.layer1 = torch.nn.Linear(3, 2)
        self.layer2 = torch.nn.Linear(2, 1)

    def forward(self, x):
        x = torch.nn.functional.relu(self.layer1(x))
        return torch.sigmoid(self.layer2(x))

model = Model()
train(model, data)

model_ver = reg_model.create_standard_model_from_torch(
    model,
    Python(["torch"]),
)
endpoint.update(model_ver, wait=True)
endpoint.get_deployed_model().predict(input)
create_standard_model_from_xgboost(obj, environment, model_api=None, name=None, desc=None, labels=None, attrs=None, lock_level=None, input_description=None, hide_input_label=False, output_description=None, hide_output_label=False)

Create a Standard Verta Model version from an XGBoost model.

New in version 0.18.2.

Note

If using an XGBoost model from their scikit-learn API, "scikit-learn" must also be specified in environment (in addition to "xgboost").

Parameters:
  • obj (xgboost.sklearn.XGBModel) – XGBoost model using their scikit-learn wrapper interface.

  • environment (Python) – pip and apt dependencies.

  • model_api (ModelAPI, optional) – Model API specifying the model’s expected input and output

  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • desc (str, optional) – Description of the model version.

  • labels (list of str, optional) – Labels of the model version.

  • attrs (dict of str to {None, bool, float, int, str}, optional) – Attributes of the model version.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

  • input_description (str, optional) – Description of the model version’s input.

  • hide_input_label (bool, default False) – Whether to hide the model version’s input label.

  • output_description (str, optional) – Description of the model version’s output.

  • hide_output_label (bool, default False) – Whether to hide the model version’s output label.

Returns:

RegisteredModelVersion

Examples

import xgboost as xgb
from verta.environment import Python

model = xgb.XGBClassifier(**hyperparams)
model.fit(X_train, y_train)

model_ver = reg_model.create_standard_model_from_xgboost(
    model,
    Python(["scikit-learn", "xgboost"]),
)
endpoint.update(model_ver, wait=True)
endpoint.get_deployed_model().predict(input)
create_version(name=None, desc=None, labels=None, attrs=None, time_created=None, lock_level=None, input_description=None, hide_input_label=False, output_description=None, hide_output_label=False)

Creates a model registry entry.

Parameters:
  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • desc (str, optional) – Description of the model version.

  • labels (list of str, optional) – Labels of the model version.

  • attrs (dict of str to {None, bool, float, int, str}, optional) – Attributes of the model version.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

  • input_description (str, optional) – Description of the model version’s input.

  • hide_input_label (bool, default False) – Whether to hide the model version’s input label.

  • output_description (str, optional) – Description of the model version’s output.

  • hide_output_label (bool, default False) – Whether to hide the model version’s output label.

Returns:

RegisteredModelVersion

create_version_from_run(run_id, name=None, lock_level=None)

Create a model version copied from an experiment run.

Parameters:
  • run_id (str or ExperimentRun) – Run from which to create the model version.

  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

Returns:

RegisteredModelVersion

del_label(label)

Deletes a label from this registered model.

Parameters:

label (str) – Label to delete.

delete()

Deletes this registered model.

get_data_type()

Gets this registered model data type

Returns:

data_type (data_type) – This registered model data type.

get_labels()

Gets all labels of this registered model.

Returns:

labels (list of str) – List of all labels of this registered model.

get_or_create_version(name=None, desc=None, labels=None, attrs=None, time_created=None, lock_level=None, id=None, input_description=None, hide_input_label=False, output_description=None, hide_output_label=False)

Gets or creates a model version.

If an accessible model version with name name does not already exist under this registered model, it will be created and initialized with specified metadata parameters. If such a model version does already exist, it will be retrieved; specifying metadata parameters in this case will raise a warning.

Parameters:
  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • desc (str, optional) – Description of the model version.

  • labels (list of str, optional) – Labels of the model version.

  • attrs (dict of str to {None, bool, float, int, str}, optional) – Attributes of the model version.

  • lock_level (lock, default Open) – Lock level to set when creating this model version.

  • id (str, optional) – ID of the model version. This parameter cannot be provided alongside name, and other parameters will be ignored.

  • input_description (str, optional) – Description of the model version’s input.

  • hide_input_label (bool, default False) – Whether to hide the model version’s input label.

  • output_description (str, optional) – Description of the model version’s output.

  • hide_output_label (bool, default False) – Whether to hide the model version’s output label.

Returns:

RegisteredModelVersion

Raises:

ValueError – If name and id are both passed in.

get_pii()

Returns the PII value of this registered model.

New in version 0.24.0.

Returns:

boolTrue indicates that the model ingests personally identifiable information.

get_task_type()

Gets this registered model task type

Returns:

task_type (task_type) – This registered model task type.

get_version(name=None, id=None)

Gets a model version of this registered model by name or id

Parameters:
  • name (str, optional) – Name of the model version. If no name is provided, one will be generated.

  • id (str, optional) – ID of the model version. This parameter cannot be provided alongside name, and other parameters will be ignored.

Returns:

RegisteredModelVersion

set_data_type(data_type)

Sets this registered model data type

Parameters:

data_type (data_type) – Data type to set.

set_pii(pii)

Updates the PII value of this registered model.

New in version 0.24.0.

Parameters:

pii (bool) – True indicates that the model ingests personally identifiable information.

Warning

You MUST update any live endpoints running this model in order to propagate this change. A simple no-op update is sufficient.

set_task_type(task_type)

Sets this registered model task type

Parameters:

task_type (task_type) – Task type to set.

set_version(*args, **kwargs)

Alias for RegisteredModel.get_or_create_version().