Skip to content

Commit

Permalink
New method to create/deploy trained model object
Browse files Browse the repository at this point in the history
  • Loading branch information
abchoo committed Jan 19, 2021
1 parent 488d992 commit b58d1de
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/google/uuid v1.1.1
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8
github.com/json-iterator/go v1.1.10
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/kelseyhightower/envconfig v1.4.0
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a // indirect
github.com/onsi/ginkgo v1.14.0
github.com/onsi/gomega v1.10.2
github.com/pkg/errors v0.9.1
Expand All @@ -39,6 +39,7 @@ require (
istio.io/gogo-genproto v0.0.0-20191029161641-f7d19ec0141d // indirect
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29
knative.dev/networking v0.0.0-20200922180040-a71b40c69b15
Expand Down
24 changes: 24 additions & 0 deletions python/kfserving/kfserving/api/kf_serving_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,30 @@ def wait_isvc_ready(self, name, namespace=None, # pylint:disable=too-many-argum
raise RuntimeError("Timeout to start the InferenceService {}. \
The InferenceService is as following: {}".format(name, current_isvc))

def create_trained_model(self, trainedmodel, namespace):
"""
Create a trained model
:param trainedmodel: trainedmodel object
:param namespace: defaults to current or default namespace
:return:
"""

if trainedmodel.api_version == constants.KFSERVING_V1ALPHA2:
logging.warning("The version v1alpha2 will be deprecated from KFServing 0.6 release.")
version = trainedmodel.api_version.split("/")[1]

try:
outputs = self.api_instance.create_namespaced_custom_object(
constants.KFSERVING_GROUP,
version,
namespace,
constants.KFSERVING_PLURAL_TRAINEDMODEL,
trainedmodel)
except client.rest.ApiException as e:
raise RuntimeError(
"Exception when calling CustomObjectsApi->create_namespaced_custom_object:\
%s\n" % e)

def wait_model_ready(self, service_name, model_name, isvc_namespace=None, # pylint:disable=too-many-arguments
isvc_version=constants.KFSERVING_V1BETA1_VERSION,
cluster_ip=None,
Expand Down
29 changes: 12 additions & 17 deletions test/e2e/predictor/test_multi_model_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from ..common.utils import predict, get_cluster_ip
from ..common.utils import KFSERVING_TEST_NAMESPACE

api_v1alpha1_version = constants.KFSERVING_GROUP + "/v1alpha1"
api_v1beta1_version = constants.KFSERVING_GROUP + "/" + constants.KFSERVING_V1BETA1_VERSION

KFServing = KFServingClient(config_file=os.environ.get("KUBECONFIG", "~/.kube/config"))
Expand All @@ -50,7 +49,7 @@ def test_mms_sklearn_kfserving():
)
)

service_name = "isvc-sklearn"
service_name = "isvc-sklearn-mms"
isvc = V1beta1InferenceService(
api_version=api_v1beta1_version,
kind=constants.KFSERVING_KIND,
Expand All @@ -77,7 +76,7 @@ def test_mms_sklearn_kfserving():
model1_name = "model1-sklearn"
model2_name = "model2-sklearn"
model1 = V1alpha1TrainedModel(
api_version=api_v1alpha1_version,
api_version=constants.KFSERVING_V1ALPHA1,
kind=constants.KFSERVING_KIND_TRAINEDMODEL,
metadata=client.V1ObjectMeta(
name=model1_name,
Expand All @@ -90,7 +89,7 @@ def test_mms_sklearn_kfserving():
)

model2 = V1alpha1TrainedModel(
api_version=api_v1alpha1_version,
api_version=constants.KFSERVING_V1ALPHA1,
kind=constants.KFSERVING_KIND_TRAINEDMODEL,
metadata=client.V1ObjectMeta(
name=model2_name,
Expand All @@ -103,14 +102,12 @@ def test_mms_sklearn_kfserving():
)

# Create an instance of inference service with isvc
KFServing.create(isvc, version=constants.KFSERVING_V1BETA1_VERSION)
KFServing.create(isvc)
KFServing.wait_isvc_ready(service_name, namespace=KFSERVING_TEST_NAMESPACE)

# Create instances of trained models using model1 and model2
KFServing.create(model1, namespace=KFSERVING_TEST_NAMESPACE, version=constants.KFSERVING_V1ALPHA1_VERSION,
plural=constants.KFSERVING_PLURAL_TRAINEDMODEL)
KFServing.create(model2, namespace=KFSERVING_TEST_NAMESPACE, version=constants.KFSERVING_V1ALPHA1_VERSION,
plural=constants.KFSERVING_PLURAL_TRAINEDMODEL)
KFServing.create_trained_model(model1, KFSERVING_TEST_NAMESPACE)
KFServing.create_trained_model(model2, KFSERVING_TEST_NAMESPACE)

cluster_ip = get_cluster_ip()

Expand Down Expand Up @@ -142,7 +139,7 @@ def test_mms_xgboost_kfserving():
)
)

service_name = "isvc-xgboost"
service_name = "isvc-xgboost-mms"
isvc = V1beta1InferenceService(
api_version=api_v1beta1_version,
kind=constants.KFSERVING_KIND,
Expand All @@ -169,7 +166,7 @@ def test_mms_xgboost_kfserving():
model1_name = "model1-xgboost"
model2_name = "model2-xgboost"
model1 = V1alpha1TrainedModel(
api_version=api_v1alpha1_version,
api_version=constants.KFSERVING_V1ALPHA1,
kind=constants.KFSERVING_KIND_TRAINEDMODEL,
metadata=client.V1ObjectMeta(
name=model1_name,
Expand All @@ -182,7 +179,7 @@ def test_mms_xgboost_kfserving():
)

model2 = V1alpha1TrainedModel(
api_version=api_v1alpha1_version,
api_version=constants.KFSERVING_V1ALPHA1,
kind=constants.KFSERVING_KIND_TRAINEDMODEL,
metadata=client.V1ObjectMeta(
name=model2_name,
Expand All @@ -195,14 +192,12 @@ def test_mms_xgboost_kfserving():
)

# Create an instance of inference service with isvc
KFServing.create(isvc, version=constants.KFSERVING_V1BETA1_VERSION)
KFServing.create(isvc)
KFServing.wait_isvc_ready(service_name, namespace=KFSERVING_TEST_NAMESPACE)

# Create instances of trained models using model1 and model2
KFServing.create(model1, namespace=KFSERVING_TEST_NAMESPACE, version=constants.KFSERVING_V1ALPHA1_VERSION,
plural=constants.KFSERVING_PLURAL_TRAINEDMODEL)
KFServing.create(model2, namespace=KFSERVING_TEST_NAMESPACE, version=constants.KFSERVING_V1ALPHA1_VERSION,
plural=constants.KFSERVING_PLURAL_TRAINEDMODEL)
KFServing.create_trained_model(model1, KFSERVING_TEST_NAMESPACE)
KFServing.create_trained_model(model2, KFSERVING_TEST_NAMESPACE)

cluster_ip = get_cluster_ip()

Expand Down

0 comments on commit b58d1de

Please sign in to comment.