Пример #1
0
def k8s_sklearn_model(sklearn_model: Model, k8s_runtime: SeldonKubernetesRuntime) -> Generator[Model, None, None]:
    sklearn_model.runtime = k8s_runtime

    sklearn_model.deploy()
    sklearn_model.wait_ready(timeout_secs=60)

    yield sklearn_model

    sklearn_model.undeploy()
Пример #2
0
def k8s_inference_pipeline(
    sklearn_model: Model,
    xgboost_model: Model,
    k8s_runtime: SeldonKubernetesRuntime,
    k8s_runtime_v2: SeldonKubernetesRuntime,
):
    sklearn_model.runtime = k8s_runtime
    xgboost_model.runtime = k8s_runtime

    @pipeline(
        name="classifier",
        runtime=k8s_runtime_v2,
        models=[sklearn_model, xgboost_model],
        uri="gs://seldon-models/tempo/test",
    )
    def _pipeline(payload: np.ndarray) -> np.ndarray:
        res1 = sklearn_model(payload=payload)
        if res1[0][0] > 0.7:
            return res1
        else:
            return xgboost_model(payload=payload)

    _pipeline.save()
    _pipeline.upload()
    _pipeline.deploy()
    _pipeline.wait_ready(timeout_secs=60)

    # TODO: Pipeline shouldn't become ready until models are ready
    sklearn_model.wait_ready(timeout_secs=60)
    xgboost_model.wait_ready(timeout_secs=60)

    yield _pipeline

    try:
        _pipeline.undeploy()
    except docker.errors.NotFound:
        # Ignore if the pipeline was already undeployed
        pass