mirror of
https://github.com/deepseek-ai/DeepSeek-Coder.git
synced 2026-11-05 00:57:19 +00:00
[GH-ISSUE #58] 请问在微调模型后,如何加载微调后的模型并在测试集上评估性能? #47
Labels
No labels
documentation
ENV
pull-request
research question
WIP
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepSeek-Coder#47
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Horizon2022 on GitHub (Nov 28, 2023).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-Coder/issues/58
有没有这样的代码样例,或者可参考的例子,谢谢
@guoday commented on GitHub (Nov 28, 2023):
https://github.com/deepseek-ai/DeepSeek-Coder/blob/main/Evaluation/HumanEval/eval_instruct.py
你可以查看这个
@Horizon2022 commented on GitHub (Dec 1, 2023):
tokenizer = AutoTokenizer.from_pretrained(
args.tuned_model,
padding_side="left",
trust_remote_code=True
)
tokenizer.pad_token = tokenizer.eos_token
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForCausalLM.from_pretrained(
args.tuned_model,
device_map="auto",
torch_dtype=torch.float16,
trust_remote_code=True,
pad_token_id=tokenizer.eos_token_id
)
inputs = tokenizer(prompt, return_tensors="pt").to(device)
outputs = model.generate(**inputs, max_new_tokens=128)
generated_response = tokenizer.decode(outputs[0], skip_special_tokens=True)
我微调了一个代码分类模型,并使用上面的代码使用微调后的模型做预测,模型输出如下内容:
### Response: Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald Ald
测试的 prompt 为微调数据去除了 ### Response: 后的内容的形式。
我打印了inputs['input_ids']如下:
tensor([[32013, 2042, 417, 274, 20926, 14244, 20391, 13, 185, 13518,
3649, 3475, 25, 185, 7983, 498, 3192, 254, 1884, 2974,
5396, 16371, 7551, 13, 185, 13518, 17645, 25, 185, 1426,
66, 13484, 5991, 11578, 7, 5960, 14025, 4651, 8, 185,
90, 185, 315, 5878, 23740, 7, 87, 49, 1185, 477,
185, 185, 315, 4716, 334, 292, 2140, 12, 29, 2448,
8, 507, 185, 315, 1452, 1439, 62, 13484, 5995, 8110,
25, 185, 436, 967, 1378, 66, 13484, 5995, 8110, 7,
6008, 477, 185, 315, 1452, 1439, 62, 13484, 7256, 4828,
25, 185, 436, 967, 1378, 66, 13484, 7256, 4828, 7,
6008, 477, 185, 315, 1452, 1439, 62, 13484, 17874, 34,
805, 708, 25, 185, 436, 967, 1378, 66, 13484, 17874,
34, 805, 708, 7, 6008, 477, 185, 315, 1452, 1439,
62, 13484, 2826, 15475, 34, 805, 708, 25, 185, 436,
967, 1378, 66, 13484, 2826, 15475, 34, 805, 708, 7,
6008, 477, 185, 315, 1452, 1439, 62, 13484, 3106, 4828,
25, 185, 436, 967, 1378, 66, 13484, 3106, 4828, 7,
6008, 477, 185, 315, 1452, 1439, 62, 13484, 25291, 4828,
25, 185, 436, 967, 1378, 66, 13484, 25291, 4828, 7,
6008, 477, 185, 315, 1452, 1439, 62, 13484, 5991, 508,
4828, 25, 185, 436, 967, 1378, 66, 13484, 5991, 508,
4828, 7, 6008, 477, 185, 315, 1452, 1439, 62, 13484,
13842, 4828, 25, 185, 436, 967, 1378, 66, 13484, 13842,
4828, 7, 6008, 477, 185, 315, 3346, 25, 185, 436,
967, 13147, 4397, 26, 185, 315, 611, 185, 92, 15189,
4535, 1378, 66, 13484, 5991, 11578, 1641, 185, 13518, 21289,
25]], device='cuda:0')
请问造成这种换乱输出的原因可能是什么
@Horizon2022 commented on GitHub (Dec 1, 2023):
这似乎不能解决我的问题,我使用base模型微调的,使用下面的tokenize方式会报错:
inputs = tokenizer.apply_chat_template(
[{'role': 'user', 'content': prompt }],
return_tensors="pt"
).to(model.device)
@txy6666yr commented on GitHub (Dec 6, 2023):
对 这个是chat模型的prompt拼接方式,和coder的不一样
@Horizon2022 commented on GitHub (Dec 6, 2023):
我用的base模型,然后依据微调的模版设置的prompt,只让预测Response的内容,然而遇到了输出错乱的问题
@txy6666yr commented on GitHub (Dec 6, 2023):
对 你可以看我提的issue,官方代码预测也是乱输出,我用官方代码微调后的模型,拼接成训练时的prompt也是乱输出