diff --git a/tools/fastllm_pytools/hf_model.py b/tools/fastllm_pytools/hf_model.py index 439227e3..f2135ff7 100644 --- a/tools/fastllm_pytools/hf_model.py +++ b/tools/fastllm_pytools/hf_model.py @@ -64,6 +64,10 @@ def create(model, modelInfo["im_start_id"] = tokenizer.im_start_id elif (modelInfo["model_type"] == "qwen2"): modelInfo["eos_token_id"] = "151645" + pre_prompt = modelInfo["pre_prompt"] = "<|im_start|>system\nYou are a helpful assistant.<|im_end|>" + user_role = modelInfo["user_role"] = "<|im_start|>user\n" + bot_role = modelInfo["bot_role"] = "<|im_end|><|im_start|>assistant\n" + history_sep = modelInfo["history_sep"] = "<|im_end|>\n" elif (modelInfo["model_type"] == "internlm"): modelInfo["eos_token_id"] = "103028" if "rotary" in modelInfo: @@ -81,7 +85,6 @@ def create(model, rope_scaling = modelInfo.pop("rope_scaling") modelInfo["rope_scaling.type"] = rope_scaling["type"] modelInfo["rope_scaling.factor"] = rope_scaling["factor"] - if tokenizer: modelInfo["tokenizer_use_score"] = "1" # 分词带分数 if len(tokenizer.all_special_tokens) > 0: diff --git a/tools/fastllm_pytools/llm.py b/tools/fastllm_pytools/llm.py index 75024a4c..29d079bb 100644 --- a/tools/fastllm_pytools/llm.py +++ b/tools/fastllm_pytools/llm.py @@ -351,7 +351,9 @@ def stream_chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = No max_length: int = 8192, do_sample = True, top_p = 0.8, top_k = 1, temperature = 1.0, repeat_penalty = 1.0, return_past_key_values = False, stop_token_ids: List[int] = None, **kwargs) -> str: type = None - if (tokenizer.name == "GLMTokenizer" and hasattr(tokenizer, "build_chat_input")): + if (hasattr(tokenizer, "name") + and tokenizer.name == "GLMTokenizer" + and hasattr(tokenizer, "build_chat_input")): type = "ChatGLM3" if (not(history)):