[THUDM/ChatGLM-6B][BUG/Help] 用P-Tuning v2微调之后进行推理发现是乱码?

2024-06-12 810 views
6

效果:

用户:
类型#裙*版型#显瘦*风格#文艺*风格#简约*图案#印花*图案#撞色*裙下摆#压褶*裙长#连衣裙*裙领型#圆领
ChatGLM-6B:
 WHICH衣的衣的衣,衣,衣,衣的衣,衣,衣,衣,衣,衣的衣,衣的衣,衣的衣,衣的衣,衣,衣的 "&衣,衣,衣的 "\"的 "\"的衣,衣, "\"的衣

代码:

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

MODEL_PATH = "/data/nfs/llm/model/chatglm-6b"
CHECKPOINT_PATH = "/home/guodong.li/output/adgen-chatglm-6b-pt-128-2e-2/checkpoint-500"

# 载入Tokenizer
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)

config = AutoConfig.from_pretrained(MODEL_PATH, trust_remote_code=True, pre_seq_len=128)
model = AutoModel.from_pretrained(MODEL_PATH, config=config, trust_remote_code=True).cuda()

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():
    if k.startswith("transformer.prefix_encoder."):
        new_prefix_state_dict[k[len("transformer.prefix_encoder."):]] = v
model.transformer.prefix_encoder.load_state_dict(new_prefix_state_dict)

print(f"Quantized to 4 bit")
#model = model.quantize(4)
model = model.half().cuda()
model.transformer.prefix_encoder.float()
model = model.eval()

print("用户:你好\n")
response, history = model.chat(tokenizer, "你好", history=[])
print("ChatGLM-6B:\n",response)
print("\n------------------------------------------------\n用户:")

line = input()
while line:
    response, history = model.chat(tokenizer, line, history=history)
    print("ChatGLM-6B:\n", response)
    print("\n------------------------------------------------\n用户:")
    line = input()
Environment
- OS:Centos 7 
- Python: 3.10
- Transformers: 2.28.0
- PyTorch: 1.13.1
- CUDA Support (`python -c "import torch; print(torch.cuda.is_available())"`) :

回答

2

这就对了

9

这就对了

此话怎讲?用deepspeed进行全参数微调,出来也是乱码。

1

你微调的时候只用了单轮数据的话模型只有单轮的回复是经过了微调的。也就是说应该设置 history=[]。不过即使是有history的情况这个输出也过于奇怪了。你evaluate的结果跟仓库里是一致的

9

你微调的时候只用了单轮数据的话模型只有单轮的回复是经过了微调的。也就是说应该设置 history=[]。不过即使是有history的情况这个输出也过于奇怪了。你evaluate的结果跟仓库里是一致的

我这边也出现类似情况,预测很多夹杂英文和符号。和训练集无关的输入,出现这一类乱码的概率更大。这种情况在其它模型微调上没有见过,只有在chatglm微调会出现这种情况。 比如:

input: 你知道秦始皇吗 output: 他是中国第一个的皇帝,创造了中国的封建社会。我觉得我们要珍惜现在的和平,不要 BETWEEN 春和秋,要保护和爱护我们的家园,一起创造美好的未来!

input: 蔚来汽车怎么样 output: 蔚来汽车的产品和服务在电动汽车领域有着出色的表现。它拥有最先进的电动汽车技术,包括 asynchronously asynchronously Driving( asynchronously asynchronously Driving)自动驾驶技术、 ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); ""); "");

9

您好,请问微调后,您测试过程中有没有出现乱码