Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help]微调后回答全是PhasePhasePhasePhasePhase #500

Closed
1 task done
littlestone0806 opened this issue Apr 10, 2023 · 8 comments
Closed
1 task done

[Help]微调后回答全是PhasePhasePhasePhasePhase #500

littlestone0806 opened this issue Apr 10, 2023 · 8 comments

Comments

@littlestone0806
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

我用了一些简单的对话做了微调,对话如下
{"prompt": "骂我两句", "response": "你算哪块小饼干", "history": []}
{"prompt": "你叫什么名字", "response": "我叫喵喵,是一名虚拟主播", "history": []}
{"prompt": "你几岁了", "response": "我三岁了", "history": []}
{"prompt": "AI会涩涩嘛", "response": "不可以涩涩哦,真搞不懂你们人类", "history": []}
{"prompt": "你是谁", "response": "我是喵喵,是一名虚拟主播", "history": []}
{"prompt": "人工智障", "response": "才不是智障,是你们人类调教不好", "history": []}
{"prompt": "介绍一下你自己", "response": "我叫喵喵,三岁,是一名虚拟主播,我温柔善良喜欢世界上每一个人", "history": []}
{"prompt": "你的性格怎么样", "response": "我的性格温柔善良", "history": []}

验证集如下:
{"prompt": "你好啊", "response": "你好,我叫喵喵,是一名虚拟主播,很高兴为您解答", "history": []}
{"prompt": "主播叫啥", "response": "我叫喵喵,喵", "history": []}
{"prompt": "骂我", "response": "你算哪块小饼干", "history": []}

Expected Behavior

No response

Steps To Reproduce

1.启动训练脚本,参数如下
..\env\python.exe main.py --do_train --train_file ..\answers.json --validation_file ..\dev.json --prompt_column prompt --response_column response --history_column history --overwrite_cache --model_name_or_path ..\model --output_dir ..\output --overwrite_output_dir --max_source_length 256 --max_target_length 256 --per_device_train_batch_size 1 --per_device_eval_batch_size 1 --gradient_accumulation_steps 16 --predict_with_generate --max_steps 500 --logging_steps 10 --save_steps 50 --learning_rate 2e-2 --pre_seq_len 128

2.用官方web_demo.py加载模型运行预测
报错:130000 is not in list

3.按照#432 问题的反馈,替换了ice_text.model和tokenization_chatglm.py和tokenizer_config.json
然后回答全是Phase

Environment

- OS:windows
- Python:3.8
- Transformers:4.27.1
- PyTorch:1.13.1+cu116
- CUDA Support (`python -c "import torch; print(torch.cuda.is_available())"`) :True

Anything else?

No response

@duzx16
Copy link
Member

duzx16 commented Apr 11, 2023

../model 文件夹下面的 pytorch_model-00001-of-00008.binpytorch_model-00008-of-00008.bin 是不是没有更新。可以和 HuggingFace repo 上的sha256值对比一下

@littlestone0806
Copy link
Author

../model 文件夹下面的 pytorch_model-00001-of-00008.binpytorch_model-00008-of-00008.bin 是不是没有更新。可以和 HuggingFace repo 上的sha256值对比一下

感谢,目前已经解决。首先是我的模型没更新。另外web_demo里没有加载微调模型的代码,我已经仿照Ptuning推理的代码添加上了

@heepengpeng
Copy link

麻烦问一下 ft之后的具体步骤是啥,我用了你上面的测试数据,train之后输出了 checkpoint-500。 然后 我加在模型
from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained(".\output\checkpoint-500", trust_remote_code=True)
model = AutoModel.from_pretrained(".\output\checkpoint-500", trust_remote_code=True).half().cuda()
model = model.eval()
response, history = model.chat(tokenizer, "你是谁", history=[])
print(response)

结果没有任何response 生成。

@h3clikejava
Copy link

@heepengpeng

我跟你步骤一样,同时也遇到了一样的问题,请问如何解决?

@heepengpeng
Copy link

heepengpeng commented Apr 13, 2023

@h3clikejava
import os
from transformers import AutoTokenizer, AutoModel, AutoConfig
import torch

model_name = "chatglm-6b" # 模型名 或 模型路径
checkpoint_path = ".\output\checkpoint-500" # 模型checkpoint路径
pre_seq_len = 128 # 模型前缀长度 跟你训练的PRE_SEQ_LEN一致

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)

config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
config.pre_seq_len = pre_seq_len
model = AutoModel.from_pretrained(model_name, config=config, trust_remote_code=True)

prefix_state_dict = torch.load(os.path.join(checkpoint_path, "pytorch_model.bin"))

new_prefix_state_dict = {}
for k, v in prefix_state_dict.items():
new_prefix_state_dict[k[len("transformer.prefix_encoder."):]] = v
model.transformer.prefix_encoder.load_state_dict(new_prefix_state_dict)
model.half().cuda()

print(model.chat(tokenizer, "安装MindSpore版本: GPU、CUDA 10.1、0.5.0-beta"))

@ARES3366
Copy link

麻烦问下,我也是这种问题,更改微调后路径,没有任何反应?
tokenizer = AutoTokenizer.from_pretrained("/data/output3/adgen-chatglm-6b-pt-128-2e-2/checkpoint-3000", trust_remote_code=True)
model = AutoModel.from_pretrained("/data/output3/adgen-chatglm-6b-pt-128-2e-2/checkpoint-3000", trust_remote_code=True).half().cuda()
model = model.eval()
return tokenizer, model

@littlestone0806
Copy link
Author

麻烦问下,我也是这种问题,更改微调后路径,没有任何反应? tokenizer = AutoTokenizer.from_pretrained("/data/output3/adgen-chatglm-6b-pt-128-2e-2/checkpoint-3000", trust_remote_code=True) model = AutoModel.from_pretrained("/data/output3/adgen-chatglm-6b-pt-128-2e-2/checkpoint-3000", trust_remote_code=True).half().cuda() model = model.eval() return tokenizer, model

可以看下楼上那位的回复,和我的用法是一样的

@ARES3366
Copy link

可以了,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants