Skip to content

Commit

Permalink
修复qwen1.5模型from_hf直接转换
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyuyang committed Mar 20, 2024
1 parent 2232e22 commit 580a31b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tools/fastllm_pytools/hf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion tools/fastllm_pytools/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down

0 comments on commit 580a31b

Please sign in to comment.