Skip to content

Commit

Permalink
remove fuzzywuzzy
Browse files Browse the repository at this point in the history
  • Loading branch information
AllentDan committed Mar 1, 2024
1 parent df8b4fd commit 0015384
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
29 changes: 11 additions & 18 deletions lmdeploy/model.py
Original file line number Diff line number Diff line change
@@ -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'])


Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -839,29 +846,15 @@ 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.
"""
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
1 change: 0 additions & 1 deletion requirements/runtime.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fastapi
fire
fuzzywuzzy
mmengine-lite
numpy
peft<=0.8.2
Expand Down

0 comments on commit 0015384

Please sign in to comment.