示例#1
0
 def test_incomplete_verta(self, model):
     msg_match = (
         r"^model must finish implementing the following methods of VertaModelBase: "
     )
     msg_match += re.escape(str(list(sorted(model.__abstractmethods__))))
     with pytest.raises(TypeError, match=msg_match):
         model_validator.must_verta(model)
示例#2
0
    def create_standard_model(
        self,
        model_cls,
        environment,
        code_dependencies=None,
        model_api=None,
        artifacts=None,
        name=None,
        desc=None,
        labels=None,
        attrs=None,
        lock_level=None,
    ):
        """Create a Standard Verta Model version from a Verta Model Specification.

        .. versionadded:: 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 :class:`~verta.registry.VertaModelBase`
            Model class that implements ``VertaModelBase``.
        environment : :class:`~verta.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
            :meth:`RegisteredModelVersion.log_model`.
        model_api : :class:`~verta.utils.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 : :mod:`~verta.registry.lock`, default :class:`~verta.registry.lock.Open`
            Lock level to set when creating this model version.

        Returns
        -------
        :class:`~verta.registry.entities.RegisteredModelVersion`

        Examples
        --------
        .. code-block:: python

            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)

        """
        model_validator.must_verta(model_cls)

        return self._create_standard_model_from_spec(
            model=model_cls,
            environment=environment,
            code_dependencies=code_dependencies,
            model_api=model_api,
            artifacts=artifacts,
            name=name,
            desc=desc,
            labels=labels,
            attrs=attrs,
            lock_level=lock_level,
        )
示例#3
0
 def test_decorated_verta(self, model):
     with pytest.warns(None) as record:
         model_validator.must_verta(model)
     assert not record  # no warning of missing decorator on predict()
示例#4
0
 def test_verta(self, model):
     msg_match = "^" + re.escape(
         "model predict() is not decorated with verta.registry.verify_io;")
     with pytest.warns(UserWarning, match=msg_match):
         assert model_validator.must_verta(model)
示例#5
0
 def test_not_verta(self, model):
     msg_match = r"^model must be a subclass of verta.registry.VertaModelBase.*"
     with pytest.raises(TypeError, match=msg_match):
         model_validator.must_verta(model)
示例#6
0
 def test_bad_init_verta(self, model):
     msg_match = "^" + re.escape(
         "model __init__() parameters must be named ('self', 'artifacts'), not "
     )
     with pytest.raises(TypeError, match=msg_match):
         model_validator.must_verta(model)