From 97b1c5070e40ea26cee32615616067708b09ae2a Mon Sep 17 00:00:00 2001 From: Heiru Wu Date: Fri, 26 Jan 2024 19:12:31 +0800 Subject: [PATCH 1/3] feat(ray): determine ram usage by file size --- instill/helpers/ray_config.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/instill/helpers/ray_config.py b/instill/helpers/ray_config.py index d4a6f69..60fc490 100644 --- a/instill/helpers/ray_config.py +++ b/instill/helpers/ray_config.py @@ -13,6 +13,7 @@ DEFAULT_RUNTIME_ENV, ) from instill.helpers.utils import get_dir_size +from instill.helpers.errors import ModelPathException class InstillDeployable: @@ -36,6 +37,10 @@ def _update_num_cpus(self, num_cpus: float): if self._deployment.ray_actor_options is not None: self._deployment.ray_actor_options.update({"num_cpus": num_cpus}) + def _update_memory(self, memory: float): + if self._deployment.ray_actor_options is not None: + self._deployment.ray_actor_options.update({"memory": memory}) + def _update_num_gpus(self, num_gpus: float): if self._deployment.ray_actor_options is not None: self._deployment.ray_actor_options.update({"num_gpus": num_gpus}) @@ -49,7 +54,14 @@ def _determine_vram_usage(self, model_path: str, vram: str): ) if os.path.isdir(model_path): return 1.1 * get_dir_size(model_path) / (1024 * 1024 * 1024) / float(vram) - return 0.25 + raise ModelPathException + + def _determine_ram_usage(self, model_path: str): + if os.path.isfile(model_path): + return 1.1 * os.path.getsize(model_path) + if os.path.isdir(model_path): + return 1.1 * get_dir_size(model_path) + raise ModelPathException def update_min_replicas(self, num_replicas: int): new_autoscaling_config = DEFAULT_AUTOSCALING_CONFIG @@ -78,6 +90,8 @@ def deploy(self, model_folder_path: str, ray_addr: str, vram: str): if self.use_gpu: self._update_num_gpus(self._determine_vram_usage(model_path, vram)) + else: + self._update_memory(self._determine_ram_usage(model_path)) serve.run( self._deployment.options(name=application_name).bind(model_path), From 3bab48841e65c609abf9d14695e09225b7277a3e Mon Sep 17 00:00:00 2001 From: Heiru Wu Date: Fri, 26 Jan 2024 19:13:05 +0800 Subject: [PATCH 2/3] chore: fix import order --- instill/helpers/ray_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instill/helpers/ray_config.py b/instill/helpers/ray_config.py index 60fc490..b4f7826 100644 --- a/instill/helpers/ray_config.py +++ b/instill/helpers/ray_config.py @@ -12,8 +12,8 @@ DEFAULT_RAY_ACTOR_OPRTIONS, DEFAULT_RUNTIME_ENV, ) -from instill.helpers.utils import get_dir_size from instill.helpers.errors import ModelPathException +from instill.helpers.utils import get_dir_size class InstillDeployable: From b83e56b71cfdea5bc5f50fe3cb2b53749d55d9df Mon Sep 17 00:00:00 2001 From: Heiru Wu Date: Fri, 26 Jan 2024 19:14:33 +0800 Subject: [PATCH 3/3] chore: commit missing file --- instill/helpers/errors.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 instill/helpers/errors.py diff --git a/instill/helpers/errors.py b/instill/helpers/errors.py new file mode 100644 index 0000000..ef03503 --- /dev/null +++ b/instill/helpers/errors.py @@ -0,0 +1,3 @@ +class ModelPathException(Exception): + def __str__(self) -> str: + return "model path is not valid"