Skip to content

Commit 3fbc4b4

Browse files
authored
[HWORKS-349] Add compatibility with 3.0 backend (#166)
* [HWORKS-349] Add compatibility with 3.0 backend * [HWORKS-349] (2) fix missing value for model_framework * [HWORKS-349] (3) fix missing deployment status conditions
1 parent 964797d commit 3fbc4b4

File tree

8 files changed

+52
-15
lines changed

8 files changed

+52
-15
lines changed

python/hsml/engine/serving_engine.py

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ def start(self, deployment_instance, await_status: int) -> bool:
9393
)
9494

9595
if not done:
96-
total_steps = (
97-
len(self.START_STEPS) - 1
98-
) + self._get_min_starting_instances(deployment_instance)
99-
pbar = tqdm(total=total_steps)
96+
min_instances = self._get_min_starting_instances(deployment_instance)
97+
num_steps = (len(self.START_STEPS) - 1) + min_instances
98+
if deployment_instance._predictor._state.condition is None:
99+
num_steps = min_instances # backward compatibility
100+
pbar = tqdm(total=num_steps)
100101
pbar.set_description("Creating deployment")
101102

102103
# set progress function
103-
def update_progress(state, num_instances=0):
104+
def update_progress(state, num_instances):
104105
(progress, desc) = self._get_starting_progress(
105106
pbar.n, state, num_instances
106107
)
@@ -109,7 +110,7 @@ def update_progress(state, num_instances=0):
109110
pbar.set_description(desc)
110111

111112
try:
112-
update_progress(state)
113+
update_progress(state, num_instances=0)
113114
self._serving_api.post(
114115
deployment_instance, DEPLOYMENT.ACTION_START
115116
) # start deployment
@@ -138,19 +139,22 @@ def stop(self, deployment_instance, await_status: int) -> bool:
138139
if deployment_instance.requested_instances >= num_instances
139140
else num_instances
140141
)
142+
if deployment_instance._predictor._state.condition is None:
143+
# backward compatibility
144+
num_steps = self._get_min_starting_instances(deployment_instance)
141145
pbar = tqdm(total=num_steps)
142146
pbar.set_description("Preparing to stop deployment")
143147

144148
# set progress function
145-
def update_progress(state, num_instances=0):
149+
def update_progress(state, num_instances):
146150
(progress, desc) = self._get_stopping_progress(
147151
pbar.total, pbar.n, state, num_instances
148152
)
149153
pbar.update(progress)
150154
if desc is not None:
151155
pbar.set_description(desc)
152156

153-
update_progress(state)
157+
update_progress(state, num_instances)
154158
self._serving_api.post(
155159
deployment_instance, DEPLOYMENT.ACTION_STOP
156160
) # stop deployment
@@ -225,17 +229,25 @@ def _check_status(self, deployment_instance, desired_status):
225229
print("Deployment is already stopping")
226230
return (True, state)
227231
if state.status == PREDICTOR_STATE.STATUS_STARTING:
228-
raise ModelServingException(
229-
"Deployment is starting, please wait until it completely starts"
230-
)
232+
if state.condition is not None:
233+
raise ModelServingException(
234+
"Deployment is starting, please wait until it completely starts"
235+
)
231236
if state.status == PREDICTOR_STATE.STATUS_UPDATING:
232-
raise ModelServingException(
233-
"Deployment is updating, please wait until the update completes"
234-
)
237+
if state.condition is not None:
238+
raise ModelServingException(
239+
"Deployment is updating, please wait until the update completes"
240+
)
235241

236242
return (False, state)
237243

238244
def _get_starting_progress(self, current_step, state, num_instances):
245+
if state.condition is None: # backward compatibility
246+
progress = num_instances - current_step
247+
if state.status == PREDICTOR_STATE.STATUS_RUNNING:
248+
return (progress, "Deployment is ready")
249+
return (progress, None if current_step == 0 else "Deployment is starting")
250+
239251
step = self.START_STEPS.index(state.condition.type)
240252
if (
241253
state.condition.type == PREDICTOR_STATE.CONDITION_TYPE_STARTED
@@ -253,6 +265,15 @@ def _get_starting_progress(self, current_step, state, num_instances):
253265
return (progress, desc)
254266

255267
def _get_stopping_progress(self, total_steps, current_step, state, num_instances):
268+
if state.condition is None: # backward compatibility
269+
progress = (total_steps - num_instances) - current_step
270+
if state.status == PREDICTOR_STATE.STATUS_STOPPED:
271+
return (progress, "Deployment is stopped")
272+
return (
273+
progress,
274+
None if total_steps == current_step else "Deployment is stopping",
275+
)
276+
256277
step = 0
257278
if state.condition.type == PREDICTOR_STATE.CONDITION_TYPE_SCHEDULED:
258279
step = 1 if state.condition.status is None else 0

python/hsml/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ def from_response_json(cls, json_dict):
165165

166166
def update_from_response_json(self, json_dict):
167167
json_decamelized = humps.decamelize(json_dict)
168+
if "type" in json_decamelized: # backwards compatibility
169+
_ = json_decamelized.pop("type")
168170
self.__init__(**json_decamelized)
169171
return self
170172

python/hsml/predictor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ def extract_fields_from_json(cls, json_decamelized):
210210
)
211211
kwargs["model_path"] = json_decamelized.pop("model_path")
212212
kwargs["model_version"] = json_decamelized.pop("model_version")
213-
kwargs["model_framework"] = json_decamelized.pop("model_framework")
213+
kwargs["model_framework"] = (
214+
json_decamelized.pop("model_framework")
215+
if "model_framework" in json_decamelized
216+
else MODEL.FRAMEWORK_SKLEARN # backward compatibility
217+
)
214218
kwargs["artifact_version"] = util.extract_field_from_json(
215219
json_decamelized, "artifact_version"
216220
)

python/hsml/python/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ def __init__(
6666

6767
def update_from_response_json(self, json_dict):
6868
json_decamelized = humps.decamelize(json_dict)
69+
if "type" in json_decamelized: # backwards compatibility
70+
_ = json_decamelized.pop("type")
6971
self.__init__(**json_decamelized)
7072
return self

python/hsml/sklearn/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ def __init__(
6666

6767
def update_from_response_json(self, json_dict):
6868
json_decamelized = humps.decamelize(json_dict)
69+
if "type" in json_decamelized: # backwards compatibility
70+
_ = json_decamelized.pop("type")
6971
self.__init__(**json_decamelized)
7072
return self

python/hsml/tensorflow/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ def __init__(
6666

6767
def update_from_response_json(self, json_dict):
6868
json_decamelized = humps.decamelize(json_dict)
69+
if "type" in json_decamelized: # backwards compatibility
70+
_ = json_decamelized.pop("type")
6971
self.__init__(**json_decamelized)
7072
return self

python/hsml/torch/model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,7 @@ def __init__(
6666

6767
def update_from_response_json(self, json_dict):
6868
json_decamelized = humps.decamelize(json_dict)
69+
if "type" in json_decamelized: # backwards compatibility
70+
_ = json_decamelized.pop("type")
6971
self.__init__(**json_decamelized)
7072
return self

python/hsml/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def _is_numpy_scalar(x):
108108

109109
def set_model_class(model):
110110
_ = model.pop("href")
111+
if "type" in model: # backwards compatibility
112+
_ = model.pop("type")
111113

112114
if "framework" not in model:
113115
return BaseModel(**model)

0 commit comments

Comments
 (0)