From 0015384df0569f08d505007e878638d0f1feed95 Mon Sep 17 00:00:00 2001 From: AllentDan Date: Fri, 1 Mar 2024 10:37:04 +0800 Subject: [PATCH] remove fuzzywuzzy --- lmdeploy/model.py | 29 +++++++++++------------------ requirements/runtime.txt | 1 - 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/lmdeploy/model.py b/lmdeploy/model.py index 2af31babef..15acd20c85 100644 --- a/lmdeploy/model.py +++ b/lmdeploy/model.py @@ -1,12 +1,13 @@ # Copyright (c) OpenMMLab. All rights reserved. import dataclasses -import os from abc import abstractmethod from typing import Literal, Optional -from fuzzywuzzy import fuzz, process from mmengine import Registry +from lmdeploy.utils import get_logger + +logger = get_logger('lmdeploy') MODELS = Registry('model', locations=['lmdeploy.model']) @@ -45,7 +46,13 @@ def chat_template(self): for key, value in dataclasses.asdict(self).items() if value is not None } - model: BaseModel = MODELS.get(self.model_name)(**attrs) + if self.model_name in MODELS.module_dict.keys(): + model: BaseModel = MODELS.get(self.model_name)(**attrs) + else: + logger.warning( + f'Could not find {self.model_name} in registered models. ' + f'Register {self.model_name} using the BaseChatTemplate.') + model = BaseChatTemplate(**attrs) return model @@ -839,12 +846,11 @@ def match(cls, model_path: str) -> Optional[str]: return 'deepseek-chat' -def best_match_model(query: str, similarity_cutoff: float = 0.5): +def best_match_model(query: str): """Get the model that matches the query. Args: query (str): the input query. Could be a model path. - similarity_cutoff (float): similarities below the limit are ignored. Return: List[str] | None: the possible model names or none. @@ -852,16 +858,3 @@ def best_match_model(query: str, similarity_cutoff: float = 0.5): for name, model in MODELS.module_dict.items(): if model.match(query): return model.match(query) - model_names = list(MODELS.module_dict.keys()) - if query.endswith('/'): - query = query[:-1] - base_name = os.path.basename(query).lower() - # Using fuzzy matching - matches = process.extract(base_name, model_names, scorer=fuzz.ratio) - - # Ignore matches with score below similarity_cutoff - matches = [ - match for match, score in matches if score / 100 >= similarity_cutoff - ] - - return matches[0] if matches else None diff --git a/requirements/runtime.txt b/requirements/runtime.txt index 6509144915..9b08ba5020 100644 --- a/requirements/runtime.txt +++ b/requirements/runtime.txt @@ -1,6 +1,5 @@ fastapi fire -fuzzywuzzy mmengine-lite numpy peft<=0.8.2