From 909db8c3bf575d0c80811510274fcd21de4e73f0 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Wed, 22 Nov 2023 02:27:42 +0000 Subject: [PATCH] refactor: reduce compiled cacheline Signed-off-by: Aaron Pham <29749331+aarnphm@users.noreply.github.com> --- openllm-python/src/openllm/client.py | 7 ++---- openllm-python/src/openllm/utils.py | 34 ++++++---------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/openllm-python/src/openllm/client.py b/openllm-python/src/openllm/client.py index a10cf35b..262c55b8 100644 --- a/openllm-python/src/openllm/client.py +++ b/openllm-python/src/openllm/client.py @@ -1,6 +1,3 @@ # fmt: off -import openllm_client as _client - - -def __dir__():return sorted(dir(_client)) -def __getattr__(it):return getattr(_client, it) +def __dir__():import openllm_client as _client;return sorted(dir(_client)) +def __getattr__(it):import openllm_client as _client;return getattr(_client, it) diff --git a/openllm-python/src/openllm/utils.py b/openllm-python/src/openllm/utils.py index f23b26b4..08af3eec 100644 --- a/openllm-python/src/openllm/utils.py +++ b/openllm-python/src/openllm/utils.py @@ -1,9 +1,7 @@ -import functools -import importlib.metadata - -import openllm_core - +# fmt: off +import functools, importlib.metadata, openllm_core +__all__ = ['generate_labels', 'available_devices', 'device_count'] def generate_labels(llm): return { 'backend': llm.__llm_backend__, @@ -13,28 +11,10 @@ def generate_labels(llm): 'serialisation': llm._serialisation, **{package: importlib.metadata.version(package) for package in {'openllm', 'openllm-core', 'openllm-client'}}, } - - -def available_devices(): - from ._strategies import NvidiaGpuResource - - return tuple(NvidiaGpuResource.from_system()) - - +def available_devices():from ._strategies import NvidiaGpuResource;return tuple(NvidiaGpuResource.from_system()) @functools.lru_cache(maxsize=1) -def device_count(): - return len(available_devices()) - - -__all__ = ['generate_labels', 'available_devices', 'device_count'] - - -def __dir__(): - coreutils = set(dir(openllm_core.utils)) | set([it for it in openllm_core.utils._extras if not it.startswith('_')]) - return sorted(__all__) + sorted(list(coreutils)) - - +def device_count()->int:return len(available_devices()) +def __dir__():coreutils=set(dir(openllm_core.utils))|set([it for it in openllm_core.utils._extras if not it.startswith('_')]);return sorted(__all__)+sorted(list(coreutils)) def __getattr__(it): - if hasattr(openllm_core.utils, it): - return getattr(openllm_core.utils, it) + if hasattr(openllm_core.utils, it):return getattr(openllm_core.utils, it) raise AttributeError(f'module {__name__} has no attribute {it}')