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()
def test_deploy(): rt = SeldonDeployRuntime( host="http://34.105.136.157/seldon-deploy/api/v1alpha1", user="******", password="******", k8s_options=KubernetesOptions(namespace="seldon"), ) sklearn_model = Model( name="test-iris-sklearn", runtime=rt, platform=ModelFramework.SKLearn, uri="gs://seldon-models/sklearn/iris", local_folder=os.getcwd() + "/sklearn", ) sklearn_model.deploy() sklearn_model.wait_ready() sklearn_model(np.array([[4.9, 3.1, 1.5, 0.2]]))
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