From 1ec117dbb2bdeefbfb723f9d369d1696cac2b0d6 Mon Sep 17 00:00:00 2001 From: hainaweiben Date: Wed, 29 May 2024 15:05:29 +0800 Subject: [PATCH 1/2] add real paths column --- xinference/core/cache_tracker.py | 12 ++++++++++++ xinference/core/supervisor.py | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/xinference/core/cache_tracker.py b/xinference/core/cache_tracker.py index 9eeb01bade..69cb476fc2 100644 --- a/xinference/core/cache_tracker.py +++ b/xinference/core/cache_tracker.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os from logging import getLogger from typing import Any, Dict, List, Optional @@ -108,6 +109,17 @@ def list_cached_models(self) -> List[Dict[Any, Any]]: if version_info["cache_status"]: ret = version_info.copy() ret["model_name"] = model_name + re_dict = version_info.get("model_file_location", None) + actor_ip_address, path = next(iter(re_dict.items())) + ret["actor_ip_address"] = actor_ip_address + ret["path"] = path + if os.path.isdir(path): + files = os.listdir(path) + resolved_file = os.path.realpath(os.path.join(path, files[0])) + if resolved_file: + ret["real_path"] = os.path.dirname(resolved_file) + else: + ret["real_path"] = os.path.realpath(path) cached_models.append(ret) cached_models = sorted(cached_models, key=lambda x: x["model_name"]) return cached_models diff --git a/xinference/core/supervisor.py b/xinference/core/supervisor.py index dd9ee7e525..a77887475c 100644 --- a/xinference/core/supervisor.py +++ b/xinference/core/supervisor.py @@ -993,8 +993,9 @@ async def list_cached_models(self) -> List[Dict[str, Any]]: "model_size_in_billions", None ) quantizations = model_version.get("quantization", None) - re_dict = model_version.get("model_file_location", None) - actor_ip_address, path = next(iter(re_dict.items())) + actor_ip_address = model_version.get("actor_ip_address", None) + path = model_version.get("path", None) + real_path = model_version.get("real_path", None) cache_entry = { "model_name": model_name, @@ -1003,6 +1004,7 @@ async def list_cached_models(self) -> List[Dict[str, Any]]: "quantizations": quantizations, "path": path, "Actor IP Address": actor_ip_address, + "real_path": real_path, } cached_models.append(cache_entry) From 06c23d6c435e0d8931aae54d9178243b0455c972 Mon Sep 17 00:00:00 2001 From: hainaweiben Date: Fri, 31 May 2024 14:42:44 +0800 Subject: [PATCH 2/2] add some type checking --- xinference/core/cache_tracker.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xinference/core/cache_tracker.py b/xinference/core/cache_tracker.py index 69cb476fc2..ae2ab28352 100644 --- a/xinference/core/cache_tracker.py +++ b/xinference/core/cache_tracker.py @@ -106,11 +106,20 @@ def list_cached_models(self) -> List[Dict[Any, Any]]: cached_models = [] for model_name, model_versions in self._model_name_to_version_info.items(): for version_info in model_versions: - if version_info["cache_status"]: + cache_status = version_info.get("cache_status", None) + if cache_status == True: ret = version_info.copy() ret["model_name"] = model_name + re_dict = version_info.get("model_file_location", None) - actor_ip_address, path = next(iter(re_dict.items())) + if re_dict is not None and isinstance(re_dict, dict): + if re_dict: + actor_ip_address, path = next(iter(re_dict.items())) + else: + raise ValueError("The dictionary is empty.") + else: + raise ValueError("re_dict must be a non-empty dictionary.") + ret["actor_ip_address"] = actor_ip_address ret["path"] = path if os.path.isdir(path):