Ejemplo n.º 1
0
def test_undeploy_pipeline_docker(inference_pipeline: Pipeline,
                                  docker_runtime: SeldonDockerRuntime):
    inference_pipeline.undeploy()

    for model in inference_pipeline._models:
        with pytest.raises(docker.errors.NotFound):
            docker_runtime._get_container(model._details)
Ejemplo n.º 2
0
async def test_pipeline_save_load(inference_pipeline: Pipeline, tmp_path: str):
    inference_pipeline.details.local_folder = tmp_path
    inference_pipeline.save()

    loaded_pipeline = Pipeline.load(tmp_path)
    y_pred = loaded_pipeline(np.array([[4.9, 3.1, 1.5, 0.2]]))

    np.testing.assert_allclose(y_pred, [[0.8, 0.19, 0.01]], atol=1e-2)
Ejemplo n.º 3
0
async def test_pipeline_save(inference_pipeline: Pipeline, tmp_path: str):
    pipeline_path = os.path.join(tmp_path, "pipeline.pickle")
    inference_pipeline.save(pipeline_path)

    loaded_pipeline = Pipeline.load(pipeline_path)

    y_pred = loaded_pipeline(np.array([[4.9, 3.1, 1.5, 0.2]]))

    np.testing.assert_allclose(y_pred, [[0.8, 0.19, 0.01]], atol=1e-2)
Ejemplo n.º 4
0
    def _pipeline(f):
        if inspect.isclass(f):
            K = f
            func = None

            for a in dir(K):
                if not a.startswith("__") and callable(getattr(
                        K, a)) and hasattr(getattr(K, a), "predict"):
                    func = getattr(K, a)
                    break
            K.pipeline = Pipeline(
                name,
                runtime=runtime,
                local_folder=local_folder,
                uri=uri,
                models=models,
                inputs=inputs,
                outputs=outputs,
                pipeline_func=func,
                conda_env=conda_env,
            )
            setattr(K, "deploy", K.pipeline.deploy)
            setattr(K, "deploy_models", K.pipeline.deploy_models)
            setattr(K, "wait_ready", K.pipeline.wait_ready)
            setattr(K, "undeploy", K.pipeline.undeploy)
            setattr(K, "undeploy_models", K.pipeline.undeploy_models)
            setattr(K, "request", K.pipeline.request)
            setattr(K, "set_runtime", K.pipeline.set_runtime)
            setattr(K, "to_k8s_yaml", K.pipeline.to_k8s_yaml)
            setattr(K, "save", K.pipeline.save)
            setattr(K, "remote", K.pipeline.remote)
            setattr(K, "upload", K.pipeline.upload)
            setattr(K, "download", K.pipeline.download)

            orig_init = K.__init__

            # Make copy of original __init__, so we can call it without recursion
            def __init__(self, *args, **kws):
                K.pipeline.set_cls(self)
                orig_init(self, *args, **kws)  # Call the original __init__

            K.__init__ = __init__  # Set the class' __init__ to the new one

            return K
        else:
            return Pipeline(
                name,
                runtime=runtime,
                local_folder=local_folder,
                uri=uri,
                models=models,
                inputs=inputs,
                outputs=outputs,
                pipeline_func=f,
                conda_env=conda_env,
            )
Ejemplo n.º 5
0
    def _pipeline(f):
        if inspect.isclass(f):
            K = f
            func = None

            for a in dir(K):
                if (not a.startswith("__") and callable(getattr(K, a))
                        and hasattr(getattr(K, a), "predict")):
                    func = getattr(K, a)
                    break
            K.pipeline = Pipeline(
                name,
                runtime=runtime,
                models=models,
                inputs=inputs,
                outputs=outputs,
                pipeline_func=func,
            )
            setattr(K, "deploy", K.pipeline.deploy)
            setattr(K, "deploy_models", K.pipeline.deploy_models)
            setattr(K, "undeploy", K.pipeline.undeploy)
            setattr(K, "undeploy_models", K.pipeline.undeploy_models)
            setattr(K, "request", K.pipeline.request)

            orig_init = K.__init__

            # Make copy of original __init__, so we can call it without recursion
            def __init__(self, *args, **kws):
                K.pipeline.set_cls(self)
                orig_init(self, *args, **kws)  # Call the original __init__

            K.__init__ = __init__  # Set the class' __init__ to the new one

            return K
        else:
            return Pipeline(
                name,
                runtime=runtime,
                models=models,
                inputs=inputs,
                outputs=outputs,
                pipeline_func=f,
            )
Ejemplo n.º 6
0
def test_pipeline_k8s(k8s_inference_pipeline: Pipeline, x_input):
    y_pred = k8s_inference_pipeline.remote(payload=x_input)

    np.testing.assert_allclose(y_pred, [2.0], atol=1e-2)
Ejemplo n.º 7
0
def test_seldon_pipeline_request_docker(
    inference_pipeline: Pipeline, x_input, expected
):
    y_pred = inference_pipeline.request(x_input)

    assert y_pred == expected
Ejemplo n.º 8
0
def test_pipeline_remote(inference_pipeline: Pipeline,
                         runtime: SeldonDockerRuntime, x_input):
    y_pred = inference_pipeline.remote(payload=x_input)

    np.testing.assert_allclose(y_pred, [2.0], atol=1e-2)
Ejemplo n.º 9
0
def pipeline_uri(inference_pipeline: Pipeline) -> str:
    inference_pipeline.save(save_env=False)

    return inference_pipeline.details.local_folder
Ejemplo n.º 10
0
def test_seldon_pipeline_request_docker(
        inference_pipeline_deployed_with_runtime: Pipeline, x_input, expected):
    y_pred = inference_pipeline_deployed_with_runtime.request(x_input)

    assert y_pred == expected
Ejemplo n.º 11
0
    async def load(self) -> bool:
        pipeline_uri = await get_model_uri(self._settings)
        self._pipeline = Pipeline.load(pipeline_uri)

        self.ready = True
        return self.ready