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

src/api_demo以及web_demo输出乱码 #391

Closed
bxjxxyy opened this issue Aug 7, 2023 · 13 comments
Closed

src/api_demo以及web_demo输出乱码 #391

bxjxxyy opened this issue Aug 7, 2023 · 13 comments
Labels
solved This problem has been already solved

Comments

@bxjxxyy
Copy link

bxjxxyy commented Aug 7, 2023

用的baichuan-13B模型
启动命令分别用的
python api_demo.py --model_name_or_path baichuan-inc/Baichuan-13B-Chat --template default --quantization_bit 8
python web_demo.py --model_name_or_path baichuan-inc/Baichuan-13B-Chat --template default --quantization_bit 8
web_demo使用en和zh都是乱码
image
api_demo也是乱码
image

@franklyd
Copy link

franklyd commented Aug 7, 2023

qwen用了8bit后也是乱码。api日志有输出:Using bos_token, but it is not set yet.

@bxjxxyy
Copy link
Author

bxjxxyy commented Aug 8, 2023

发现如果不用quantization_bit 8,输出的就正常

@bxjxxyy
Copy link
Author

bxjxxyy commented Aug 8, 2023

怀疑乱码是quantization_bit时,使用的bitsandbytes的问题导致的。
如果把core里面的loader.py修改为下面如图。使用quantization_bit 8的时候,不再使用bitsandbytes
108-115行注释掉,然后添加
model = AutoModelForCausalLM.from_pretrained("baichuan-inc/Baichuan-13B-Chat", torch_dtype=torch.float16, trust_remote_code=True)
model = model.quantize(8).cuda()
就不会再出现乱码的情况。
X~99O%KFAJ{6X}0`1WYT3

但是这样会出现另外一个情况,当提问时content为你好或者你是什么之类的问题时
image
回答就会变成这种情况
image

如果content为一个更明确的问题,如:红烧肉怎么做,回答则是正常的
image

@hiyouga
Copy link
Owner

hiyouga commented Aug 8, 2023

template 没选对。

@bxjxxyy
Copy link
Author

bxjxxyy commented Aug 8, 2023

template 没选对。

请问这是指的template 没选对导致的乱码还是导致的回答里带自问自答?template 应该选择什么?
另外我看到#170 这个问题比较类似,但是这个问题说的是要加prompt_template

@franklyd
Copy link

franklyd commented Aug 8, 2023

qwen用了8-bit出乱码,不用就正常输出。
!python ../src/api_demo.py \ --model_name_or_path Qwen/Qwen-7B-Chat \ --template chatml \ --quantization_bit 8
应该不是template的问题

@bxjxxyy
Copy link
Author

bxjxxyy commented Aug 8, 2023

template 没选对。

回答里面自问自答的根据你说的这个解决了。就是#170 的方案。
但是乱码的问题,应该如何处理?我感觉我的那个处理方式不太对。

@hiyouga
Copy link
Owner

hiyouga commented Aug 8, 2023

乱码应该是显卡本身不支持 8bit

@bxjxxyy
Copy link
Author

bxjxxyy commented Aug 8, 2023

乱码应该是显卡本身不支持 8bit

不是,显卡是A6000。直接在baichuan-13b的项目里面的web_demo执行8bit是正常的。
这个项目按照我在4楼的方法就可以正常输出了,但是我总觉得那么改不太对。

@franklyd
Copy link

franklyd commented Aug 8, 2023

乱码应该是显卡本身不支持 8bit

我用的t4,用qwen官方的8bit代码是可以跑的;但用项目里的api就会出乱码。官方给的代码如下:

# quantization configuration for Int8 (8 bits)
quantization_config = BitsAndBytesConfig(load_in_8bit=True)

model = AutoModelForCausalLM.from_pretrained(
    args.checkpoint_path,
    device_map="cuda:0",
    quantization_config=quantization_config,
    max_memory=max_memory,
    trust_remote_code=True,
).eval()

@hiyouga
Copy link
Owner

hiyouga commented Aug 8, 2023

@franklyd 更新一下代码试试

@xuanxuanzl
Copy link

我微调了baichuan13-B也出现了乱码这个问题,代码我用的是8.9日晚上20点左右的。
python src/web_demo.py
--model_name_or_path /mnt/d/model_center/Baichuan-13B-Base \ --------------------百川的基础模型
--template baichuan
--quantization_bit 8
--finetuning_type lora
--lora_target W_pack

说明: 开始有--checkpoint_dir path_to_checkpoint,也是乱码,去掉后还是乱码。

@hiyouga hiyouga added the pending This problem is yet to be addressed label Aug 10, 2023
@hiyouga
Copy link
Owner

hiyouga commented Aug 11, 2023

已修复,请更新代码。

@hiyouga hiyouga added solved This problem has been already solved and removed pending This problem is yet to be addressed labels Aug 11, 2023
@hiyouga hiyouga closed this as completed Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved This problem has been already solved
Projects
None yet
Development

No branches or pull requests

4 participants