Skip to content

Commit 493463e

Browse files
committed
[Deploy] Recursively find the model serving package folder
1 parent 2c7d434 commit 493463e

2 files changed

Lines changed: 25 additions & 28 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os
2+
3+
4+
def find_file_inside_folder(folder_path, file_name):
5+
"""
6+
Recursively search for a file inside a folder and its sub-folders.
7+
return the full path of the file if found, otherwise return None.
8+
"""
9+
for root, dirs, files in os.walk(folder_path):
10+
if file_name in files:
11+
return os.path.join(root, file_name)
12+
13+
return None

python/fedml/computing/scheduler/model_scheduler/worker_job_runner.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import yaml
1111
from fedml.computing.scheduler.comm_utils.job_utils import JobRunnerUtils
1212
from fedml.core.mlops import MLOpsRuntimeLog
13+
from fedml.computing.scheduler.comm_utils import file_utils
1314
from .device_client_constants import ClientConstants
1415
from .device_model_cache import FedMLModelCache
1516
from ..scheduler_core.general_constants import GeneralConstants
@@ -205,7 +206,7 @@ def run_impl(self, run_extend_queue_list, sender_message_center,
205206
# Check if the package is already downloaded
206207
unzip_package_path = ""
207208
if os.path.exists(os.path.join(models_root_dir, parent_fd)):
208-
unzip_package_path = self.find_previous_downloaded_pkg(os.path.join(models_root_dir, parent_fd), model_name)
209+
unzip_package_path = self.find_previous_downloaded_pkg(os.path.join(models_root_dir, parent_fd))
209210

210211
# Download the package if not found
211212
if unzip_package_path == "":
@@ -510,30 +511,13 @@ def build_dynamic_constrain_variables(self, run_id, run_config):
510511
pass
511512

512513
@staticmethod
513-
def find_previous_downloaded_pkg(parent_dir: str, model_name: str) -> str:
514-
unzip_fd = ""
515-
res = ""
516-
517-
for folder in os.listdir(parent_dir):
518-
if folder.startswith("unzip_fedml_run"):
519-
unzip_fd = os.path.join(parent_dir, folder)
520-
break
521-
522-
exact_matched = False
523-
524-
if unzip_fd == "":
525-
return res
526-
527-
for folder in os.listdir(unzip_fd):
528-
if folder == model_name:
529-
res = os.path.join(unzip_fd, folder)
530-
exact_matched = True
531-
break
532-
533-
if not exact_matched:
534-
# Use the first folder found
535-
for folder in os.listdir(unzip_fd):
536-
res = os.path.join(unzip_fd, folder)
537-
break
538-
539-
return res
514+
def find_previous_downloaded_pkg(parent_dir: str) -> str:
515+
"""
516+
Find a folder inside parent_dir that contains the fedml_model_config.yaml file.
517+
"""
518+
res = file_utils.find_file_inside_folder(parent_dir, ClientConstants.MODEL_REQUIRED_MODEL_CONFIG_FILE)
519+
if res is not None:
520+
# return the parent folder of res
521+
return os.path.dirname(res)
522+
else:
523+
return ""

0 commit comments

Comments
 (0)