Skip to content

Commit

Permalink
初步支持QWEN1.5模型
Browse files Browse the repository at this point in the history
  • Loading branch information
TylunasLi committed Feb 19, 2024
1 parent 81e6fa1 commit 1934030
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ namespace fastllm {
model->model_type = "internlm";
} else if (modelType == "llama") {
model = (basellm*)(new LlamaModel());
} else if (modelType == "qwen2") {
model = new LlamaModel();
model->model_type = "qwen";
} else if (modelType == "qwen") {
model = (basellm *) (new QWenModel());
model->weight.tokenizer.type = Tokenizer::TokenizerType::QWEN;
Expand Down
2 changes: 2 additions & 0 deletions tools/fastllm_pytools/hf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def create(model,
if modelInfo["chat_format"] == "chatml":
modelInfo["im_end_id"] = tokenizer.im_end_id
modelInfo["im_start_id"] = tokenizer.im_start_id
elif (modelInfo["model_type"] == "qwen2"):
modelInfo["eos_token_id"] = "151645"
if (modelInfo["model_type"] == "chatglm" and hasattr(tokenizer, "build_chat_input")):
# chatglm3
modelInfo["pre_prompt"] = "";
Expand Down
2 changes: 2 additions & 0 deletions tools/fastllm_pytools/torch2flm.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def tofile(exportPath,
if modelInfo["chat_format"] == "chatml":
modelInfo["im_end_id"] = tokenizer.im_end_id
modelInfo["im_start_id"] = tokenizer.im_start_id
elif (modelInfo["model_type"] == "qwen2"):
modelInfo["eos_token_id"] = "151645"
if (modelInfo["model_type"] == "chatglm" and hasattr(tokenizer, "build_chat_input")):
# chatglm3
modelInfo["pre_prompt"] = "";
Expand Down
14 changes: 14 additions & 0 deletions tools/scripts/qwen2_2flm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from fastllm_pytools import torch2flm

if __name__ == "__main__":
model_name = sys.argv[3] if len(sys.argv) >= 4 else 'qwen/Qwen1.5-7B-Chat'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="cpu", torch_dtype=torch.float16)
dtype = sys.argv[2] if len(sys.argv) >= 3 else "float16"
exportPath = sys.argv[1] if len(sys.argv) >= 2 else "qwen1.5-7b-' + dtype + '.flm"
# add custom code here
torch2flm.tofile(exportPath, model, tokenizer, pre_prompt="<|im_start|>system\nYou are a helpful assistant.<|im_end|>", user_role="<|im_start|>user\n",
bot_role="<|im_end|><|im_start|>assistant\n", history_sep="<|im_end|>\n", dtype = dtype)

0 comments on commit 1934030

Please sign in to comment.