Skip to content

Commit 18a9fef

Browse files
committed
Improved model deployment progress bar.
1 parent c20b4d8 commit 18a9fef

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

ads/common/oci_mixin.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
WORK_REQUEST_STOP_STATE = ("SUCCEEDED", "FAILED", "CANCELED")
3434
DEFAULT_WAIT_TIME = 1200
3535
DEFAULT_POLL_INTERVAL = 10
36-
DEFAULT_WORKFLOW_STEPS = 2
36+
WORK_REQUEST_PERCENTAGE = 100
3737

3838

3939
class MergeStrategy(Enum):
@@ -939,7 +939,6 @@ def get_work_request_response(
939939
def wait_for_progress(
940940
self,
941941
work_request_id: str,
942-
num_steps: int = DEFAULT_WORKFLOW_STEPS,
943942
max_wait_time: int = DEFAULT_WAIT_TIME,
944943
poll_interval: int = DEFAULT_POLL_INTERVAL,
945944
):
@@ -949,8 +948,6 @@ def wait_for_progress(
949948
----------
950949
work_request_id: str
951950
Work Request OCID.
952-
num_steps: (int, optional). Defaults to 2.
953-
Number of steps for the progress indicator.
954951
max_wait_time: int
955952
Maximum amount of time to wait in seconds (Defaults to 1200).
956953
Negative implies infinite wait time.
@@ -965,13 +962,14 @@ def wait_for_progress(
965962

966963
i = 0
967964
start_time = time.time()
968-
with get_progress_bar(num_steps) as progress:
965+
with get_progress_bar(WORK_REQUEST_PERCENTAGE) as progress:
969966
seconds_since = time.time() - start_time
970967
exceed_max_time = max_wait_time > 0 and seconds_since >= max_wait_time
971968
if exceed_max_time:
972969
logger.error(f"Max wait time ({max_wait_time} seconds) exceeded.")
970+
previous_percent_complete = 0
973971
while not exceed_max_time and (
974-
not work_request_logs or len(work_request_logs) < num_steps
972+
not work_request_logs or previous_percent_complete <= WORK_REQUEST_PERCENTAGE
975973
):
976974
time.sleep(poll_interval)
977975
new_work_request_logs = []
@@ -988,9 +986,23 @@ def wait_for_progress(
988986
work_request_logs[i:] if work_request_logs else []
989987
)
990988

991-
for wr_item in new_work_request_logs:
992-
progress.update(wr_item.message)
993-
i += 1
989+
percent_change = work_request.percent_complete - previous_percent_complete
990+
previous_percent_complete = work_request.percent_complete
991+
992+
if len(new_work_request_logs) > 0:
993+
start_index = True
994+
for wr_item in new_work_request_logs:
995+
if start_index:
996+
progress.update(wr_item.message, percent_change)
997+
start_index = False
998+
else:
999+
progress.update(wr_item.message, 0)
1000+
i += 1
1001+
else:
1002+
# if there is new percent change but the new work request logs is empty
1003+
# needs to add this percent change to the bar to ensure the final percentage is 100
1004+
if percent_change != 0:
1005+
progress.update(n=percent_change)
9941006

9951007
if work_request and work_request.status in WORK_REQUEST_STOP_STATE:
9961008
if work_request.status != "SUCCEEDED":

ads/model/service/oci_datascience_model_deployment.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020

2121
DEFAULT_WAIT_TIME = 1200
2222
DEFAULT_POLL_INTERVAL = 10
23-
DEACTIVATE_WORKFLOW_STEPS = 2
24-
DELETE_WORKFLOW_STEPS = 2
25-
ACTIVATE_WORKFLOW_STEPS = 6
26-
CREATE_WORKFLOW_STEPS = 6
2723
ALLOWED_STATUS = [
2824
State.ACTIVE.name,
2925
State.CREATING.name,
@@ -203,7 +199,6 @@ def activate(
203199
try:
204200
self.wait_for_progress(
205201
self.workflow_req_id,
206-
ACTIVATE_WORKFLOW_STEPS,
207202
max_wait_time,
208203
poll_interval
209204
)
@@ -254,7 +249,6 @@ def create(
254249
try:
255250
self.wait_for_progress(
256251
self.workflow_req_id,
257-
CREATE_WORKFLOW_STEPS,
258252
max_wait_time,
259253
poll_interval
260254
)
@@ -317,7 +311,6 @@ def deactivate(
317311
try:
318312
self.wait_for_progress(
319313
self.workflow_req_id,
320-
DEACTIVATE_WORKFLOW_STEPS,
321314
max_wait_time,
322315
poll_interval
323316
)
@@ -387,7 +380,6 @@ def delete(
387380
try:
388381
self.wait_for_progress(
389382
self.workflow_req_id,
390-
DELETE_WORKFLOW_STEPS,
391383
max_wait_time,
392384
poll_interval
393385
)

tests/unitary/default_setup/model_deployment/test_oci_datascience_model_deployment.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
from ads.common.oci_mixin import OCIModelMixin, OCIWorkRequestMixin
1616

1717
from ads.model.service.oci_datascience_model_deployment import (
18-
ACTIVATE_WORKFLOW_STEPS,
19-
CREATE_WORKFLOW_STEPS,
20-
DEACTIVATE_WORKFLOW_STEPS,
21-
DELETE_WORKFLOW_STEPS,
2218
OCIDataScienceModelDeployment,
2319
)
2420

@@ -163,7 +159,6 @@ def test_activate_with_waiting(self):
163159
mock_activate.assert_called_with(self.mock_model_deployment.id)
164160
mock_wait.assert_called_with(
165161
"test",
166-
ACTIVATE_WORKFLOW_STEPS,
167162
1,
168163
1,
169164
)
@@ -248,7 +243,6 @@ def test_deactivate_with_waiting(self):
248243
)
249244
mock_wait.assert_called_with(
250245
"test",
251-
DEACTIVATE_WORKFLOW_STEPS,
252246
1,
253247
1,
254248
)
@@ -330,7 +324,6 @@ def test_create_with_waiting(self):
330324
mock_update_from_oci_model.assert_called()
331325
mock_wait.assert_called_with(
332326
"test",
333-
CREATE_WORKFLOW_STEPS,
334327
1,
335328
1,
336329
)
@@ -468,7 +461,6 @@ def test_delete_with_waiting(self):
468461
mock_delete.assert_called_with(self.mock_model_deployment.id)
469462
mock_wait.assert_called_with(
470463
"test",
471-
DELETE_WORKFLOW_STEPS,
472464
1,
473465
1,
474466
)

0 commit comments

Comments
 (0)