From b43f1441a94d677bb903706fd7f807f52e4639a2 Mon Sep 17 00:00:00 2001 From: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Date: Wed, 3 Jan 2024 11:36:57 +0800 Subject: [PATCH] Fix/model runtime (#1873) --- .../model_providers/xinference/llm/xinference_helper.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/core/model_runtime/model_providers/xinference/llm/xinference_helper.py b/api/core/model_runtime/model_providers/xinference/llm/xinference_helper.py index cb27025337..d73fab29e5 100644 --- a/api/core/model_runtime/model_providers/xinference/llm/xinference_helper.py +++ b/api/core/model_runtime/model_providers/xinference/llm/xinference_helper.py @@ -33,10 +33,13 @@ class XinferenceHelper: @staticmethod def _clean_cache() -> None: - with cache_lock: - for model_uid, model in cache.items(): - if model['expires'] < time(): + try: + with cache_lock: + expired_keys = [model_uid for model_uid, model in cache.items() if model['expires'] < time()] + for model_uid in expired_keys: del cache[model_uid] + except RuntimeError as e: + pass @staticmethod def _get_xinference_extra_parameter(server_url: str, model_uid: str) -> XinferenceModelExtraParameter: