From e4abd56eeb80d600a51751097bc88a71ccdee4e2 Mon Sep 17 00:00:00 2001 From: Fangyin Cheng Date: Sun, 14 Jul 2024 20:39:38 +0800 Subject: [PATCH] feat(model): Support codegeex4-all-9b (#1720) --- dbgpt/configs/model_config.py | 2 ++ dbgpt/model/adapter/hf_adapter.py | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dbgpt/configs/model_config.py b/dbgpt/configs/model_config.py index 53c46b0fb..1791c1586 100644 --- a/dbgpt/configs/model_config.py +++ b/dbgpt/configs/model_config.py @@ -55,6 +55,8 @@ def get_device() -> str: # https://huggingface.co/THUDM/glm-4-9b-chat "glm-4-9b-chat": os.path.join(MODEL_PATH, "glm-4-9b-chat"), "glm-4-9b-chat-1m": os.path.join(MODEL_PATH, "glm-4-9b-chat-1m"), + # https://huggingface.co/THUDM/codegeex4-all-9b + "codegeex4-all-9b": os.path.join(MODEL_PATH, "codegeex4-all-9b"), "guanaco-33b-merged": os.path.join(MODEL_PATH, "guanaco-33b-merged"), "falcon-40b": os.path.join(MODEL_PATH, "falcon-40b"), "gorilla-7b": os.path.join(MODEL_PATH, "gorilla-7b"), diff --git a/dbgpt/model/adapter/hf_adapter.py b/dbgpt/model/adapter/hf_adapter.py index 601b59bf6..784d7ce3b 100644 --- a/dbgpt/model/adapter/hf_adapter.py +++ b/dbgpt/model/adapter/hf_adapter.py @@ -552,9 +552,9 @@ def do_match(self, lower_model_name_or_path: Optional[str] = None): ) -class GLM4Aapter(NewHFChatModelAdapter): +class GLM4Adapter(NewHFChatModelAdapter): """ - https://huggingface.co/defog/glm-4-8b + https://huggingface.co/THUDM/glm-4-9b-chat """ def do_match(self, lower_model_name_or_path: Optional[str] = None): @@ -565,6 +565,22 @@ def do_match(self, lower_model_name_or_path: Optional[str] = None): ) +class Codegeex4Adapter(GLM4Adapter): + """ + https://huggingface.co/THUDM/codegeex4-all-9b + """ + + def do_match(self, lower_model_name_or_path: Optional[str] = None): + return lower_model_name_or_path and "codegeex4" in lower_model_name_or_path + + def load(self, model_path: str, from_pretrained_kwargs: dict): + if not from_pretrained_kwargs: + from_pretrained_kwargs = {} + if "trust_remote_code" not in from_pretrained_kwargs: + from_pretrained_kwargs["trust_remote_code"] = True + return super().load(model_path, from_pretrained_kwargs) + + # The following code is used to register the model adapter # The last registered model adapter is matched first register_model_adapter(YiAdapter) @@ -583,5 +599,6 @@ def do_match(self, lower_model_name_or_path: Optional[str] = None): register_model_adapter(PhiAdapter) register_model_adapter(SQLCoderAdapter) register_model_adapter(OpenChatAdapter) -register_model_adapter(GLM4Aapter) +register_model_adapter(GLM4Adapter) +register_model_adapter(Codegeex4Adapter) register_model_adapter(Qwen2Adapter)